org.axonframework.commandhandling.callbacks
Class FutureCallback<R>

java.lang.Object
  extended by org.axonframework.commandhandling.callbacks.FutureCallback<R>
Type Parameters:
R - the type of result of the command handling
All Implemented Interfaces:
Future<R>, CommandCallback<R>

public class FutureCallback<R>
extends Object
implements CommandCallback<R>, Future<R>

Command Handler Callback that allows the dispatching thread to wait for the result of the callback, using the Future mechanism. This callback allows the caller to synchronize calls when an asynchronous command bus is being used.

Since:
0.6
Author:
Allard Buijze

Constructor Summary
FutureCallback()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          Always returns false, since command execution cannot be cancelled.
 R get()
          Waits if necessary for the command handling to complete, and then returns its result.
 R get(long timeout, TimeUnit unit)
          Waits if necessary for at most the given time for the command handling to complete, and then retrieves its result, if available.
 boolean isCancelled()
          Always returns false, since command execution cannot be cancelled.
 boolean isDone()
          Indicates whether command handler execution has finished.
 void onFailure(Throwable cause)
          Invoked when command handling execution resulted in an error.
 void onSuccess(R executionResult)
          Invoked when command handling execution was successful.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FutureCallback

public FutureCallback()
Method Detail

onSuccess

public void onSuccess(R executionResult)
Description copied from interface: CommandCallback
Invoked when command handling execution was successful.

Specified by:
onSuccess in interface CommandCallback<R>
Parameters:
executionResult - The result of the command handling execution, if any.

onFailure

public void onFailure(Throwable cause)
Description copied from interface: CommandCallback
Invoked when command handling execution resulted in an error.

Specified by:
onFailure in interface CommandCallback<R>
Parameters:
cause - The exception raised during command handling

get

public R get()
      throws InterruptedException,
             ExecutionException
Waits if necessary for the command handling to complete, and then returns its result.

Specified by:
get in interface Future<R>
Returns:
the result of the command handler execution.
Throws:
InterruptedException - if the current thread is interrupted while waiting
ExecutionException - if the command handler threw an exception

get

public R get(long timeout,
             TimeUnit unit)
      throws TimeoutException,
             InterruptedException,
             ExecutionException
Waits if necessary for at most the given time for the command handling to complete, and then retrieves its result, if available.

Specified by:
get in interface Future<R>
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
the result of the command handler execution.
Throws:
InterruptedException - if the current thread is interrupted while waiting
TimeoutException - if the wait timed out
ExecutionException - if the command handler threw an exception

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Always returns false, since command execution cannot be cancelled.

Specified by:
cancel in interface Future<R>
Parameters:
mayInterruptIfRunning - true if the thread executing the command should be interrupted; otherwise, in-progress tasks are allowed to complete
Returns:
false

isCancelled

public boolean isCancelled()
Always returns false, since command execution cannot be cancelled.

Specified by:
isCancelled in interface Future<R>
Returns:
false

isDone

public boolean isDone()
Indicates whether command handler execution has finished.

Specified by:
isDone in interface Future<R>
Returns:
true if command handler execution has finished, otherwise false.


Copyright © 2011. All Rights Reserved.