groovyx.gpars.actor
Class BlockingActor
java.lang.Object
groovyx.gpars.serial.WithSerialId
groovyx.gpars.actor.impl.MessageStream
groovyx.gpars.actor.Actor
groovyx.gpars.actor.impl.ReplyingMessageStream
groovyx.gpars.actor.impl.SequentialProcessingActor
groovyx.gpars.actor.BlockingActor
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Runnable
- Direct Known Subclasses:
- RunnableBackedBlockingActor
public abstract class BlockingActor
- extends SequentialProcessingActor
- Author:
- Vaclav Pech, Alex Tkachman, Dierk Koenig
- See Also:
- Serialized Form
Fields inherited from class groovyx.gpars.actor.impl.SequentialProcessingActor |
S_ACTIVE_MASK, S_FINISHED_MASK, S_FINISHING_MASK, S_NOT_STARTED, S_RUNNING, S_STOP_TERMINATE_MASK, S_STOPPED, S_STOPPING, S_TERMINATED, S_TERMINATING, stopFlag, stopFlagUpdater |
Method Summary |
private java.lang.Object |
enhanceAndUnwrap(ActorMessage message)
|
private void |
enhanceReplies(ActorMessage message)
Adds reply and replyIfExists methods to the current Actor and the message. |
protected void |
handleStart()
|
private void |
checkStoppedFlags()
|
protected void |
receive(groovy.lang.Closure handler)
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
protected void |
receive(groovy.time.Duration duration,
groovy.lang.Closure handler)
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
protected void |
receive(long timeout,
java.util.concurrent.TimeUnit timeUnit,
groovy.lang.Closure handler)
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
protected java.lang.Object |
receiveImpl()
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
protected java.lang.Object |
receiveImpl(long timeout,
java.util.concurrent.TimeUnit units)
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
Methods inherited from class groovyx.gpars.actor.impl.SequentialProcessingActor |
act, handleTermination, hasBeenStopped, checkStopTerminate, isActive, pollMessage, receive, receive, receive, run, send, setParallelGroup, silentStart, start, stop, sweepNextMessage, takeMessage, takeMessage, terminate |
Methods inherited from class groovyx.gpars.actor.Actor |
createActorMessage, createRemoteHandle, deregisterCurrentActorWithThread, getJoinLatch, getParallelGroup, handleException, handleInterrupt, handleTimeout, isActorThread, join, join, join, join, onStop, registerCurrentActorWithThread, sendAndContinue, sweepQueue, threadBoundActor |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
THE_ACTOR_HAS_NOT_BEEN_STARTED
private static final java.lang.String THE_ACTOR_HAS_NOT_BEEN_STARTED
- See Also:
- Constant Field Values
THE_ACTOR_HAS_BEEN_STOPPED
private static final java.lang.String THE_ACTOR_HAS_BEEN_STOPPED
- See Also:
- Constant Field Values
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
AN_ACTOR_CAN_ONLY_RECEIVE_ONE_MESSAGE_AT_A_TIME
public static final java.lang.String AN_ACTOR_CAN_ONLY_RECEIVE_ONE_MESSAGE_AT_A_TIME
- See Also:
- Constant Field Values
BlockingActor
public BlockingActor()
enhanceReplies
private void enhanceReplies(ActorMessage message)
- Adds
reply
and replyIfExists
methods to the current Actor
and the message.
These methods will call send
on the target actor (the sender of the original message). The
reply
/replyIfExists
methods invoked on the actor will be sent to all currently
processed messages, reply
/replyIfExists
invoked on a message will send a reply to the
sender of that particular message only.
- Parameters:
message
- The original message
receiveImpl
protected final java.lang.Object receiveImpl()
throws java.lang.InterruptedException
- Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
- Specified by:
receiveImpl
in class SequentialProcessingActor
- Returns:
- The message retrieved from the queue.
- Throws:
java.lang.InterruptedException
- If the thread is interrupted during the wait. Should propagate up to stop the thread.
receiveImpl
protected final java.lang.Object receiveImpl(long timeout,
java.util.concurrent.TimeUnit units)
throws java.lang.InterruptedException
- Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
- Specified by:
receiveImpl
in class SequentialProcessingActor
- Parameters:
timeout
- how long to wait before giving up, in units of unitunits
- a TimeUnit
determining how to interpret the timeout parameter
- Returns:
- The message retrieved from the queue, or null, if the timeout expires.
- Throws:
java.lang.InterruptedException
- If the thread is interrupted during the wait. Should propagate up to stop the thread.
enhanceAndUnwrap
private java.lang.Object enhanceAndUnwrap(ActorMessage message)
checkStoppedFlags
private void checkStoppedFlags()
receive
protected final void receive(groovy.lang.Closure handler)
throws java.lang.InterruptedException
- Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
The message retrieved from the queue is passed into the handler as the only parameter.
- Parameters:
handler
- A closure accepting the retrieved message as a parameter, which will be invoked after a message is received.
- Throws:
java.lang.InterruptedException
- If the thread is interrupted during the wait. Should propagate up to stop the thread.
receive
protected final void receive(long timeout,
java.util.concurrent.TimeUnit timeUnit,
groovy.lang.Closure handler)
throws java.lang.InterruptedException
- Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
The message retrieved from the queue is passed into the handler as the only parameter.
A null value is passed into the handler, if the timeout expires
- Parameters:
timeout
- how long to wait before giving up, in units of unittimeUnit
- a TimeUnit determining how to interpret the timeout parameterhandler
- A closure accepting the retrieved message as a parameter, which will be invoked after a message is received.
- Throws:
java.lang.InterruptedException
- If the thread is interrupted during the wait. Should propagate up to stop the thread.
receive
protected final void receive(groovy.time.Duration duration,
groovy.lang.Closure handler)
throws java.lang.InterruptedException
- Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
The message retrieved from the queue is passed into the handler as the only parameter.
A null value is passed into the handler, if the timeout expires
- Parameters:
duration
- how long to wait before giving up, in units of unithandler
- A closure accepting the retrieved message as a parameter, which will be invoked after a message is received.
- Throws:
java.lang.InterruptedException
- If the thread is interrupted during the wait. Should propagate up to stop the thread.
handleStart
protected void handleStart()
- Overrides:
handleStart
in class Actor