@java.lang.SuppressWarnings({"UnqualifiedStaticUsage"}) public abstract class SequentialProcessingActor extends ReplyingMessageStream
Modifiers | Name | Description |
---|---|---|
private static class |
SequentialProcessingActor.Node |
Represents an element in the message queue. |
Modifiers | Name | Description |
---|---|---|
private static java.lang.String |
SHOULD_NOT_REACH_HERE |
|
protected static int |
S_ACTIVE_MASK |
|
protected static int |
S_FINISHED_MASK |
|
protected static int |
S_FINISHING_MASK |
|
protected static int |
S_NOT_STARTED |
|
protected static int |
S_RUNNING |
|
protected static int |
S_STOPPED |
|
protected static int |
S_STOPPING |
|
protected static int |
S_STOP_TERMINATE_MASK |
|
protected static int |
S_TERMINATED |
|
protected static int |
S_TERMINATING |
|
private SequentialProcessingActor.Node |
inputQueue |
Stored incoming messages. |
private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<SequentialProcessingActor, Node> |
inputQueueUpdater |
|
private java.util.concurrent.atomic.AtomicBoolean |
ongoingThreadTermination |
|
private SequentialProcessingActor.Node |
outputQueue |
Stores messages ready for processing by the actor. |
private static long |
serialVersionUID |
|
protected int |
stopFlag |
Indicates whether the actor should terminate |
protected static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<SequentialProcessingActor> |
stopFlagUpdater |
|
private java.lang.Thread |
waitingThread |
Fields inherited from class | Fields |
---|---|
class ReplyingMessageStream |
sender, serialVersionUID |
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 |
class MessageStream |
serialVersionUID |
class WithSerialId |
serialHandle, serialVersionUID |
Constructor and description |
---|
protected SequentialProcessingActor
() Creates a new instance, sets the default actor group. |
Type | Name and description |
---|---|
protected void |
act() This method represents the body of the actor. |
private ActorMessage |
awaitNextMessage(long endTime) Holds common functionality for takeMessage() methods. |
protected void |
checkStopTerminate() |
protected void |
handleTermination() |
protected boolean |
hasBeenStopped() |
boolean |
isActive() Checks the current status of the Actor. |
protected ActorMessage |
pollMessage() Polls a message from the queues |
protected java.lang.Object |
receive() Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
protected java.lang.Object |
receive(long timeout, java.util.concurrent.TimeUnit units) Retrieves a message from the message queue, waiting, if necessary, for a message to arrive. |
protected java.lang.Object |
receive(groovy.time.BaseDuration duration) 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. |
private ActorMessage |
retrieveNextMessage() Takes the next message from the outputQueue, decrements the counter and possibly throws control exceptions |
void |
run() |
MessageStream |
send(java.lang.Object message) |
void |
setParallelGroup(PGroup group) Sets the actor's group. |
Actor |
silentStart() |
SequentialProcessingActor |
start() Starts the Actor. |
Actor |
stop() Send message to stop to the actor. |
protected ActorMessage |
sweepNextMessage() Removes the head of the message queue |
protected ActorMessage |
takeMessage() Takes a message from the queues. |
protected ActorMessage |
takeMessage(long timeout, java.util.concurrent.TimeUnit timeUnit) Takes a message from the queues. |
Actor |
terminate() Terminate the Actor. |
private void |
throwIfNeeded(ActorMessage toProcess) Checks the supplied message and throws either STOP or TERMINATE, if the message is a Stop or Terminate message respectively. |
private void |
transferQueues() Transfers messages from the input queue into the output queue, reverting the order of the elements. |
private static java.lang.Object |
unwrapMessage(java.lang.Object msg) |
Stored incoming messages. The most recently received message is in the head of the list.
Stores messages ready for processing by the actor. The oldest message is in the head of the list. Messages are transferred from the inputQueue into the output queue in the transferQueues() method.
Indicates whether the actor should terminate
Creates a new instance, sets the default actor group.
This method represents the body of the actor. It is called upon actor's start and can exit either
normally by return or due to actor being stopped through the stop() method, which cancels the current
actor action. Provides an extension point for subclasses to provide their custom Actor
's
message handling code.
Holds common functionality for takeMessage() methods.
endTime
- End of the timeout, 0 if no timeout was setChecks the current status of the Actor.
Polls a message from the queues
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
timeout
- how long to wait before giving up, in units of unitunits
- a TimeUnit determining how to interpret the timeout parameterRetrieves a message from the message queue, waiting, if necessary, for a message to arrive.
duration
- how long to wait before giving up, in units of unitRetrieves a message from the message queue, waiting, if necessary, for a message to arrive.
Retrieves a message from the message queue, waiting, if necessary, for a message to arrive.
timeout
- how long to wait before giving up, in units of unitunits
- a TimeUnit determining how to interpret the timeout parameterTakes the next message from the outputQueue, decrements the counter and possibly throws control exceptions
Sets the actor's group. It can only be invoked before the actor is started.
group
- new groupStarts the Actor. No messages can be send or received before an Actor is started.
Send message to stop to the actor. All messages in queue will be processed before stopped but no new messages will be accepted after that point
Removes the head of the message queue
Takes a message from the queues. Blocks until a message is available.
Takes a message from the queues. Blocks until a message is available.
timeout
- Max time to wait for a messagetimeUnit
- The units for the timeoutTerminate the Actor. The background thread will be interrupted, unprocessed messages will be passed to the afterStop method, if exists. Has no effect if the Actor is not started.
Checks the supplied message and throws either STOP or TERMINATE, if the message is a Stop or Terminate message respectively.
toProcess
- The next message to process by the actorsTransfers messages from the input queue into the output queue, reverting the order of the elements.
Copyright © 2008–2014 Václav Pech. All Rights Reserved.