|
||||||||||
PREV CLASS NEXT CLASS | 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
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
|
Nested classes/interfaces inherited from class groovyx.gpars.actor.impl.MessageStream |
---|
MessageStream.RemoteMessageStream, MessageStream.SendTo |
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 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 groovyx.gpars.group.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 java.util.Timer |
timer
Timer holding timeouts for react methods |
Fields inherited from class groovyx.gpars.serial.WithSerialId |
---|
serialHandle |
Constructor Summary | |
---|---|
protected |
Actor()
|
protected |
Actor(DataflowExpression<java.lang.Object> joinLatch)
Constructor to be used by deserialization |
protected |
Actor(DataflowExpression<java.lang.Object> joinLatch,
groovyx.gpars.group.PGroup parallelGroup)
|
Method Summary | ||
---|---|---|
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 |
|
groovyx.gpars.group.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 |
|
|
sendAndContinue(T message,
groovy.lang.Closure closure)
Sends a message and execute continuation when reply became available. |
|
void |
setParallelGroup(groovyx.gpars.group.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 |
Methods inherited from class groovyx.gpars.actor.impl.MessageStream |
---|
call, getRemoteClass, leftShift, send, send, send, sendAndWait, sendAndWait, sendAndWait |
Methods inherited from class groovyx.gpars.serial.WithSerialId |
---|
getOrCreateSerialHandle, writeReplace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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 groovyx.gpars.group.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 java.util.Timer timer
Constructor Detail |
---|
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, groovyx.gpars.group.PGroup parallelGroup)
Method Detail |
---|
public final groovyx.gpars.group.PGroup getParallelGroup()
public void setParallelGroup(groovyx.gpars.group.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 available
java.lang.InterruptedException
- if interrupted while waitingpublic 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 notify
java.lang.InterruptedException
- if interrupted while waitingpublic final void join(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
timeout
- timeoutunit
- units of timeout
java.lang.InterruptedException
- if interrupted while waitingpublic final void join(groovy.time.BaseDuration duration) throws java.lang.InterruptedException
duration
- timeout to wait
java.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()
|
Copyright © 2008–2010 Václav Pech. All Rights Reserved. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |