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

Holds the particular instance of async messaging core to use

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

protected MessageStream getSender()

Retrieves the sender actor of the currently processed message.

protected boolean hasBeenStopped()

protected void initialize(groovy.lang.Closure code)

Builds the async messaging core using the supplied code handler

boolean isActive()

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

Makes the actor fair.

protected void reply(java.lang.Object message)

Sends a reply to all currently processed messages.

protected void replyIfExists(java.lang.Object message)

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

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 without sending the START_MESSAGE message to speed the start-up.

Actor start()

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

Actor stop()

protected ActorMessage sweepNextMessage()

Removes the head of the message queue

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

core

private AsyncMessagingCore core
Holds the particular instance of async messaging core to use


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

protected final MessageStream getSender()
Retrieves the sender actor of the currently processed message.
throws:
groovyx.gpars.actor.impl.ActorReplyException If some of the replies failed to be sent.
Returns:
The sender of the currently processed message or null, if the message was not sent by an actor


hasBeenStopped

@Override
protected final boolean hasBeenStopped()


initialize

protected final void initialize(groovy.lang.Closure code)
Builds the async messaging core using the supplied code handler
Parameters:
code - Code to run on each message


isActive

@Override
public final boolean isActive()


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()
Makes the actor fair. Actors are non-fair by default. 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.


reply

protected final void reply(java.lang.Object message)
Sends a reply to all currently processed messages. Throws ActorReplyException if some messages have not been sent by an actor. For such cases use replyIfExists().
throws:
groovyx.gpars.actor.impl.ActorReplyException If some of the replies failed to be sent.
Parameters:
message - reply message


replyIfExists

protected final void replyIfExists(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


runEnhancedWithoutRepliesOnMessages

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


send

@Override
public MessageStream send(java.lang.Object message)


setParallelGroup

@Override
public void setParallelGroup(PGroup group)


setTimeout

protected final void setTimeout(long timeout)


silentStart

@Override
public Actor silentStart()
Starts the Actor without sending the START_MESSAGE message to speed the start-up. The potential custom afterStart handlers won't be run. No messages can be sent or received before an Actor is started.
Returns:
same actor


start

@Override
public Actor start()
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


stop

@Override
public final Actor stop()


sweepNextMessage

@Override
protected ActorMessage sweepNextMessage()
Removes the head of the message queue
Returns:
The head message, or null, if the message queue is empty


terminate

@Override
public final Actor terminate()


 

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