|
org.codehaus.gpars | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovyx.gpars.serial.WithSerialId groovyx.gpars.actor.impl.MessageStream groovyx.gpars.actor.Actor
public abstract class Actor extends MessageStream
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.
Nested Class Summary | |
---|---|
static class |
Actor.MyRemoteHandle
|
static class |
Actor.RemoteActor
|
Field Summary | |
---|---|
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 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 |
currentActorPerThread
Maps each thread to the actor it currently processes. |
protected java.lang.Thread |
currentThread
|
private DataflowExpression |
joinLatch
|
private groovy.lang.Closure |
onStop
|
protected PGroup |
parallelGroup
The parallel group to which the message stream belongs |
private static long |
serialVersionUID
|
protected static java.util.Timer |
timer
Timer holding timeouts for react methods |
Fields inherited from class MessageStream | |
---|---|
serialVersionUID |
Fields inherited from class WithSerialId | |
---|---|
serialHandle, serialVersionUID |
Constructor Summary | |
protected Actor()
|
|
protected Actor(DataflowExpression joinLatch)
Constructor to be used by deserialization |
|
protected Actor(DataflowExpression joinLatch, PGroup parallelGroup)
|
Method Summary | |
---|---|
private boolean
|
callDynamic(java.lang.String method, 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
|
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. |
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
|
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 MessageStream | |
---|---|
call, getRemoteClass, leftShift, reInterrupt, send, send, send, sendAndWait, sendAndWait, sendAndWait |
Methods inherited from class WithSerialId | |
---|---|
createRemoteHandle, getOrCreateSerialHandle, getRemoteClass, writeReplace |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), 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() |
Field Detail |
---|
protected static final java.lang.String ACTOR_HAS_ALREADY_BEEN_STARTED
private static final java.lang.String AFTER_START
public static final java.lang.String CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED
private static final Object[] EMPTY_ARGUMENTS
private static final java.lang.String ON_DELIVERY_ERROR
private static final java.lang.String RESPONDS_TO
protected static final ActorMessage START_MESSAGE
protected static final ActorMessage STOP_MESSAGE
protected static final ActorMessage TERMINATE_MESSAGE
@SuppressWarnings({"ConstantDeclaredInAbstractClass"}) public static final java.lang.String TIMEOUT
protected static final ActorMessage TIMEOUT_MESSAGE
private static final java.lang.ThreadLocal currentActorPerThread
protected java.lang.Thread currentThread
private final DataflowExpression joinLatch
private groovy.lang.Closure onStop
protected PGroup parallelGroup
private static final long serialVersionUID
protected static final java.util.Timer timer
Constructor Detail |
---|
protected Actor()
protected Actor(DataflowExpression joinLatch)
joinLatch
- The instance of DataflowExpression to use for join operation
protected Actor(DataflowExpression joinLatch, PGroup parallelGroup)
Method Detail |
---|
private boolean callDynamic(java.lang.String method, Object[] args)
protected final ActorMessage createActorMessage(java.lang.Object message)
@Override protected RemoteHandle createRemoteHandle(SerialHandle handle, SerialContext host)
protected static void deregisterCurrentActorWithThread()
public DataflowExpression getJoinLatch()
public final PGroup getParallelGroup()
@SuppressWarnings({"UseOfSystemOutOrSystemErr"}) protected void handleException(java.lang.Throwable exception)
@SuppressWarnings({"TypeMayBeWeakened", "UseOfSystemOutOrSystemErr"}) protected void handleInterrupt(java.lang.InterruptedException exception)
@SuppressWarnings("unchecked") protected void handleStart()
protected void handleTermination()
protected void handleTimeout()
protected boolean hasBeenStopped()
public boolean isActive()
public final boolean isActorThread()
public final void join()
public final void join(MessageStream listener)
listener
- listener to notify
public final void join(long timeout, java.util.concurrent.TimeUnit unit)
timeout
- timeoutunit
- units of timeout
public final void join(groovy.time.BaseDuration duration)
duration
- timeout to wait
public final void onStop(groovy.lang.Closure onStop)
onStop
- The code to invoke when stopping
protected static void registerCurrentActorWithThread(Actor currentActor)
currentActor
- The actor to register
@SuppressWarnings({"AssignmentToMethodParameter"}) public final MessageStream sendAndContinue(T message, groovy.lang.Closure closure)
message
- message to sendclosure
- closure to execute when reply became available
public void setParallelGroup(PGroup group)
group
- new group
public Actor silentStart()
public Actor start()
public Actor stop()
protected ActorMessage sweepNextMessage()
@SuppressWarnings("unchecked") final java.util.List sweepQueue()
public Actor terminate()
public static Actor threadBoundActor()
Copyright © 2008–2010 Václav Pech. All Rights Reserved.