org.axonframework.commandhandling
Class AsynchronousCommandBus

java.lang.Object
  extended by org.axonframework.commandhandling.SimpleCommandBus
      extended by org.axonframework.commandhandling.AsynchronousCommandBus
All Implemented Interfaces:
CommandBus

public class AsynchronousCommandBus
extends SimpleCommandBus

Specialization of the SimpleCommandBus that processed Commands asynchronously from the calling thread. By default, the AsynchronousCommandBus uses a Cached Thread Pool (see Executors.newCachedThreadPool()). It will reuse threads while possible, and shut them down after 60 seconds of inactivity.

Each Command is dispatched in a separate task, which is processed by the Executor.

Note that you should call shutdown() to stop any threads waiting for new tasks. Failure to do so may cause the JVM to hang for up to 60 seconds on JVM shutdown.

Since:
1.3.4
Author:
Allard Buijze

Constructor Summary
AsynchronousCommandBus()
          Initialize the AsynchronousCommandBus, using a Cached Thread Pool.
AsynchronousCommandBus(Executor executor)
          Initialize the AsynchronousCommandBus using the given executor.
 
Method Summary
protected
<R> void
doDispatch(CommandMessage<?> command, CommandCallback<R> callback)
          Performs the actual dispatching logic.
 void shutdown()
          Shuts down the Executor used to asynchronously dispatch incoming commands.
 
Methods inherited from class org.axonframework.commandhandling.SimpleCommandBus
dispatch, dispatch, intercept, setDispatchInterceptors, setHandlerInterceptors, setRollbackConfiguration, setSubscriptions, setTransactionManager, setUnitOfWorkFactory, subscribe, unsubscribe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsynchronousCommandBus

public AsynchronousCommandBus()
Initialize the AsynchronousCommandBus, using a Cached Thread Pool.


AsynchronousCommandBus

public AsynchronousCommandBus(Executor executor)
Initialize the AsynchronousCommandBus using the given executor.

Parameters:
executor - The executor that processes Command dispatching threads
Method Detail

doDispatch

protected <R> void doDispatch(CommandMessage<?> command,
                              CommandCallback<R> callback)
Description copied from class: SimpleCommandBus
Performs the actual dispatching logic. The dispatch interceptors must have been invoked at this point.

Overrides:
doDispatch in class SimpleCommandBus
Type Parameters:
R - The type of result expected from the command handler
Parameters:
command - The actual command to dispatch to the handler
callback - The callback to notify of the result

shutdown

public void shutdown()
Shuts down the Executor used to asynchronously dispatch incoming commands. If the Executor provided in the constructor does not implement ExecutorService, this method does nothing.



Copyright © 2010-2016. All Rights Reserved.