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 class
Supervisor.ChildMode
Determines whether a child (supervised) actor should be restarted if the supervisor'srestart strategy
states that it should be restarted.static class
Supervisor.ChildSpec
Describes 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 itsid
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.java.util.List<? extends ActorRef<?>>
getChildren()
Retrieves the children actor references as an immutable list.boolean
removeChild(ActorRef<?> actor, boolean terminate)
Removes a child actor from the supervisor.boolean
removeChild(java.lang.Object id, boolean terminate)
Removes a child actor from the supervisor.java.lang.String
toString()
-
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)
Ifactor
is known to be aServerActor
, creates a newServer
interface to it. Normally, you don't use this constructor, but theSupervisor
instance 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.InterruptedException
SuspendExecution
-
getChild
public final <T extends ActorRef<M>,M> T getChild(java.lang.Object id) throws SuspendExecution, java.lang.InterruptedException
Retrieves a child actor by itsid
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'sid
in the supervisor.- Returns:
- the child, if found;
null
if the child was not found - Throws:
SuspendExecution
java.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
ActorRef
s. - Throws:
SuspendExecution
java.lang.InterruptedException
-
removeChild
public final boolean removeChild(java.lang.Object id, 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:
id
- the child'sid
in the supervisor.terminate
- whether or not the supervisor should terminate the actor- Returns:
true
if the actor has been successfully removed from the supervisor;false
if the child was not found.- Throws:
java.lang.InterruptedException
SuspendExecution
-
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:
true
if the actor has been successfully removed from the supervisor;false
if the child was not found.- Throws:
java.lang.InterruptedException
SuspendExecution
-
-