org.actorsguildframework
Interface AsyncResult<T>

Type Parameters:
T - the type of the result
All Known Implementing Classes:
ImmediateResult

public interface AsyncResult<T>

AsyncResult represents a result that may have not been determined yet. It is the return type for all Message methods.


Nested Class Summary
static interface AsyncResult.Notifier<T>
          Implement this interface to receive a notification when the result is ready.
 
Method Summary
 void addNotifier(AsyncResult.Notifier<T> notifier)
          Adds the given Notifier to the AsyncResult.
 void await()
          Blocks until the AsyncResult is ready.
 T get()
          Waits until the result is ready, and then returns it.
 Throwable getException()
          Checks whether the result is ready but the implementation threw an exception.
 boolean isReady()
          Checks whether a result (value or exception) is ready.
 void removeNotifier(AsyncResult.Notifier<T> notifier)
          Removes the given Notifier from the AsyncResult.
 

Method Detail

get

T get()
Waits until the result is ready, and then returns it. If the implementation threw an exception, get() will re-throw the exception.

Returns:
the result
Throws:
WrappedException - if the message implementation threw a non-RuntimeException that needs to be declared
RuntimeException - if the message implementation threw an exception
See Also:
await(), addNotifier(org.actorsguildframework.AsyncResult.Notifier)

await

void await()
Blocks until the AsyncResult is ready.

See Also:
addNotifier(org.actorsguildframework.AsyncResult.Notifier), isReady(), DefaultAgent.awaitAll(AsyncResult...), DefaultAgent.awaitAny(AsyncResult...)

isReady

boolean isReady()
Checks whether a result (value or exception) is ready. Implementations should implement this in a way that wait for the result, but returns as fast as possible.

Returns:
true if the result is ready, false otherwise
See Also:
await()

getException

Throwable getException()
Checks whether the result is ready but the implementation threw an exception. Only in this case the method returns this exception. In all other cases, the method must return null immediately.

Returns:
the exception, if there was one. Null otherwise.

addNotifier

void addNotifier(AsyncResult.Notifier<T> notifier)
Adds the given Notifier to the AsyncResult. It will be invoked (possibly from another thread) as soon as the result is ready. If the result is ready at the time of the invocation, the AsyncResult may invoke the notifier while the addNotifier() is running (probably in the same thread). After the notification the notifier will be removed automatically. It is not needed to remove it then anymore. If a notifier will be added more than once it will be called for each time it has been added.

Parameters:
notifier - the notifier to be called
Throws:
IllegalArgumentException - if the notifier was null
See Also:
removeNotifier(org.actorsguildframework.AsyncResult.Notifier)

removeNotifier

void removeNotifier(AsyncResult.Notifier<T> notifier)
Removes the given Notifier from the AsyncResult. This means that the notifier will probably not be called when the result is ready. This is not guaranteed though, it may be called anyway. It is not necessary to remove the notifier after receiving a notification. If you try to remove a notifier that is not registered, the invocation will be ignored.

Parameters:
notifier - the notifier to be called
Throws:
IllegalArgumentException - if the notifier was null
See Also:
addNotifier(org.actorsguildframework.AsyncResult.Notifier)