Class DisruptorCommandBus.Builder
java.lang.Object
org.axonframework.disruptor.commandhandling.DisruptorCommandBus.Builder
- Enclosing class:
DisruptorCommandBus
Builder class to instantiate a
DisruptorCommandBus.
The following configurable fields have defaults:
- The
rescheduleCommandsOnCorruptStatedefaults totrue. - The
coolingDownPerioddefaults to1000. - The
CommandTargetResolverdefaults to anAnnotationCommandTargetResolver. - The
publisherThreadCountdefaults to1. - The
MessageMonitordefaults toNoOpMessageMonitor.INSTANCE. - The
RollbackConfigurationdefaults toRollbackConfigurationType.UNCHECKED_EXCEPTIONS. - The
bufferSizedefaults to4096. - The
ProducerTypedefaults toProducerType.MULTI. - The
WaitStrategydefaults to aBlockingWaitStrategy. - The
invokerThreadCountdefaults to1. - The
Cachedefaults toNoCache.INSTANCE. - The
DuplicateCommandHandlerResolverdefaults toDuplicateCommandHandlerResolution.logAndOverride().
Executor.
The CommandTargetResolver, MessageMonitor, RollbackConfiguration, ProducerType,
WaitStrategy and Cache are a hard requirements. Thus setting them to null will
result in an AxonConfigurationException.
Additionally, the coolingDownPeriod, publisherThreadCount, bufferSize and
invokerThreadCount have a positive number constraint, thus will also result in an
AxonConfigurationException if set otherwise.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbufferSize(int bufferSize) Sets the buffer size to use.build()Initializes aDisruptorCommandBusas specified through this Builder.Sets theCachein which loaded aggregates will be stored.commandTargetResolver(CommandTargetResolver commandTargetResolver) Sets theCommandTargetResolverthat must be used to indicate which Aggregate instance will be invoked by an incoming command.coolingDownPeriod(long coolingDownPeriod) Sets the cooling down period in milliseconds.defaultCommandCallback(CommandCallback<Object, Object> defaultCommandCallback) Sets the callback to use when commands are dispatched in a "fire and forget" method, such asDisruptorCommandBus.dispatch(CommandMessage).dispatchInterceptors(List<MessageDispatchInterceptor<CommandMessage<?>>> dispatchInterceptors) ConfiguresMessageDispatchInterceptorof generic typeCommandMessageto use with theDisruptorCommandBuswhen commands are dispatched.duplicateCommandHandlerResolver(DuplicateCommandHandlerResolver duplicateCommandHandlerResolver) Sets theDuplicateCommandHandlerResolverused to resolves the road to take when a duplicate command handler is subscribed.Sets theExecutorthat provides the processing resources (Threads) for the components of theDisruptorCommandBus.invokerInterceptors(List<MessageHandlerInterceptor<? super CommandMessage<?>>> invokerInterceptors) Set theMessageHandlerInterceptorof generic typeCommandMessageto use with theDisruptorCommandBusduring in the invocation thread.invokerThreadCount(int invokerThreadCount) Sets the number of Threads that should be used to invoke the Command Handlers.messageMonitor(MessageMonitor<? super CommandMessage<?>> messageMonitor) Sets theMessageMonitorof generic typeCommandMessageused the to monitor the command bus.producerType(com.lmax.disruptor.dsl.ProducerType producerType) Sets theProducerTypeto use by theDisruptor.publisherInterceptors(List<MessageHandlerInterceptor<CommandMessage<?>>> publisherInterceptors) Configures theMessageHandlerInterceptorof generic typeCommandMessageto use with theDisruptorCommandBusduring the publication of changes.publisherThreadCount(int publisherThreadCount) Sets the number of Threads that should be used to store and publish the generated Events.rescheduleCommandsOnCorruptState(boolean rescheduleCommandsOnCorruptState) Set the indicator specifying whether commands that failed because they were executed against potentially corrupted aggregate state should be automatically rescheduled.rollbackConfiguration(RollbackConfiguration rollbackConfiguration) Sets theRollbackConfigurationwhich allows you to specify when aUnitOfWorkshould be rolled back.transactionManager(TransactionManager transactionManager) Sets theTransactionManagerto use to manage a transaction around the storage and publication of events.protected voidvalidate()Validate whether the fields contained in this Builder as set accordingly.waitStrategy(com.lmax.disruptor.WaitStrategy waitStrategy) Sets theWaitStrategywhich is used to make dependent threads wait for tasks to be completed.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
invokerInterceptors
public DisruptorCommandBus.Builder invokerInterceptors(List<MessageHandlerInterceptor<? super CommandMessage<?>>> invokerInterceptors) Set theMessageHandlerInterceptorof generic typeCommandMessageto use with theDisruptorCommandBusduring in the invocation thread. The interceptors are invoked by the thread that also executes the command handler. Note that this is *not* the thread that stores and publishes the generated events. SeepublisherInterceptors(java.util.List).- Parameters:
invokerInterceptors- theMessageHandlerInterceptors to invoke when handling an incoming command- Returns:
- the current Builder instance, for fluent interfacing
-
publisherInterceptors
public DisruptorCommandBus.Builder publisherInterceptors(List<MessageHandlerInterceptor<CommandMessage<?>>> publisherInterceptors) Configures theMessageHandlerInterceptorof generic typeCommandMessageto use with theDisruptorCommandBusduring the publication of changes. The interceptors are invoked by the thread that also stores and publishes the events.- Parameters:
publisherInterceptors- theMessageHandlerInterceptors to invoke when handling an incoming command- Returns:
- the current Builder instance, for fluent interfacing
-
dispatchInterceptors
public DisruptorCommandBus.Builder dispatchInterceptors(List<MessageDispatchInterceptor<CommandMessage<?>>> dispatchInterceptors) ConfiguresMessageDispatchInterceptorof generic typeCommandMessageto use with theDisruptorCommandBuswhen commands are dispatched. The interceptors are invoked by the thread that provides the commands to the command bus.- Parameters:
dispatchInterceptors- theMessageDispatchInterceptors dispatch interceptors to invoke when dispatching a command- Returns:
- the current Builder instance, for fluent interfacing
-
executor
Sets theExecutorthat provides the processing resources (Threads) for the components of theDisruptorCommandBus. The provided executor must be capable of providing the required number of threads. Three threads are required immediately at startup and will not be returned until the CommandBus is stopped. Additional threads are used to invoke callbacks and start a recovery process in case aggregate state has been corrupted. Failure to do this results in the disruptor hanging at startup, waiting for resources to become available. Defaults tonull, causing the DisruptorCommandBus to create the necessary threads itself. In that case, threads are created in the DisruptorCommandBus ThreadGroup.- Parameters:
executor- theExecutorthat provides the processing resources- Returns:
- the current Builder instance, for fluent interfacing
-
rescheduleCommandsOnCorruptState
public DisruptorCommandBus.Builder rescheduleCommandsOnCorruptState(boolean rescheduleCommandsOnCorruptState) Set the indicator specifying whether commands that failed because they were executed against potentially corrupted aggregate state should be automatically rescheduled. Commands that caused the aggregate state to become corrupted are never automatically rescheduled, to prevent poison message syndrome. Defaults totrue.- Parameters:
rescheduleCommandsOnCorruptState- abooleanspecifying whether or not to automatically reschedule commands that failed due to potentially corrupted aggregate state.- Returns:
- the current Builder instance, for fluent interfacing
-
coolingDownPeriod
Sets the cooling down period in milliseconds. This is the time in which new commands are no longer accepted, but theDisruptorCommandBusmay reschedule commands that may have been executed against a corrupted Aggregate. If no commands have been rescheduled during this period, the disruptor shuts down completely. Otherwise, it wait until no commands were scheduled for processing. Defaults to 1000 ms (1 second).- Parameters:
coolingDownPeriod- alongspecifying the cooling down period for the shutdown of theDisruptorCommandBus, in milliseconds.- Returns:
- the current Builder instance, for fluent interfacing
-
commandTargetResolver
public DisruptorCommandBus.Builder commandTargetResolver(CommandTargetResolver commandTargetResolver) Sets theCommandTargetResolverthat must be used to indicate which Aggregate instance will be invoked by an incoming command. TheDisruptorCommandBusonly uses this value ifinvokerThreadCount(int)}, orpublisherThreadCount(int)is greater than1. Defaults to anAnnotationCommandTargetResolverinstance.- Parameters:
commandTargetResolver- TheCommandTargetResolverto use to indicate which Aggregate instance is target of an incoming Command- Returns:
- the current Builder instance, for fluent interfacing
-
publisherThreadCount
Sets the number of Threads that should be used to store and publish the generated Events. Defaults to1. A good value for this setting mainly depends on the number of cores your machine has, as well as the amount of I/O that the process requires. If no I/O is involved, a good starting value is[processors / 2].- Parameters:
publisherThreadCount- the number of Threads to use for publishing as anint- Returns:
- the current Builder instance, for fluent interfacing
-
messageMonitor
public DisruptorCommandBus.Builder messageMonitor(MessageMonitor<? super CommandMessage<?>> messageMonitor) Sets theMessageMonitorof generic typeCommandMessageused the to monitor the command bus. Defaults to aNoOpMessageMonitor.- Parameters:
messageMonitor- aMessageMonitorused the message monitor to monitor the command bus- Returns:
- the current Builder instance, for fluent interfacing
-
transactionManager
Sets theTransactionManagerto use to manage a transaction around the storage and publication of events. The default (null) is to not have publication and storage of events wrapped in a transaction.- Parameters:
transactionManager- theTransactionManagerto use to manage a transaction around the storage and publication of events- Returns:
- the current Builder instance, for fluent interfacing
-
rollbackConfiguration
public DisruptorCommandBus.Builder rollbackConfiguration(RollbackConfiguration rollbackConfiguration) Sets theRollbackConfigurationwhich allows you to specify when aUnitOfWorkshould be rolled back. Defaults to aRollbackConfigurationType.UNCHECKED_EXCEPTIONS, which triggers a rollback on all unchecked exceptions.- Parameters:
rollbackConfiguration- aRollbackConfigurationspecifying when aUnitOfWorkshould be rolled back- Returns:
- the current Builder instance, for fluent interfacing
-
bufferSize
Sets the buffer size to use. This field must be positive and a power of 2.The default is
4096.- Parameters:
bufferSize- anintspecifying the buffer size to use- Returns:
- the current Builder instance, for fluent interfacing
-
producerType
Sets theProducerTypeto use by theDisruptor.Defaults to a
ProducerType.MULTIsolution.- Parameters:
producerType- theProducerTypeto use by theDisruptor- Returns:
- the current Builder instance, for fluent interfacing
-
waitStrategy
Sets theWaitStrategywhich is used to make dependent threads wait for tasks to be completed. The choice of strategy mainly depends on the number of processors available and the number of tasks other than theDisruptorCommandBusbeing processed. TheBusySpinWaitStrategyprovides the best throughput at the lowest latency, but also put a big claim on available CPU resources. TheSleepingWaitStrategyyields lower performance, but leaves resources available for other processes to use. Defaults to theBlockingWaitStrategy.- Parameters:
waitStrategy- The WaitStrategy to use- Returns:
- the current Builder instance, for fluent interfacing
- See Also:
-
invokerThreadCount
Sets the number of Threads that should be used to invoke the Command Handlers. Defaults to1. A good value for this setting mainly depends on the number of cores your machine has, as well as the amount of I/O that the process requires. A good range, if no I/O is involved is1 .. ([processor count] / 2).- Parameters:
invokerThreadCount- anintspecifying the number of Threads to use for Command Handler invocation- Returns:
- the current Builder instance, for fluent interfacing
-
cache
Sets theCachein which loaded aggregates will be stored. Aggregates that are not active in the CommandBus' buffer will be loaded from this cache. If they are not in the cache, a new instance will be constructed using Events from theEventStore. By default, no cache is used.- Parameters:
cache- the cache to store loaded aggregates in- Returns:
- the current Builder instance, for fluent interfacing
-
duplicateCommandHandlerResolver
public DisruptorCommandBus.Builder duplicateCommandHandlerResolver(DuplicateCommandHandlerResolver duplicateCommandHandlerResolver) Sets theDuplicateCommandHandlerResolverused to resolves the road to take when a duplicate command handler is subscribed. Defaults toLog and Override.- Parameters:
duplicateCommandHandlerResolver- aDuplicateCommandHandlerResolverused to resolves the road to take when a duplicate command handler is subscribed- Returns:
- the current Builder instance, for fluent interfacing
-
defaultCommandCallback
public DisruptorCommandBus.Builder defaultCommandCallback(CommandCallback<Object, Object> defaultCommandCallback) Sets the callback to use when commands are dispatched in a "fire and forget" method, such asDisruptorCommandBus.dispatch(CommandMessage). Defaults to aDisruptorCommandBus.FailureLoggingCommandCallback, which logs failed commands to a logger. Passingnullwill result in aNoOpCallbackbeing used.- Parameters:
defaultCommandCallback- the callback to invoke when no explicit callback is provided for a command- Returns:
- the current Builder instance, for fluent interfacing
-
build
Initializes aDisruptorCommandBusas specified through this Builder.- Returns:
- a
DisruptorCommandBusas specified through this Builder
-
validate
protected void validate()Validate whether the fields contained in this Builder as set accordingly.- Throws:
AxonConfigurationException- if one field is asserted to be incorrect according to the Builder's specifications
-