org.codehaus.gpars

groovyx.gpars.actor
[Java] 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

@SuppressWarnings({"ThrowCaughtLocally", "UnqualifiedStaticUsage"})
public abstract class BlockingActor
extends SequentialProcessingActor

Authors:
Vaclav Pech, Alex Tkachman, Dierk Koenig


Field Summary
static java.lang.String AN_ACTOR_CAN_ONLY_RECEIVE_ONE_MESSAGE_AT_A_TIME

private static java.lang.String THE_ACTOR_HAS_BEEN_STOPPED

private static java.lang.String THE_ACTOR_HAS_NOT_BEEN_STARTED

private static long serialVersionUID

 
Fields inherited from class SequentialProcessingActor
SHOULD_NOT_REACH_HERE, S_ACTIVE_MASK, S_FINISHED_MASK, S_FINISHING_MASK, S_NOT_STARTED, S_RUNNING, S_STOPPED, S_STOPPING, S_STOP_TERMINATE_MASK, S_TERMINATED, S_TERMINATING, inputQueue, inputQueueUpdater, ongoingThreadTermination, outputQueue, serialVersionUID, stopFlag, stopFlagUpdater, waitingThread
 
Fields inherited from class ReplyingMessageStream
sender, serialVersionUID
 
Fields inherited from class Actor
ACTOR_HAS_ALREADY_BEEN_STARTED, AFTER_START, CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED, EMPTY_ARGUMENTS, ON_DELIVERY_ERROR, RESPONDS_TO, START_MESSAGE, STOP_MESSAGE, TERMINATE_MESSAGE, TIMEOUT, TIMEOUT_MESSAGE, currentActorPerThread, currentThread, joinLatch, onStop, parallelGroup, serialVersionUID, timer
 
Fields inherited from class MessageStream
serialVersionUID
 
Fields inherited from class WithSerialId
serialHandle, serialVersionUID
 
Constructor Summary
BlockingActor()

 
Method Summary
private void checkStoppedFlags()

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()

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(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 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 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 SequentialProcessingActor
act, awaitNextMessage, checkStopTerminate, handleTermination, hasBeenStopped, isActive, pollMessage, receive, receive, receive, receiveImpl, receiveImpl, retrieveNextMessage, run, send, setParallelGroup, silentStart, start, stop, sweepNextMessage, takeMessage, takeMessage, terminate, throwIfNeeded, transferQueues, unwrapMessage
 
Methods inherited from class ReplyingMessageStream
getSender, reply, replyIfExists, setSender
 
Methods inherited from class Actor
callDynamic, createActorMessage, createRemoteHandle, deregisterCurrentActorWithThread, getJoinLatch, getParallelGroup, handleException, handleInterrupt, handleStart, handleTermination, handleTimeout, hasBeenStopped, isActive, isActorThread, join, join, join, join, onStop, registerCurrentActorWithThread, sendAndContinue, setParallelGroup, silentStart, start, stop, sweepNextMessage, sweepQueue, terminate, threadBoundActor
 
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

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


THE_ACTOR_HAS_BEEN_STOPPED

private static final java.lang.String THE_ACTOR_HAS_BEEN_STOPPED


THE_ACTOR_HAS_NOT_BEEN_STARTED

private static final java.lang.String THE_ACTOR_HAS_NOT_BEEN_STARTED


serialVersionUID

private static final long serialVersionUID


 
Constructor Detail

BlockingActor

BlockingActor()


 
Method Detail

checkStoppedFlags

private void checkStoppedFlags()


enhanceAndUnwrap

private java.lang.Object enhanceAndUnwrap(ActorMessage message)


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


handleStart

@Override
protected void handleStart()


receive

@SuppressWarnings({"MethodOverloadsMethodOfSuperclass"})
protected final void receive(groovy.lang.Closure handler)
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.
throws:
InterruptedException If the thread is interrupted during the wait. Should propagate up to stop the thread.
Parameters:
handler - A closure accepting the retrieved message as a parameter, which will be invoked after a message is received.


receive

protected final 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. 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
throws:
InterruptedException If the thread is interrupted during the wait. Should propagate up to stop the thread.
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.


receive

@SuppressWarnings({"MethodOverloadsMethodOfSuperclass", "TypeMayBeWeakened"})
protected final 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. 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
throws:
InterruptedException If the thread is interrupted during the wait. Should propagate up to stop the thread.
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.


receiveImpl

@Override
protected final java.lang.Object receiveImpl()
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
throws:
InterruptedException If the thread is interrupted during the wait. Should propagate up to stop the thread.
Returns:
The message retrieved from the queue.


receiveImpl

@Override
protected final 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.
throws:
InterruptedException If the thread is interrupted during the wait. Should propagate up to stop the thread.
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.


 

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