org.codehaus.gpars

groovyx.gpars.actor
[Java] Class Actor

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

public abstract class Actor
extends MessageStream

Actors are active objects, which borrow a thread from a thread pool. The Actor interface provides means to send messages to the actor, start and stop the background thread as well as check its status.

Authors:
Vaclav Pech, Alex Tkachman


Nested Class Summary
static class Actor.MyRemoteHandle

static class Actor.RemoteActor

 
Field Summary
protected static java.lang.String ACTOR_HAS_ALREADY_BEEN_STARTED

private static java.lang.String AFTER_START

static java.lang.String CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED

private static java.lang.Object[] EMPTY_ARGUMENTS

private static java.lang.String ON_DELIVERY_ERROR

private static java.lang.String RESPONDS_TO

protected static ActorMessage START_MESSAGE

protected static ActorMessage STOP_MESSAGE

protected static ActorMessage TERMINATE_MESSAGE

static java.lang.String TIMEOUT

protected static ActorMessage TIMEOUT_MESSAGE

private static java.lang.ThreadLocal currentActorPerThread

protected java.lang.Thread currentThread

private DataflowExpression joinLatch

private groovy.lang.Closure onStop

protected PGroup parallelGroup

private static long serialVersionUID

protected static GeneralTimer timer

 
Fields inherited from class MessageStream
serialVersionUID
 
Fields inherited from class WithSerialId
serialHandle, serialVersionUID
 
Constructor Summary
protected Actor()

protected Actor(DataflowExpression joinLatch)

Retrieves the group to which the actor belongs

protected Actor(DataflowExpression joinLatch, PGroup parallelGroup)

 
Method Summary
private boolean callDynamic(java.lang.String method, java.lang.Object[] args)

protected ActorMessage createActorMessage(java.lang.Object message)

protected RemoteHandle createRemoteHandle(SerialHandle handle, SerialContext host)

protected static void deregisterCurrentActorWithThread()

DataflowExpression getJoinLatch()

PGroup getParallelGroup()

protected void handleException(java.lang.Throwable exception)

protected void handleInterrupt(java.lang.InterruptedException exception)

protected void handleStart()

protected void handleTermination()

Set on stop handler for this actor

protected void handleTimeout()

protected boolean hasBeenStopped()

boolean isActive()

boolean isActorThread()

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

void join()

void join(MessageStream listener)

void join(long timeout, java.util.concurrent.TimeUnit unit)

Joins the actor.

void join(groovy.time.BaseDuration duration)

Join-point for this actor

void onStop(groovy.lang.Closure onStop)

protected static void registerCurrentActorWithThread(Actor currentActor)

MessageStream sendAndContinue(java.lang.Object message, groovy.lang.Closure closure)

Sends a message and returns a promise for the reply.

Promise sendAndPromise(java.lang.Object message)

void setParallelGroup(PGroup group)

Sends a message and execute continuation when reply became available.

Actor silentStart()

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

Actor start()

Actor stop()

protected ActorMessage sweepNextMessage()

Clears the message queue returning all the messages it held.

java.util.List sweepQueue()

Actor terminate()

Joins the actor.

static Actor 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

ACTOR_HAS_ALREADY_BEEN_STARTED

protected static final java.lang.String ACTOR_HAS_ALREADY_BEEN_STARTED


AFTER_START

private static final java.lang.String AFTER_START


CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED

public static final java.lang.String CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED


EMPTY_ARGUMENTS

private static final java.lang.Object[] EMPTY_ARGUMENTS


ON_DELIVERY_ERROR

private static final java.lang.String ON_DELIVERY_ERROR


RESPONDS_TO

private static final java.lang.String RESPONDS_TO


START_MESSAGE

protected static final ActorMessage START_MESSAGE


STOP_MESSAGE

protected static final ActorMessage STOP_MESSAGE


TERMINATE_MESSAGE

protected static final ActorMessage TERMINATE_MESSAGE


TIMEOUT

@java.lang.SuppressWarnings}
public static final java.lang.String TIMEOUT


TIMEOUT_MESSAGE

protected static final ActorMessage TIMEOUT_MESSAGE


currentActorPerThread

private static final java.lang.ThreadLocal currentActorPerThread


currentThread

protected java.lang.Thread currentThread


joinLatch

private final DataflowExpression joinLatch


onStop

private groovy.lang.Closure onStop


parallelGroup

protected PGroup parallelGroup


serialVersionUID

private static final long serialVersionUID


timer

protected static final GeneralTimer timer


 
Constructor Detail

Actor

protected Actor()


Actor

protected Actor(DataflowExpression joinLatch)
Retrieves the group to which the actor belongs
Returns:
The group


Actor

protected Actor(DataflowExpression joinLatch, PGroup parallelGroup)


 
Method Detail

callDynamic

private boolean callDynamic(java.lang.String method, java.lang.Object[] args)


createActorMessage

protected final ActorMessage createActorMessage(java.lang.Object message)


createRemoteHandle

@java.lang.OverrideonStop.call(queue);
protected RemoteHandle createRemoteHandle(SerialHandle handle, SerialContext host)


deregisterCurrentActorWithThread

protected static void deregisterCurrentActorWithThread()


getJoinLatch

public DataflowExpression getJoinLatch()


getParallelGroup

public final PGroup getParallelGroup()


handleException

@java.lang.SuppressWarnings}
protected void handleException(java.lang.Throwable exception)


handleInterrupt

@java.lang.SuppressWarningsfinal MetaClass metaClass = InvokerHelper.getMetaClass(this);
protected void handleInterrupt(java.lang.InterruptedException exception)


handleStart

@java.lang.SuppressWarnings/**
protected void handleStart()


handleTermination

protected void handleTermination()
Set on stop handler for this actor
Parameters:
onStop - The code to invoke when stopping


handleTimeout

protected void handleTimeout()


hasBeenStopped

protected boolean hasBeenStopped()


isActive

public boolean isActive()


isActorThread

public final boolean isActorThread()
Checks whether the current thread is the actor's current thread.
Returns:
True if invoked from within an actor thread


join

public final void join()


join

public final void join(MessageStream listener)


join

public final void join(long timeout, java.util.concurrent.TimeUnit unit)
Joins the actor. Waits for its termination.
throws:
InterruptedException if interrupted while waiting
Parameters:
duration - timeout to wait


join

public final void join(groovy.time.BaseDuration duration)
Join-point for this actor
Returns:
The DataflowExpression instance, which is used to join this actor


onStop

public final void onStop(groovy.lang.Closure onStop)


registerCurrentActorWithThread

protected static void registerCurrentActorWithThread(Actor currentActor)


sendAndContinue

@java.lang.SuppressWarningspublic final  Promise sendAndPromise(final T message) {
public final MessageStream sendAndContinue(java.lang.Object message, groovy.lang.Closure closure)
        
Sends a message and returns a promise for the reply.
Parameters:
message - message to send
Returns:
The message that came in reply to the original send.


sendAndPromise

@java.lang.SuppressWarnings* No messages can be sent or received before an Actor is started.
public final Promise sendAndPromise(java.lang.Object message)


setParallelGroup

public void setParallelGroup(PGroup group)
Sends a message and execute continuation when reply became available.
Parameters:
message - message to send
closure - closure to execute when reply became available
Returns:
The message that came in reply to the original send.


silentStart

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

public Actor start()


stop

public Actor stop()


sweepNextMessage

protected ActorMessage sweepNextMessage()
Clears the message queue returning all the messages it held.
Returns:
The messages stored in the queue


sweepQueue

@java.lang.SuppressWarningsmessages.add(message);
final java.util.List sweepQueue()


terminate

public Actor terminate()
Joins the actor. Waits for its termination.
throws:
InterruptedException when interrupted while waiting


threadBoundActor

public static Actor threadBoundActor()


 

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