Groovy Documentation

gpars.actor.impl
Class SequentialProcessingActor

java.lang.Object
  groovyx.gpars.actor.Actor
      gpars.actor.impl.SequentialProcessingActor
All Implemented Interfaces:
Runnable

@SuppressWarnings({"UnqualifiedStaticUsage"})
class SequentialProcessingActor
extends Actor

author:
Alex Tkachman, Vaclav Pech


Nested Class Summary
class SequentialProcessingActor.MultiMessageReaction

Enables multiple argument closures to be passed to react().

class SequentialProcessingActor.Node

Represents an element in the message queue.

class SequentialProcessingActor.Reaction

Buffers messages for the next continuation of an event-driven actor, handles timeouts and no-param continuations.

 
Field Summary
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

protected PGroup actorGroup

The actor group to which the actor belongs

protected Runnable loopCode

Code for the loop, if any

protected int stopFlag

Indicates whether the actor should terminate

protected static AtomicIntegerFieldUpdater stopFlagUpdater

 
Constructor Summary
protected SequentialProcessingActor()

Creates a new instance, sets the default actor group.

 
Method Summary
protected void checkStopTerminate()

protected void doOnException(Throwable exception)

Allows subclasses to add behavior to run after exception in actor's body

protected void doOnInterrupt(InterruptedException exception)

Allows subclasses to add behavior to run after actor's interruption

protected void doOnStart()

Allows subclasses to add behavior to run after actor's start

protected void doOnTermination()

Allows subclasses to add behavior to run after actor's termination

protected void doOnTimeout()

Allows subclasses to add behavior to run after actor's timeout

PGroup getActorGroup()

Retrieves the group to which the actor belongs

boolean isActive()

Checks the current status of the Actor.

boolean isActorThread()

Checks whether the current thread is the actor's current thread.

protected void loop(Runnable code)

Ensures that the supplied closure will be invoked repeatedly in a loop.

protected ActorMessage pollMessage()

Polls a message from the queues

protected void react(Duration duration, Closure code)

Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure.

protected void react(Closure code)

Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure.

protected void react(long timeout, TimeUnit timeUnit, Closure code)

Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure.

protected void react(long timeout, Closure code)

Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure.

void run()

void runReaction(ActorMessage message, Closure code)

protected void scheduleLoop()

MessageStream send(Object message)

void setActorGroup(PGroup group)

Sets the actor's group.

SequentialProcessingActor start()

Starts the Actor.

Actor stop()

Send message to stop to the actor.

protected ActorMessage takeMessage()

Takes a message from the queues.

protected ActorMessage takeMessage(long timeout, TimeUnit timeUnit)

Takes a message from the queues.

Actor terminate()

Terminate the Actor.

 

Field Detail

S_ACTIVE_MASK

protected static final int S_ACTIVE_MASK


S_FINISHED_MASK

protected static final int S_FINISHED_MASK


S_FINISHING_MASK

protected static final int S_FINISHING_MASK


S_NOT_STARTED

protected static final int S_NOT_STARTED


S_RUNNING

protected static final int S_RUNNING


S_STOPPED

protected static final int S_STOPPED


S_STOPPING

protected static final int S_STOPPING


S_STOP_TERMINATE_MASK

protected static final int S_STOP_TERMINATE_MASK


S_TERMINATED

protected static final int S_TERMINATED


S_TERMINATING

protected static final int S_TERMINATING


actorGroup

protected PGroup actorGroup
The actor group to which the actor belongs


loopCode

protected Runnable loopCode
Code for the loop, if any


stopFlag

protected int stopFlag
Indicates whether the actor should terminate


stopFlagUpdater

protected static final AtomicIntegerFieldUpdater stopFlagUpdater


 
Constructor Detail

SequentialProcessingActor

protected SequentialProcessingActor()
Creates a new instance, sets the default actor group.


 
Method Detail

checkStopTerminate

protected final void checkStopTerminate()


doOnException

protected void doOnException(Throwable exception)
Allows subclasses to add behavior to run after exception in actor's body
param:
exception The exception that was fired


doOnInterrupt

protected void doOnInterrupt(InterruptedException exception)
Allows subclasses to add behavior to run after actor's interruption
param:
exception The InterruptedException


doOnStart

protected void doOnStart()
Allows subclasses to add behavior to run after actor's start


doOnTermination

protected void doOnTermination()
Allows subclasses to add behavior to run after actor's termination


doOnTimeout

protected void doOnTimeout()
Allows subclasses to add behavior to run after actor's timeout


getActorGroup

public PGroup getActorGroup()
Retrieves the group to which the actor belongs
return:
The actor's group


isActive

@Override
public final boolean isActive()
Checks the current status of the Actor.


isActorThread

@Override
public final boolean isActorThread()
Checks whether the current thread is the actor's current thread.


loop

protected final void loop(Runnable code)
Ensures that the supplied closure will be invoked repeatedly in a loop. The method never returns, but instead frees the processing thread back to the thread pool.
param:
code The closure to invoke repeatedly


pollMessage

protected final ActorMessage pollMessage()
Polls a message from the queues
return:
The message


react

protected final void react(Duration duration, Closure code)
Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure. The method never returns, but instead frees the processing thread back to the thread pool.
param:
duration Time to wait at most for a message to arrive. The actor terminates if a message doesn't arrive within the given timeout. The TimeCategory DSL to specify timeouts must be enabled explicitly inside the Actor's act() method.
param:
code The code to handle the next message. The reply() and replyIfExists() methods are available inside the closure to send a reply back to the actor, which sent the original message.


react

protected final void react(Closure code)
Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure. The method never returns, but instead frees the processing thread back to the thread pool.
param:
code The code to handle the next message. The reply() and replyIfExists() methods are available inside the closure to send a reply back to the actor, which sent the original message.


react

protected final void react(long timeout, TimeUnit timeUnit, Closure code)
Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure. The method never returns, but instead frees the processing thread back to the thread pool.
param:
timeout Time in milliseconds to wait at most for a message to arrive. The actor terminates if a message doesn't arrive within the given timeout.
param:
timeUnit a TimeUnit determining how to interpret the timeout parameter
param:
code The code to handle the next message. The reply() and replyIfExists() methods are available inside the closure to send a reply back to the actor, which sent the original message.


react

protected final void react(long timeout, Closure code)
Schedules an ActorAction to take the next message off the message queue and to pass it on to the supplied closure. The method never returns, but instead frees the processing thread back to the thread pool. Also adds reply() and replyIfExists() methods to the currentActor 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.
param:
timeout Time in milliseconds to wait at most for a message to arrive. The actor terminates if a message doesn't arrive within the given timeout.
param:
code The code to handle the next message. The reply() and replyIfExists() methods are available inside the closure to send a reply back to the actor, which sent the original message.


run

@SuppressWarnings({"ThrowCaughtLocally"})
public void run()


runReaction

public void runReaction(ActorMessage message, Closure code)


scheduleLoop

protected void scheduleLoop()


send

@Override
public final MessageStream send(Object message)


setActorGroup

public final void setActorGroup(PGroup group)
Sets the actor's group. It can only be invoked before the actor is started.
param:
group new group


start

@Override
public final SequentialProcessingActor start()
Starts the Actor. No messages can be send or received before an Actor is started.
return:
this (the actor itself) to allow method chaining


stop

@Override
public final Actor stop()
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
return:
this (the actor itself) to allow method chaining


takeMessage

protected final ActorMessage takeMessage()
Takes a message from the queues. Blocks until a message is available.
return:
The message
throws:
InterruptedException If the thread gets interrupted.


takeMessage

protected ActorMessage takeMessage(long timeout, TimeUnit timeUnit)
Takes a message from the queues. Blocks until a message is available.
param:
timeout Max time to wait for a message
param:
timeUnit The units for the timeout
return:
The message
throws:
InterruptedException If the thread gets interrupted.


terminate

@Override
public final Actor terminate()
Terminate 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.
return:
this (the actor itself) to allow method chaining


 

Groovy Documentation