|
org.codehaus.gpars | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovyx.gpars.agent.AgentCore groovyx.gpars.agent.AgentBase
abstract class AgentBase extends AgentCore
Implements most of Agent's public method in Java
Nested Class Summary | |
---|---|
private static class |
AgentBase.AwaitClosure
|
Field Summary | |
---|---|
private static groovy.lang.Closure |
awaitClosure
|
private groovy.lang.Closure |
copy
|
protected java.lang.Object |
data
|
private java.util.Collection |
listeners
|
protected java.util.concurrent.locks.ReadWriteLock |
lock
|
private java.util.Collection |
validators
|
Fields inherited from class AgentCore | |
---|---|
core, currentThread, errors |
Constructor Summary | |
AgentBase(java.lang.Object data)
|
|
AgentBase(java.lang.Object data, groovy.lang.Closure copy)
Accepts a NullObject instance and sets the internal state to null |
Method Summary | |
---|---|
void
|
addListener(groovy.lang.Closure listener)
Adds a validator checking the agent's state A listener should be a closure accepting the old and the new value in this order plus optionally the agent reference as the first argument. |
void
|
addValidator(groovy.lang.Closure validator)
Only two-argument closures are allowed |
void
|
await()
Blocks until all messages in the queue prior to call to await() complete. |
private groovy.lang.Closure
|
checkClosure(groovy.lang.Closure code)
Returns the current value of the Agent's state |
java.lang.Object
|
getInstantVal()
A shorthand method for safe message-based retrieval of the internal state. |
java.lang.Object
|
getVal()
A shorthand method for safe asynchronous message-based retrieval of the internal state. |
void
|
onMessage(org.codehaus.groovy.runtime.NullObject obj)
Accepts and invokes the closure |
void
|
onMessage(groovy.lang.Closure code)
Other messages than closures are accepted as new values for the internal state |
void
|
onMessage(java.lang.Object message)
Allows closures to set the new internal state as a whole Do not call this method directly from the outside. |
java.lang.Object
|
sendAndWait(groovy.lang.Closure message)
|
void
|
updateValue(java.lang.Object newValue)
|
void
|
valAsync(groovy.lang.Closure callback)
|
Methods inherited from class AgentCore | |
---|---|
attachToThreadPool, call, getErrors, handleMessage, hasErrors, isFair, leftShift, makeFair, registerError, send, setPGroup |
Field Detail |
---|
private static final groovy.lang.Closure awaitClosure
private final groovy.lang.Closure copy
protected java.lang.Object data
private final java.util.Collection listeners
protected java.util.concurrent.locks.ReadWriteLock lock
private final java.util.Collection validators
Constructor Detail |
---|
AgentBase(java.lang.Object data)
AgentBase(java.lang.Object data, groovy.lang.Closure copy)
obj
- The received message
Method Detail |
---|
public void addListener(groovy.lang.Closure listener)
validator
- The closure with two or three arguments
public void addValidator(groovy.lang.Closure validator)
code
- The passed-in closure
public final void await()
private groovy.lang.Closure checkClosure(groovy.lang.Closure code)
@java.lang.SuppressWarnings* @throws InterruptedException If the thread gets interrupted while waiting for a value to be bound public final java.lang.Object getInstantVal()
public final java.lang.Object getVal()
callback
- A closure to invoke with the internal state as a parameter
final void onMessage(org.codehaus.groovy.runtime.NullObject obj)
code
- The received message
final void onMessage(groovy.lang.Closure code)
message
- The received message
final void onMessage(java.lang.Object message)
newValue
- The value to set the internal state to
@java.lang.SuppressWarnings}); public final java.lang.Object sendAndWait(groovy.lang.Closure message)
@java.lang.SuppressWarningslistener.call(new Object[]{oldValue, newValue}); public final void updateValue(java.lang.Object newValue)
public final void valAsync(groovy.lang.Closure callback)
Copyright © 2008–2013 Václav Pech. All Rights Reserved.