org.codehaus.gpars

groovyx.gpars.actor
[Java] Class AbstractLoopingActor

java.lang.Object
  groovyx.gpars.serial.WithSerialId
      groovyx.gpars.actor.impl.MessageStream
          groovyx.gpars.actor.Actor
              groovyx.gpars.actor.AbstractLoopingActor

public abstract class AbstractLoopingActor
extends Actor

Wraps all actors that repeatedly loop through incoming messages and hold no implicit state between subsequent messages.

Authors:
Vaclav Pech Date: Aug 23, 2010


Field Summary
private AsyncMessagingCore core

private MessageStream currentSender

private ActorTimerTask currentTimerTask

private static long serialVersionUID

private boolean stoppedFlag

private boolean terminatedFlag

boolean terminatingFlag

private int timeoutCounter

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

 
Method Summary
private void cancelCurrentTimeoutTask()

private Actor doStart()

AsyncMessagingCore getCore()

MessageStream getSender()

protected boolean hasBeenStopped()

protected void initialize(groovy.lang.Closure code)

boolean isActive()

Removes the head of the message queue

boolean isFair()

Retrieves the actor's fairness flag Fair actors give up the thread after processing each message, non-fair actors keep a thread until their message queue is empty.

void makeFair()

void reply(java.lang.Object message)

Sends a reply to all currently processed messages, which have been sent by an actor.

void replyIfExists(java.lang.Object message)

private void runEnhancedWithoutRepliesOnMessages(ActorMessage message, groovy.lang.Closure code, java.lang.Object arguments)

MessageStream send(java.lang.Object message)

void setParallelGroup(PGroup group)

protected void setTimeout(long timeout)

Actor silentStart()

Starts the Actor and sends it the START_MESSAGE to run any afterStart handlers.

Actor start()

Actor stop()

protected ActorMessage sweepNextMessage()

Actor terminate()

 
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, sendAndPromise, 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
 

Field Detail

core

private AsyncMessagingCore core


currentSender

private MessageStream currentSender


currentTimerTask

private ActorTimerTask currentTimerTask


serialVersionUID

private static final long serialVersionUID


stoppedFlag

private boolean stoppedFlag


terminatedFlag

private boolean terminatedFlag


terminatingFlag

boolean terminatingFlag


timeoutCounter

private int timeoutCounter


 
Constructor Detail

AbstractLoopingActor

AbstractLoopingActor()


 
Method Detail

cancelCurrentTimeoutTask

private void cancelCurrentTimeoutTask()


doStart

private Actor doStart()


getCore

final AsyncMessagingCore getCore()


getSender

public final MessageStream getSender()


hasBeenStopped

@java.lang.Override}
protected final boolean hasBeenStopped()


initialize

protected final void initialize(groovy.lang.Closure code)


isActive

@java.lang.Override
public final boolean isActive()
Removes the head of the message queue
Returns:
The head message, or null, if the message queue is empty


isFair

public final boolean isFair()
Retrieves the actor's fairness flag Fair actors give up the thread after processing each message, non-fair actors keep a thread until their message queue is empty. Non-fair actors tend to perform better than fair ones.
Returns:
True for fair actors, false for non-fair ones. actors are non-fair by default.


makeFair

public final void makeFair()


reply

public final void reply(java.lang.Object message)
Sends a reply to all currently processed messages, which have been sent by an actor. Ignores potential errors when sending the replies, like no sender or sender already stopped.
Parameters:
message - reply message


replyIfExists

public final void replyIfExists(java.lang.Object message)


runEnhancedWithoutRepliesOnMessages

private void runEnhancedWithoutRepliesOnMessages(ActorMessage message, groovy.lang.Closure code, java.lang.Object arguments)


send

@java.lang.Overridereturn currentSender;
public MessageStream send(java.lang.Object message)


setParallelGroup

@java.lang.Override*
public void setParallelGroup(PGroup group)


setTimeout

protected final void setTimeout(long timeout)


silentStart

@java.lang.Override
public Actor silentStart()
Starts the Actor and sends it the START_MESSAGE to run any afterStart handlers. No messages can be sent or received before an Actor is started.
Returns:
same actor


start

@java.lang.Overrideif (!hasBeenStopped()) {
public Actor start()


stop

@java.lang.Overrideif (isActorThread()) {
public final Actor stop()


sweepNextMessage

@java.lang.Override*
protected ActorMessage sweepNextMessage()


terminate

@java.lang.OverridecurrentThread.interrupt();  //NPE may occur non-deterministically, since we're running concurrently with the actor's thread
public final Actor terminate()


 

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