org.axonframework.commandhandling.distributed
Class DistributedCommandBus

java.lang.Object
  extended by org.axonframework.commandhandling.distributed.DistributedCommandBus
All Implemented Interfaces:
org.axonframework.commandhandling.CommandBus

public class DistributedCommandBus
extends Object
implements org.axonframework.commandhandling.CommandBus

Implementation of a CommandBus that is aware of multiple instances of a CommandBus working together to spread load. Each "physical" CommandBus instance is considered a "segment" of a conceptual distributed CommandBus.

The DistributedCommandBus relies on a CommandBusConnector to dispatch commands and replies to different segments of the CommandBus. Depending on the implementation used, each segment may run in a different JVM.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
DistributedCommandBus(CommandBusConnector connector)
          Initializes the command bus with the given connector and an AnnotationRoutingStrategy.
DistributedCommandBus(CommandBusConnector connector, RoutingStrategy routingStrategy)
          Initializes the command bus with the given connector and routingStrategy.
 
Method Summary
 void dispatch(org.axonframework.commandhandling.CommandMessage<?> command)
          
<R> void
dispatch(org.axonframework.commandhandling.CommandMessage<?> command, org.axonframework.commandhandling.CommandCallback<R> callback)
          
 void setCommandDispatchInterceptors(Collection<org.axonframework.commandhandling.CommandDispatchInterceptor> newDispatchInterceptors)
          Sets the interceptors that intercept commands just prior to dispatching them.
<C> void
subscribe(String commandName, org.axonframework.commandhandling.CommandHandler<? super C> handler)
          

In the DistributedCommandBus, the handler is subscribed to the local segment only.

<C> boolean
unsubscribe(String commandName, org.axonframework.commandhandling.CommandHandler<? super C> handler)
          

In the DistributedCommandBus, the handler is unsubscribed from the local segment only.

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DistributedCommandBus

public DistributedCommandBus(CommandBusConnector connector)
Initializes the command bus with the given connector and an AnnotationRoutingStrategy.

Parameters:
connector - the connector that connects the different command bus segments

DistributedCommandBus

public DistributedCommandBus(CommandBusConnector connector,
                             RoutingStrategy routingStrategy)
Initializes the command bus with the given connector and routingStrategy. The routingStrategy is used to calculate a routing key for each dispatched command. For a given configuration of segments, commands resulting in the same routing key are routed to the same segment.

Parameters:
connector - the connector that connects the different command bus segments
routingStrategy - the RoutingStrategy to define routing keys for each command
Method Detail

dispatch

public void dispatch(org.axonframework.commandhandling.CommandMessage<?> command)

Specified by:
dispatch in interface org.axonframework.commandhandling.CommandBus
Throws:
CommandDispatchException - when an error occurs while dispatching the command to a segment

dispatch

public <R> void dispatch(org.axonframework.commandhandling.CommandMessage<?> command,
                         org.axonframework.commandhandling.CommandCallback<R> callback)

Specified by:
dispatch in interface org.axonframework.commandhandling.CommandBus
Throws:
CommandDispatchException - when an error occurs while dispatching the command to a segment

subscribe

public <C> void subscribe(String commandName,
                          org.axonframework.commandhandling.CommandHandler<? super C> handler)

In the DistributedCommandBus, the handler is subscribed to the local segment only.

Specified by:
subscribe in interface org.axonframework.commandhandling.CommandBus

unsubscribe

public <C> boolean unsubscribe(String commandName,
                               org.axonframework.commandhandling.CommandHandler<? super C> handler)

In the DistributedCommandBus, the handler is unsubscribed from the local segment only.

Specified by:
unsubscribe in interface org.axonframework.commandhandling.CommandBus

setCommandDispatchInterceptors

public void setCommandDispatchInterceptors(Collection<org.axonframework.commandhandling.CommandDispatchInterceptor> newDispatchInterceptors)
Sets the interceptors that intercept commands just prior to dispatching them.

This operation is only guaranteed to be thread safe if no commands are dispatched during the invocation of this method. Doing so may result in commands not being intercepted at all while replacing the interceptors. Once this operation returns, all commands are guaranteed to be processed by the given interceptors.

Parameters:
newDispatchInterceptors - The interceptors to intercepts commands with


Copyright © 2010-2016. All Rights Reserved.