|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.curjent.agent.AgentResult<V>
public class AgentResult<V>
Holder for a future's value. See Futures in org.curjent.agent
for background information on future results and why a task would want to
wrap a result in a holder such as this. The following are concrete examples
for designing a task to return future results.
One option is to design the task to return the result directly:
interface Counter { Future<Integer> getCount(); } class CounterTask { private int count; int getCount() { return count; } }With this design, the task simply returns the value. For this to compile, though, the task cannot add an
implements
clause with the
Counter
interface.
Alternative, the task can return a holder for the value:
class CounterTask implements Counter { private int count; Future<Integer> getCount() { return new AgentResult<Integer>(count); } }This enables the task designer to declare the
Counter
interface
in its implements
clause and thus catch method signature
problems at compile time instead of runtime.
This holder works for Future
and AgentCall
results.
Instances of AgentResult
are not intended to be returned
directly to agent clients. This class is intended as a helper for tasks
returning results for future values. Only the get()
method is
used for this purpose. Other methods return constant values (e.g.,
isDone()
always returns true
) or throw
UnsupportedOperationException
.
Field Summary | |
---|---|
private V |
value
The result's value. |
Constructor Summary | |
---|---|
AgentResult(V value)
Saves the result's value. |
Method Summary | |
---|---|
void |
await()
Does nothing. |
void |
await(CallState state)
Does nothing. |
boolean |
await(CallState state,
long timeout,
TimeUnit unit)
Does nothing and returns false . |
boolean |
cancel(boolean mayInterruptIfRunning)
Does nothing and returns false . |
boolean |
finish()
Does nothing and returns false . |
boolean |
finish(boolean interrupt,
boolean abandon,
V result,
Throwable exception)
Does nothing and returns false . |
boolean |
finish(Throwable exception)
Does nothing and returns false . |
boolean |
finish(V result)
Does nothing and returns false . |
V |
get()
Immediately returns the saved result value. |
V |
get(long timeout,
TimeUnit unit)
Immediately returns the saved result value. |
Object |
getArgument(int index)
Throws UnsupportedOperationException . |
int |
getArgumentCount()
Throws UnsupportedOperationException . |
CallSite |
getCallSite()
Throws UnsupportedOperationException . |
CallStateListener<?> |
getCallStateListener()
Throws UnsupportedOperationException . |
CallStateListener<?> |
getCallStateListener(CallState state)
Throws UnsupportedOperationException . |
CallCompletion |
getCompletion()
Throws UnsupportedOperationException . |
Object |
getData()
Throws UnsupportedOperationException . |
Throwable |
getException()
Throws UnsupportedOperationException . |
long |
getExpirationTimeout()
Throws UnsupportedOperationException . |
long |
getExpirationTimeoutNanos()
Throws UnsupportedOperationException . |
TimeUnit |
getExpirationTimeoutUnit()
Throws UnsupportedOperationException . |
V |
getResult()
Returns the saved result value. |
CallState |
getState()
Always returns FINISHED . |
boolean |
isCancelled()
Always returns false . |
boolean |
isDone()
Always returns true . |
boolean |
isFinished()
Always returns true . |
boolean |
isReentry()
Always returns false . |
void |
run(Runnable runnable)
Throws UnsupportedOperationException . |
void |
setArgument(int index,
Object value)
Throws UnsupportedOperationException . |
boolean |
setCallStateListener(CallState state,
CallStateListener<?> listener)
Throws UnsupportedOperationException . |
CallState |
setCallStateListener(CallStateListener<?> listener)
Throws UnsupportedOperationException . |
void |
setData(Object data)
Throws UnsupportedOperationException . |
void |
setException(Throwable exception)
Throws UnsupportedOperationException . |
boolean |
setExpirationTimeout(long value,
TimeUnit unit)
Throws UnsupportedOperationException . |
void |
setResult(V value)
Throws UnsupportedOperationException . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final V value
get
methods.
Constructor Detail |
---|
public AgentResult(V value)
value
is returned by
this result's get
methods.
Method Detail |
---|
public V get()
get
in interface Future<V>
public V get(long timeout, TimeUnit unit)
timeout
and
unit
arguments are ignored.
get
in interface Future<V>
public boolean cancel(boolean mayInterruptIfRunning)
false
. The argument is ignored.
cancel
in interface Future<V>
public boolean isCancelled()
false
.
isCancelled
in interface Future<V>
public boolean isDone()
true
.
isDone
in interface Future<V>
public void await()
await
in interface AgentCall<V>
public void await(CallState state)
await
in interface AgentCall<V>
state
- Call state to reach or pass.public boolean await(CallState state, long timeout, TimeUnit unit)
false
. All arguments are ignored.
await
in interface AgentCall<V>
state
- Call state to reach or pass. For example, if
state
is EXECUTING
, this method waits until the
call's state is either EXECUTING
or FINISHED
.timeout
- The timeout period. 0
or negative to timeout
immediately. Long.MAX_VALUE
to never timeout.unit
- The timeout units. May be null
if
timeout
is 0
or Long.MAX_VALUE
.
true
if the call state was reached or passed.
false
if the call state was not reached when the timeout
period expired.public boolean finish()
false
.
finish
in interface AgentCall<V>
false
if the call was already FINISHED
;
true
in all other cases.AgentCall.setResult(Object)
,
AgentCall.setException(Throwable)
public boolean finish(V result)
false
. The argument is ignored.
finish
in interface AgentCall<V>
result
- The value of the call's result if successfully finished.
May cause this method to throw an exception if the value is invalid. Sets
the result value to the system default value (0
,
false
, \u0000
, etc.) for primitive types
if result
is null
. Ignored for
void
result types with a result
value of
null
.
true
if successfully transitioned to the
FINISHED
state.AgentCall.setResult(Object)
,
AgentCall.setException(Throwable)
,
AgentCall.finish()
,
AgentCall.finish(boolean, boolean, Object, Throwable)
public boolean finish(Throwable exception)
false
. The argument is ignored.
finish
in interface AgentCall<V>
exception
- The call's exception value if successfully finished.
This value takes precedence over the result
value; i.e., if
exception
is non-null, it is thrown regardless of the
result
value.
true
if successfully transitioned to the
FINISHED
state.AgentCall.setResult(Object)
,
AgentCall.setException(Throwable)
,
AgentCall.finish()
,
AgentCall.finish(boolean, boolean, Object, Throwable)
public boolean finish(boolean interrupt, boolean abandon, V result, Throwable exception)
false
. All arguments are ignored.
finish
in interface AgentCall<V>
interrupt
- If true
and the call is in the
EXECUTING
state with an assigned thread, the executing
thread is interrupted. Ignored if false
.abandon
- If true
and the call is in the
EXECUTING
state, finishes the call and abandons the running
task, leaving it running orphaned in the background. Ignored if
false
.result
- The value of the call's result if successfully finished.
May cause this method to throw an exception if the value is invalid. Sets
the result value to the system default value (0
,
false
, \u0000
, etc.) for primitive types
if result
is null
. Ignored for
void
result types with a result
value of
null
.exception
- The call's exception value if successfully finished.
This value takes precedence over the result
value; i.e., if
exception
is non-null, it is thrown regardless of the
result
value.
true
if successfully transitioned to the
FINISHED
state.public CallSite getCallSite()
UnsupportedOperationException
.
getCallSite
in interface AgentCall<V>
public CallCompletion getCompletion()
UnsupportedOperationException
.
getCompletion
in interface AgentCall<V>
CallCompletion
public Object getData()
UnsupportedOperationException
.
getData
in interface AgentCall<V>
public Throwable getException()
UnsupportedOperationException
.
getException
in interface AgentCall<V>
AgentCall.setException(Throwable)
public Object getArgument(int index)
UnsupportedOperationException
. The argument is
ignored.
getArgument
in interface AgentCall<V>
index
- Index of the argument. The first value is at index
0
and the last at index getArgumentCount() - 1
.public int getArgumentCount()
UnsupportedOperationException
.
getArgumentCount
in interface AgentCall<V>
public V getResult()
getResult
in interface AgentCall<V>
public CallState getState()
FINISHED
.
getState
in interface AgentCall<V>
CallState
public boolean isFinished()
true
.
public boolean isReentry()
false
.
isReentry
in interface AgentCall<V>
public void run(Runnable runnable)
UnsupportedOperationException
. The argument is
ignored.
run
in interface AgentCall<V>
runnable
- Object to run.public void setData(Object data)
UnsupportedOperationException
. The argument is
ignored.
setData
in interface AgentCall<V>
public void setException(Throwable exception)
UnsupportedOperationException
. The argument is
ignored.
setException
in interface AgentCall<V>
AgentCall.getException()
public void setArgument(int index, Object value)
UnsupportedOperationException
. All arguments are
ignored.
setArgument
in interface AgentCall<V>
AgentCall.getArgument(int)
public void setResult(V value)
UnsupportedOperationException
. The argument is
ignored.
setResult
in interface AgentCall<V>
AgentCall.getResult()
public CallStateListener<?> getCallStateListener()
UnsupportedOperationException
.
getCallStateListener
in interface AgentCall<V>
AgentCall.setCallStateListener(CallStateListener)
public CallState setCallStateListener(CallStateListener<?> listener)
UnsupportedOperationException
. The argument is
ignored.
setCallStateListener
in interface AgentCall<V>
AgentCall.setCallStateListener(CallState, CallStateListener)
public CallStateListener<?> getCallStateListener(CallState state)
UnsupportedOperationException
. The argument is
ignored.
getCallStateListener
in interface AgentCall<V>
AgentCall.setCallStateListener(CallState, CallStateListener)
public boolean setCallStateListener(CallState state, CallStateListener<?> listener)
UnsupportedOperationException
. All arguments are
ignored.
setCallStateListener
in interface AgentCall<V>
AgentCall.setCallStateListener(CallStateListener)
public long getExpirationTimeout()
UnsupportedOperationException
.
public TimeUnit getExpirationTimeoutUnit()
UnsupportedOperationException
.
public boolean setExpirationTimeout(long value, TimeUnit unit)
UnsupportedOperationException
. All arguments are
ignored.
setExpirationTimeout
in interface AgentCall<V>
Expiration
public long getExpirationTimeoutNanos()
UnsupportedOperationException
.
getExpirationTimeoutNanos
in interface AgentCall<V>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |