Class AsynchronousCommandBus

  extended by org.axonframework.commandhandling.SimpleCommandBus
      extended by org.axonframework.commandhandling.AsynchronousCommandBus
All Implemented Interfaces:

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.

Allard Buijze

Constructor Summary
          Initialize the AsynchronousCommandBus, using a Cached Thread Pool.
AsynchronousCommandBus(Executor executor)
          Initialize the AsynchronousCommandBus using the given executor.
Method Summary
<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


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


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

executor - The executor that processes Command dispatching threads
Method Detail


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.

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


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.