public abstract class Actor extends MessageStream
Modifier and Type | Class and Description |
---|---|
static class |
Actor.MyRemoteHandle |
static class |
Actor.RemoteActor |
MessageStream.RemoteMessageStream, MessageStream.SendTo
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
ACTOR_HAS_ALREADY_BEEN_STARTED |
private static java.lang.String |
AFTER_START |
static java.lang.String |
CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED |
private static java.lang.ThreadLocal<Actor> |
currentActorPerThread
Maps each thread to the actor it currently processes.
|
protected java.lang.Thread |
currentThread |
private static java.lang.Object[] |
EMPTY_ARGUMENTS |
private DataflowExpression<java.lang.Object> |
joinLatch |
private static java.lang.String |
ON_DELIVERY_ERROR |
private groovy.lang.Closure |
onStop |
protected PGroup |
parallelGroup
The parallel group to which the message stream belongs
|
private static java.lang.String |
RESPONDS_TO |
private static long |
serialVersionUID |
protected static ActorMessage |
START_MESSAGE |
protected static ActorMessage |
STOP_MESSAGE |
protected static ActorMessage |
TERMINATE_MESSAGE |
static java.lang.String |
TIMEOUT |
protected static ActorMessage |
TIMEOUT_MESSAGE |
protected static GeneralTimer |
timer
Timer holding timeouts for react methods
|
serialHandle
Modifier | Constructor and Description |
---|---|
protected |
Actor() |
protected |
Actor(DataflowExpression<java.lang.Object> joinLatch)
Constructor to be used by deserialization
|
protected |
Actor(DataflowExpression<java.lang.Object> joinLatch,
PGroup parallelGroup) |
Modifier and Type | Method and Description |
---|---|
private boolean |
callDynamic(java.lang.String method,
java.lang.Object[] args) |
protected ActorMessage |
createActorMessage(java.lang.Object message) |
protected RemoteHandle |
createRemoteHandle(SerialHandle handle,
SerialContext host) |
protected static void |
deregisterCurrentActorWithThread()
Deregisters the actor registered from the thread
|
DataflowExpression<java.lang.Object> |
getJoinLatch()
Join-point for this actor
|
PGroup |
getParallelGroup()
Retrieves the group to which the actor belongs
|
protected void |
handleException(java.lang.Throwable exception) |
protected void |
handleInterrupt(java.lang.InterruptedException exception) |
protected void |
handleStart() |
protected void |
handleTermination() |
protected void |
handleTimeout() |
protected abstract boolean |
hasBeenStopped() |
abstract boolean |
isActive()
Checks the current status of the Actor.
|
boolean |
isActorThread()
Checks whether the current thread is the actor's current thread.
|
void |
join()
Joins the actor.
|
void |
join(groovy.time.BaseDuration duration)
Joins the actor.
|
void |
join(long timeout,
java.util.concurrent.TimeUnit unit)
Joins the actor.
|
void |
join(MessageStream listener)
Notify listener when finished
|
void |
onStop(groovy.lang.Closure onStop)
Set on stop handler for this actor
|
protected static void |
registerCurrentActorWithThread(Actor currentActor)
Registers the actor with the current thread
|
<T> MessageStream |
sendAndContinue(T message,
groovy.lang.Closure closure)
Sends a message and execute continuation when reply became available.
|
<T> Promise<java.lang.Object> |
sendAndPromise(T message)
Sends a message and returns a promise for the reply.
|
void |
setParallelGroup(PGroup group)
Sets the parallel group.
|
abstract Actor |
silentStart()
Starts the Actor without sending the START_MESSAGE message to speed the start-up.
|
abstract Actor |
start()
Starts the Actor and sends it the START_MESSAGE to run any afterStart handlers.
|
abstract Actor |
stop()
Send message to stop to the Actor.
|
protected abstract ActorMessage |
sweepNextMessage()
Removes the head of the message queue
|
(package private) java.util.List<ActorMessage> |
sweepQueue()
Clears the message queue returning all the messages it held.
|
abstract Actor |
terminate()
Terminates the Actor.
|
static Actor |
threadBoundActor()
Retrieves the actor registered with the current thread
|
call, getRemoteClass, leftShift, send, send, send, sendAndWait, sendAndWait, sendAndWait
getOrCreateSerialHandle, writeReplace
private static final java.lang.ThreadLocal<Actor> currentActorPerThread
private static final long serialVersionUID
public static final java.lang.String CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED
private final DataflowExpression<java.lang.Object> joinLatch
protected volatile PGroup parallelGroup
protected static final ActorMessage START_MESSAGE
protected static final ActorMessage STOP_MESSAGE
protected static final ActorMessage TERMINATE_MESSAGE
private static final java.lang.String AFTER_START
private static final java.lang.String RESPONDS_TO
private static final java.lang.String ON_DELIVERY_ERROR
private static final java.lang.Object[] EMPTY_ARGUMENTS
public static final java.lang.String TIMEOUT
protected static final ActorMessage TIMEOUT_MESSAGE
private volatile groovy.lang.Closure onStop
protected volatile java.lang.Thread currentThread
protected static final java.lang.String ACTOR_HAS_ALREADY_BEEN_STARTED
protected static final GeneralTimer timer
protected Actor()
protected Actor(DataflowExpression<java.lang.Object> joinLatch)
joinLatch
- The instance of DataflowExpression to use for join operationprotected Actor(DataflowExpression<java.lang.Object> joinLatch, PGroup parallelGroup)
public final PGroup getParallelGroup()
public void setParallelGroup(PGroup group)
group
- new grouppublic final <T> MessageStream sendAndContinue(T message, groovy.lang.Closure closure)
message
- message to sendclosure
- closure to execute when reply became availablepublic final <T> Promise<java.lang.Object> sendAndPromise(T message)
message
- message to sendpublic abstract Actor silentStart()
public abstract Actor start()
public abstract Actor stop()
public abstract Actor terminate()
public abstract boolean isActive()
public final void join() throws java.lang.InterruptedException
java.lang.InterruptedException
- when interrupted while waitingpublic final void join(MessageStream listener)
listener
- listener to notifypublic final void join(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
timeout
- timeoutunit
- units of timeoutjava.lang.InterruptedException
- if interrupted while waitingpublic final void join(groovy.time.BaseDuration duration) throws java.lang.InterruptedException
duration
- timeout to waitjava.lang.InterruptedException
- if interrupted while waitingpublic DataflowExpression<java.lang.Object> getJoinLatch()
protected static void registerCurrentActorWithThread(Actor currentActor)
currentActor
- The actor to registerprotected static void deregisterCurrentActorWithThread()
public static Actor threadBoundActor()
protected final ActorMessage createActorMessage(java.lang.Object message)
protected abstract boolean hasBeenStopped()
protected RemoteHandle createRemoteHandle(SerialHandle handle, SerialContext host)
createRemoteHandle
in class WithSerialId
protected void handleStart()
protected void handleTermination()
public final void onStop(groovy.lang.Closure onStop)
onStop
- The code to invoke when stoppingprotected void handleException(java.lang.Throwable exception)
protected void handleInterrupt(java.lang.InterruptedException exception)
protected void handleTimeout()
private boolean callDynamic(java.lang.String method, java.lang.Object[] args)
protected abstract ActorMessage sweepNextMessage()
final java.util.List<ActorMessage> sweepQueue()
public final boolean isActorThread()