Implements most of Agent's public method in Java
Modifiers | Name | Description |
---|---|---|
private static class |
AgentBase.AwaitClosure |
Returns the current value of the Agent's state |
Modifiers | Name | Description |
---|---|---|
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 T |
data |
Holds the internal mutable state |
private java.util.Collection<groovy.lang.Closure> |
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<groovy.lang.Closure> |
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 | Fields |
---|---|
class AgentCore |
core, currentThread, errors |
class WithSerialId |
serialHandle, serialVersionUID |
Type | Name and description |
---|---|
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 |
T |
getInstantVal() A shorthand method for safe message-based retrieval of the internal state. |
T |
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(T message) Other messages than closures are accepted as new values for the internal state |
T |
sendAndWait(groovy.lang.Closure message) Submits the closure waiting for the result |
void |
updateValue(T 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 | Name |
---|---|
class AgentCore |
attachToThreadPool, call, getErrors, handleMessage, hasErrors, isFair, leftShift, makeFair, registerError, send, setPGroup |
class WithSerialId |
createRemoteHandle, getOrCreateSerialHandle, getRemoteClass, writeReplace |
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Function converting the internal state during read to prevent internal state escape from the protected boundary of the agent
Holds the internal mutable state
Holds all listeners interested in state updates A listener should be a closure accepting the old and the new value in this order.
Allows reads not to wait in the message queue. Writes and reads are mutually separated by using write or read locks respectively.
Holds all validators checking the agent's state A validator should be a closure accepting the old and the new value in this order.
Creates a new Agent around the supplied modifiable object
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 outAdds 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.
listener
- The closure with two or three argumentsAdds 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.
validator
- The closure with two or three argumentsBlocks until all messages in the queue prior to call to await() complete. Provides a means to synchronize with the Agent
Only two-argument closures are allowed
code
- The passed-in closureA shorthand method for safe message-based retrieval of the internal state. Retrieves the internal state immediately by-passing the queue of tasks waiting to be processed.
A shorthand method for safe message-based retrieval of the internal state. The request to retrieve a value is put into the message queue, so will wait for all messages delivered earlier to complete.
Accepts a NullObject instance and sets the internal state to null
obj
- The received messageAccepts and invokes the closure
code
- The received messageOther messages than closures are accepted as new values for the internal state
message
- The received messageSubmits the closure waiting for the result
message
- The message/closure to sendAllows closures to set the new internal state as a whole Do not call this method directly from the outside. It is designed to be used from within the submitted closures.
newValue
- The value to set the internal state toA shorthand method for safe asynchronous message-based retrieval of the internal state. The request to retrieve a value is put into the message queue, so will wait for all messages delivered earlier to complete.
callback
- A closure to invoke with the internal state as a parameterCopyright © 2008–2014 Václav Pech. All Rights Reserved.