groovyx.gpars.actor
Class DynamicDispatchActor

java.lang.Object
  extended by groovyx.gpars.serial.WithSerialId
      extended by groovyx.gpars.actor.impl.MessageStream
          extended by groovyx.gpars.actor.Actor
              extended by groovyx.gpars.actor.AbstractLoopingActor
                  extended by groovyx.gpars.actor.DynamicDispatchActor
All Implemented Interfaces:
java.io.Serializable

public class DynamicDispatchActor
extends AbstractLoopingActor

A pooled actor allowing for an alternative structure of the message handling code. In general DynamicDispatchActor repeatedly scans for messages and dispatches arrived messages to one of the onMessage(message) methods defined on the actor.

 final class MyActor extends DynamicDispatchActor {*      void onMessage(String message) {*          println 'Received string'
 }*      void onMessage(Integer message) {*          println 'Received integer'
 }*      void onMessage(Object message) {*          println 'Received object'
 }*      void onMessage(NullObject nullMessage) {*          println 'Received null'
 }*} 
Method when {...} provides an alternative way to define message handlers

Author:
Vaclav Pech, Alex Tkachman, Dierk Koenig Date: Jun 26, 2009
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class groovyx.gpars.actor.Actor
Actor.MyRemoteHandle, Actor.RemoteActor
 
Nested classes/interfaces inherited from class groovyx.gpars.actor.impl.MessageStream
MessageStream.RemoteMessageStream, MessageStream.SendTo
 
Field Summary
private static long serialVersionUID
           
 
Fields inherited from class groovyx.gpars.actor.AbstractLoopingActor
terminatingFlag
 
Fields inherited from class groovyx.gpars.actor.Actor
ACTOR_HAS_ALREADY_BEEN_STARTED, CANNOT_SEND_REPLIES_NO_SENDER_HAS_BEEN_REGISTERED, currentThread, parallelGroup, START_MESSAGE, STOP_MESSAGE, TERMINATE_MESSAGE, TIMEOUT, TIMEOUT_MESSAGE, timer
 
Fields inherited from class groovyx.gpars.serial.WithSerialId
serialHandle
 
Constructor Summary
DynamicDispatchActor()
          Creates a new instance without any when handlers registered
 
Method Summary
 DynamicDispatchActor become(groovy.lang.Closure closure)
          Executes the supplied closure in the context of the actor to set all when() handlers
 void when(groovy.lang.Closure closure)
           
 
Methods inherited from class groovyx.gpars.actor.AbstractLoopingActor
getCore, getSender, hasBeenStopped, initialize, isActive, isFair, makeFair, reply, replyIfExists, send, setParallelGroup, setTimeout, silentStart, start, stop, sweepNextMessage, terminate
 
Methods inherited from class groovyx.gpars.actor.Actor
createActorMessage, createRemoteHandle, deregisterCurrentActorWithThread, getJoinLatch, getParallelGroup, handleException, handleInterrupt, handleStart, handleTermination, handleTimeout, isActorThread, join, join, join, join, onStop, registerCurrentActorWithThread, sendAndContinue, sweepQueue, threadBoundActor
 
Methods inherited from class groovyx.gpars.actor.impl.MessageStream
call, getRemoteClass, leftShift, send, send, sendAndWait, sendAndWait, sendAndWait
 
Methods inherited from class groovyx.gpars.serial.WithSerialId
getOrCreateSerialHandle, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

DynamicDispatchActor

public DynamicDispatchActor()
Creates a new instance without any when handlers registered

Method Detail

become

public final DynamicDispatchActor become(groovy.lang.Closure closure)
Executes the supplied closure in the context of the actor to set all when() handlers

Parameters:
closure - A sequence of when() handlers to set on the actor
Returns:
This actor to allow for method chaining

when

public final void when(groovy.lang.Closure closure)

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