|
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
Returns the current value of the Agent's state |
Field Summary | |
---|---|
private static groovy.lang.Closure |
awaitClosure
|
private groovy.lang.Closure |
copy
Function converting the internal state during read to prevent internal state escape from the protected boundary of the agent |
protected java.lang.Object |
data
Holds the internal mutable state |
private java.util.Collection |
listeners
Holds all listeners interested in state updates A listener should be a closure accepting the old and the new value in this order. |
protected java.util.concurrent.locks.ReadWriteLock |
lock
Allows reads not to wait in the message queue. |
private java.util.Collection |
validators
Holds all validators checking the agent's state A validator should be a closure accepting the old and the new value in this order. |
Fields inherited from class AgentCore | |
---|---|
core, errors |
Constructor Summary | |
AgentBase(java.lang.Object data)
|
|
AgentBase(java.lang.Object data, groovy.lang.Closure copy)
Creates a new Agent around the supplied modifiable object |
Method Summary | |
---|---|
void
|
addListener(groovy.lang.Closure listener)
Adds a listener interested in state updates 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)
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
|
await()
Blocks until all messages in the queue prior to call to await() complete. |
private groovy.lang.Closure
|
checkClosure(groovy.lang.Closure code)
Only two-argument closures are allowed |
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 message-based retrieval of the internal state. |
void
|
onMessage(org.codehaus.groovy.runtime.NullObject obj)
Accepts a NullObject instance and sets the internal state to null |
void
|
onMessage(groovy.lang.Closure code)
Accepts and invokes the closure |
void
|
onMessage(java.lang.Object message)
Other messages than closures are accepted as new values for the internal state |
java.lang.Object
|
sendAndWait(groovy.lang.Closure message)
Submits the closure waiting for the result |
void
|
updateValue(java.lang.Object newValue)
Allows closures to set the new internal state as a whole Do not call this method directly from the outside. |
void
|
valAsync(groovy.lang.Closure callback)
A shorthand method for safe asynchronous message-based retrieval of the internal state. |
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)
data
- The object to use for storing the internal state of the variablecopy
- A closure to use to create a copy of the internal state when sending the internal state out
Method Detail |
---|
public void addListener(groovy.lang.Closure listener)
listener
- The closure with two or three arguments
public void addValidator(groovy.lang.Closure validator)
validator
- The closure with two or three arguments
public final void await()
private groovy.lang.Closure checkClosure(groovy.lang.Closure code)
code
- The passed-in closure
@SuppressWarnings({"unchecked"}) public final java.lang.Object getInstantVal()
public final java.lang.Object getVal()
final void onMessage(org.codehaus.groovy.runtime.NullObject obj)
obj
- The received message
final void onMessage(groovy.lang.Closure code)
code
- The received message
final void onMessage(java.lang.Object message)
message
- The received message
@SuppressWarnings({"unchecked"}) public final java.lang.Object sendAndWait(groovy.lang.Closure message)
message
- The message/closure to send
@SuppressWarnings({"unchecked", "CatchGenericClass"}) public final void updateValue(java.lang.Object newValue)
newValue
- The value to set the internal state to
public final void valAsync(groovy.lang.Closure callback)
callback
- A closure to invoke with the internal state as a parameter
Copyright © 2008–2012 Václav Pech. All Rights Reserved.