Class Supervisor
- java.lang.Object
-
- co.paralleluniverse.actors.ActorRef<Message>
-
- co.paralleluniverse.actors.ActorRefDelegate<java.lang.Object>
-
- co.paralleluniverse.actors.behaviors.Behavior
-
- co.paralleluniverse.actors.behaviors.Supervisor
-
- All Implemented Interfaces:
Port<java.lang.Object>,PortAutoCloseable,SendPort<java.lang.Object>,java.io.Serializable,java.lang.AutoCloseable
public class Supervisor extends Behavior
An interface to aSupervisorActor.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSupervisor.ChildModeDetermines whether a child (supervised) actor should be restarted if the supervisor'srestart strategystates that it should be restarted.static classSupervisor.ChildSpecDescribes a child actor's configuration in a supervisor
-
Constructor Summary
Constructors Constructor Description Supervisor(ActorRef<java.lang.Object> actor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends ActorRef<M>,M>
TaddChild(Supervisor.ChildSpec spec)Adds a new child actor to the supervisor.<T extends ActorRef<M>,M>
TgetChild(java.lang.Object id)Retrieves a child actor by itsidThis method does not block when called from within the Supervisor's context, so, in particular, it may be called by an actor constructor, constructed by the supervisor.java.util.List<? extends ActorRef<?>>getChildren()Retrieves the children actor references as an immutable list.booleanremoveChild(ActorRef<?> actor, boolean terminate)Removes a child actor from the supervisor.booleanremoveChild(java.lang.Object id, boolean terminate)Removes a child actor from the supervisor.java.lang.StringtoString()-
Methods inherited from class co.paralleluniverse.actors.ActorRefDelegate
getImpl, isInActor
-
Methods inherited from class co.paralleluniverse.actors.ActorRef
close, close, equals, getName, hashCode, interrupt, send, send, send, sendSync, trySend
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface co.paralleluniverse.strands.channels.PortAutoCloseable
isClosed
-
-
-
-
Constructor Detail
-
Supervisor
public Supervisor(ActorRef<java.lang.Object> actor)
Ifactoris known to be aServerActor, creates a newServerinterface to it. Normally, you don't use this constructor, but theSupervisorinstance returned bySupervisorActor.spawn().- Parameters:
actor- aServerActor
-
-
Method Detail
-
addChild
public final <T extends ActorRef<M>,M> T addChild(Supervisor.ChildSpec spec) throws SuspendExecution, java.lang.InterruptedException
Adds a new child actor to the supervisor. If the child has not been started, it will be started by the supervisor. This method does not block when called from within the Supervisor's context, so, in particular, it may be called by an actor constructor, constructed by the supervisor.- Parameters:
spec- thechild's spec.- Returns:
- the actor (possibly after it has been started by the supervisor).
- Throws:
java.lang.InterruptedExceptionSuspendExecution
-
getChild
public final <T extends ActorRef<M>,M> T getChild(java.lang.Object id) throws SuspendExecution, java.lang.InterruptedException
Retrieves a child actor by itsidThis method does not block when called from within the Supervisor's context, so, in particular, it may be called by an actor constructor, constructed by the supervisor.- Parameters:
id- the child'sidin the supervisor.- Returns:
- the child, if found;
nullif the child was not found - Throws:
SuspendExecutionjava.lang.InterruptedException
-
getChildren
public final java.util.List<? extends ActorRef<?>> getChildren() throws SuspendExecution, java.lang.InterruptedException
Retrieves the children actor references as an immutable list. This method does not block when called from within the Supervisor's context, so, in particular, it may be called by an actor constructor, constructed by the supervisor.- Returns:
- the children
ActorRefs. - Throws:
SuspendExecutionjava.lang.InterruptedException
-
removeChild
public final boolean removeChild(java.lang.Object id, boolean terminate) throws SuspendExecution, java.lang.InterruptedExceptionRemoves a child actor from the supervisor. This method does not block when called from within the Supervisor's context, so, in particular, it may be called by an actor constructor, constructed by the supervisor.- Parameters:
id- the child'sidin the supervisor.terminate- whether or not the supervisor should terminate the actor- Returns:
trueif the actor has been successfully removed from the supervisor;falseif the child was not found.- Throws:
java.lang.InterruptedExceptionSuspendExecution
-
removeChild
public boolean removeChild(ActorRef<?> actor, boolean terminate) throws SuspendExecution, java.lang.InterruptedException
Removes a child actor from the supervisor. This method does not block when called from within the Supervisor's context, so, in particular, it may be called by an actor constructor, constructed by the supervisor.- Parameters:
actor- the child actorterminate- whether or not the supervisor should terminate the actor- Returns:
trueif the actor has been successfully removed from the supervisor;falseif the child was not found.- Throws:
java.lang.InterruptedExceptionSuspendExecution
-
-