groovyx.gpars.actor
Class BlockingActor

java.lang.Object
  extended by groovyx.gpars.serial.WithSerialId
      extended by groovyx.gpars.actor.impl.MessageStream
          extended by groovyx.gpars.actor.Actor
              extended by groovyx.gpars.actor.impl.ReplyingMessageStream
                  extended by groovyx.gpars.actor.impl.SequentialProcessingActor
                      extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from class groovyx.gpars.actor.Actor
Actor.MyRemoteHandle, Actor.RemoteActor
 
Nested classes/interfaces inherited from class groovyx.gpars.actor.impl.MessageStream
MessageStream.RemoteMessageStream, MessageStream.SendTo
 
Field Summary
static java.lang.String AN_ACTOR_CAN_ONLY_RECEIVE_ONE_MESSAGE_AT_A_TIME
           
private static long serialVersionUID
           
private static java.lang.String THE_ACTOR_HAS_BEEN_STOPPED
           
private static java.lang.String THE_ACTOR_HAS_NOT_BEEN_STARTED
           
 
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
 
Fields inherited from class groovyx.gpars.actor.Actor
ACTOR_HAS_ALREADY_BEEN_STARTED, CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED, currentThread, parallelGroup, START_MESSAGE, STOP_MESSAGE, TERMINATE_MESSAGE, TIMEOUT, TIMEOUT_MESSAGE, timer
 
Fields inherited from class groovyx.gpars.serial.WithSerialId
serialHandle
 
Constructor Summary
BlockingActor()
           
 
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.impl.ReplyingMessageStream
getSender, reply, replyIfExists, setSender
 
Methods inherited from class groovyx.gpars.actor.Actor
createActorMessage, createRemoteHandle, deregisterCurrentActorWithThread, getJoinLatch, getParallelGroup, handleException, handleInterrupt, handleTimeout, isActorThread, join, join, join, join, onStop, registerCurrentActorWithThread, sendAndContinue, sendAndPromise, sweepQueue, threadBoundActor
 
Methods inherited from class groovyx.gpars.actor.impl.MessageStream
call, getRemoteClass, leftShift, 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

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
Constructor Detail

BlockingActor

public BlockingActor()
Method Detail

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 unit
units - 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 unit
timeUnit - a TimeUnit determining how to interpret the timeout parameter
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(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 unit
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.

handleStart

protected void handleStart()
Overrides:
handleStart in class Actor

Copyright © 2008–2012 Václav Pech. All Rights Reserved.