groovyx.gpars.actor
Class DynamicDispatchActor
java.lang.Object
groovyx.gpars.serial.WithSerialId
groovyx.gpars.actor.impl.MessageStream
groovyx.gpars.actor.Actor
groovyx.gpars.actor.AbstractLoopingActor
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
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, sendAndPromise, sweepQueue, threadBoundActor |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
DynamicDispatchActor
public DynamicDispatchActor()
- Creates a new instance without any when handlers registered
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)