Groovy Documentation

gpars.actor.impl
[Java] Class SequentialProcessingActor

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

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

Authors:
Alex Tkachman, Vaclav Pech


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(groovy.time.Duration duration, groovy.lang.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(groovy.lang.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, groovy.lang.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, groovy.lang.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()

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
Parameters:
exception - The exception that was fired


doOnInterrupt

protected void doOnInterrupt(InterruptedException exception)
Allows subclasses to add behavior to run after actor's interruption
Parameters:
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
Returns:
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.
Parameters:
code - The closure to invoke repeatedly


pollMessage

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


react

protected final void react(groovy.time.Duration duration, groovy.lang.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.
Parameters:
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.
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(groovy.lang.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.
Parameters:
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, groovy.lang.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.
Parameters:
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.
timeUnit - a TimeUnit determining how to interpret the timeout parameter
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, groovy.lang.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.
Parameters:
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.
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()


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.
Parameters:
group - new group


start

@Override
public final SequentialProcessingActor start()
Starts the Actor. No messages can be send or received before an Actor is started.
Returns:
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
Returns:
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.
throws:
InterruptedException If the thread gets interrupted.
Returns:
The message


takeMessage

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


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.
Returns:
this (the actor itself) to allow method chaining


 

Groovy Documentation