Actors are active objects, which borrow a thread from a thread pool. The Actor interface provides means to send messages to the actor, start and stop the background thread as well as check its status.
Modifiers | Name | 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.Object[] |
EMPTY_ARGUMENTS |
|
private static java.lang.String |
ON_DELIVERY_ERROR |
|
private static java.lang.String |
RESPONDS_TO |
|
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 |
|
private static java.lang.ThreadLocal<Actor> |
currentActorPerThread |
Maps each thread to the actor it currently processes. |
protected java.lang.Thread |
currentThread |
|
private DataflowExpression<java.lang.Object> |
joinLatch |
|
private groovy.lang.Closure |
onStop |
|
protected PGroup |
parallelGroup |
The parallel group to which the message stream belongs |
private static long |
serialVersionUID |
|
protected static GeneralTimer |
timer |
Timer holding timeouts for react methods |
Fields inherited from class | Fields |
---|---|
class MessageStream |
serialVersionUID |
class WithSerialId |
serialHandle, serialVersionUID |
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) |
Type | Name 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 boolean |
hasBeenStopped() |
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(MessageStream listener) Notify listener when finished |
void |
join(long timeout, java.util.concurrent.TimeUnit unit) Joins the actor. |
void |
join(groovy.time.BaseDuration duration) Joins the actor. |
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 |
MessageStream |
sendAndContinue(T message, groovy.lang.Closure closure) Sends a message and execute continuation when reply became available. |
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. |
Actor |
silentStart() Starts the Actor without sending the START_MESSAGE message to speed the start-up. |
Actor |
start() Starts the Actor and sends it the START_MESSAGE to run any afterStart handlers. |
Actor |
stop() Send message to stop to the Actor. |
protected ActorMessage |
sweepNextMessage() Removes the head of the message queue |
java.util.List<ActorMessage> |
sweepQueue() Clears the message queue returning all the messages it held. |
Actor |
terminate() Terminates the Actor. |
static Actor |
threadBoundActor() Retrieves the actor registered with the current thread |
Methods inherited from class | Name |
---|---|
class MessageStream |
call, getRemoteClass, leftShift, reInterrupt, send, send, send, sendAndWait, sendAndWait, sendAndWait |
class WithSerialId |
createRemoteHandle, getOrCreateSerialHandle, getRemoteClass, writeReplace |
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Maps each thread to the actor it currently processes. Used in the send() method to remember the sender of each message for potential replies
The parallel group to which the message stream belongs
Timer holding timeouts for react methods
Constructor to be used by deserialization
joinLatch
- The instance of DataflowExpression to use for join operationDeregisters the actor registered from the thread
Join-point for this actor
Retrieves the group to which the actor belongs
Checks the current status of the Actor.
Checks whether the current thread is the actor's current thread.
Joins the actor. Waits for its termination.
Notify listener when finished
listener
- listener to notifyJoins the actor. Waits for its termination.
timeout
- timeoutunit
- units of timeoutJoins the actor. Waits for its termination.
duration
- timeout to waitSet on stop handler for this actor
onStop
- The code to invoke when stoppingRegisters the actor with the current thread
currentActor
- The actor to registerSends a message and execute continuation when reply became available.
message
- message to sendclosure
- closure to execute when reply became availableSends a message and returns a promise for the reply.
message
- message to sendSets the parallel group. It can only be invoked before the actor is started.
group
- new groupStarts the Actor without sending the START_MESSAGE message to speed the start-up. The potential custom afterStart handlers won't be run. No messages can be sent or received before an Actor is started.
Starts the Actor and sends it the START_MESSAGE to run any afterStart handlers. No messages can be sent or received before an Actor is started.
Send message to stop to the Actor. The actor will finish processing the current message and all unprocessed messages will be passed to the afterStop method, if such exists. No new messages will be accepted since that point. Has no effect if the Actor is not started.
Removes the head of the message queue
Clears the message queue returning all the messages it held.
Terminates the Actor. Unprocessed messages will be passed to the afterStop method, if exists. No new messages will be accepted since that point. Has no effect if the Actor is not started.
Retrieves the actor registered with the current thread
Copyright © 2008–2014 Václav Pech. All Rights Reserved.