org.actorsguildframework
Class ImmediateResult<T>

java.lang.Object
  extended by org.actorsguildframework.ImmediateResult<T>
Type Parameters:
T - the type of the result
All Implemented Interfaces:
Serializable, AsyncResult<T>, Immutable

public final class ImmediateResult<T>
extends Object
implements AsyncResult<T>, Immutable

ImmediateResult is an AsyncResult implementation that can be used when the result is already available. It is the easiest and most common way to implement the return value in a Message method.

See Also:
Actor.result(Object), Actor.noResult(), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.actorsguildframework.AsyncResult
AsyncResult.Notifier<T>
 
Constructor Summary
ImmediateResult(T value)
          Creates a new ImmediateResult instance with the given result value.
 
Method Summary
 void addNotifier(AsyncResult.Notifier<T> notifier)
          Adds a notifier.
 void await()
          Does nothing, as the result is always ready in this implementation.
 T get()
          Returns the value immediately, as the result is always ready in this implementation.
 Throwable getException()
          This implementation will always return null.
 boolean isReady()
          Always returns true, as the result is always ready in this implementation.
 void removeNotifier(AsyncResult.Notifier<T> notifier)
          Adds a notifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImmediateResult

public ImmediateResult(T value)
Creates a new ImmediateResult instance with the given result value. ImmediateResult is usually used inside an Actor, which offers the convenient helper function @{link Actor#result(Object)} to create new instances.

Parameters:
value - the result value
See Also:
Actor.result(Object)
Method Detail

get

public T get()
Returns the value immediately, as the result is always ready in this implementation. It may be a copy of the original value. This implementation will never throw an exception.

Specified by:
get in interface AsyncResult<T>
Returns:
the result
See Also:
AsyncResult.await(), AsyncResult.addNotifier(org.actorsguildframework.AsyncResult.Notifier)

await

public void await()
Does nothing, as the result is always ready in this implementation.

Specified by:
await in interface AsyncResult<T>
See Also:
AsyncResult.addNotifier(org.actorsguildframework.AsyncResult.Notifier), AsyncResult.isReady(), DefaultAgent.awaitAll(AsyncResult...), DefaultAgent.awaitAny(AsyncResult...)

isReady

public boolean isReady()
Always returns true, as the result is always ready in this implementation.

Specified by:
isReady in interface AsyncResult<T>
Returns:
always true
See Also:
AsyncResult.await()

addNotifier

public void addNotifier(AsyncResult.Notifier<T> notifier)
Adds a notifier. This implementation will always invoke the notifier immediately in the same thread.

Specified by:
addNotifier in interface AsyncResult<T>
Parameters:
notifier - the notifier to add
Throws:
IllegalArgumentException - if the argument was null
See Also:
AsyncResult.removeNotifier(org.actorsguildframework.AsyncResult.Notifier)

removeNotifier

public void removeNotifier(AsyncResult.Notifier<T> notifier)
Adds a notifier. This implementation will do nothing, as the notifier is always invoked immediately in the same thread.

Specified by:
removeNotifier in interface AsyncResult<T>
Parameters:
notifier - the notifier to remove
Throws:
IllegalArgumentException - if the argument was null
See Also:
AsyncResult.addNotifier(org.actorsguildframework.AsyncResult.Notifier)

getException

public Throwable getException()
This implementation will always return null.

Specified by:
getException in interface AsyncResult<T>
Returns:
always null