public static class DisruptorCommandBus.Builder extends Object
DisruptorCommandBus.
The following configurable fields have defaults:
rescheduleCommandsOnCorruptState defaults to true.coolingDownPeriod defaults to 1000.CommandTargetResolver defaults to an AnnotationCommandTargetResolver.publisherThreadCount defaults to 1.MessageMonitor defaults to NoOpMessageMonitor.INSTANCE.RollbackConfiguration defaults to RollbackConfigurationType.UNCHECKED_EXCEPTIONS.bufferSize defaults to 4096.ProducerType defaults to ProducerType.MULTI.WaitStrategy defaults to a BlockingWaitStrategy.invokerThreadCount defaults to 1.Cache defaults to NoCache.INSTANCE.DuplicateCommandHandlerResolver defaults to DuplicateCommandHandlerResolution.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 and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
DisruptorCommandBus.Builder |
bufferSize(int bufferSize)
Sets the buffer size to use.
|
DisruptorCommandBus |
build()
Initializes a
DisruptorCommandBus as specified through this Builder. |
DisruptorCommandBus.Builder |
cache(Cache cache)
Sets the
Cache in which loaded aggregates will be stored. |
DisruptorCommandBus.Builder |
commandTargetResolver(CommandTargetResolver commandTargetResolver)
Sets the
CommandTargetResolver that must be used to indicate which Aggregate instance will be invoked
by an incoming command. |
DisruptorCommandBus.Builder |
coolingDownPeriod(long coolingDownPeriod)
Sets the cooling down period in milliseconds.
|
DisruptorCommandBus.Builder |
defaultCommandCallback(CommandCallback<Object,Object> defaultCommandCallback)
Sets the callback to use when commands are dispatched in a "fire and forget" method, such as
DisruptorCommandBus.dispatch(CommandMessage). |
DisruptorCommandBus.Builder |
dispatchInterceptors(List<MessageDispatchInterceptor<CommandMessage<?>>> dispatchInterceptors)
Configures
MessageDispatchInterceptor of generic type CommandMessage to use with the DisruptorCommandBus when commands are dispatched. |
DisruptorCommandBus.Builder |
duplicateCommandHandlerResolver(DuplicateCommandHandlerResolver duplicateCommandHandlerResolver)
Sets the
DuplicateCommandHandlerResolver used to resolves the road to take when a duplicate command
handler is subscribed. |
DisruptorCommandBus.Builder |
executor(Executor executor)
Sets the
Executor that provides the processing resources (Threads) for the components of the DisruptorCommandBus. |
DisruptorCommandBus.Builder |
invokerInterceptors(List<MessageHandlerInterceptor<? super CommandMessage<?>>> invokerInterceptors)
Set the
MessageHandlerInterceptor of generic type CommandMessage to use with the DisruptorCommandBus during in the invocation thread. |
DisruptorCommandBus.Builder |
invokerThreadCount(int invokerThreadCount)
Sets the number of Threads that should be used to invoke the Command Handlers.
|
DisruptorCommandBus.Builder |
messageMonitor(MessageMonitor<? super CommandMessage<?>> messageMonitor)
Sets the
MessageMonitor of generic type CommandMessage used the to monitor the command bus. |
DisruptorCommandBus.Builder |
producerType(com.lmax.disruptor.dsl.ProducerType producerType)
Sets the
ProducerType to use by the Disruptor. |
DisruptorCommandBus.Builder |
publisherInterceptors(List<MessageHandlerInterceptor<CommandMessage<?>>> publisherInterceptors)
Configures the
MessageHandlerInterceptor of generic type CommandMessage to use with the
DisruptorCommandBus during the publication of changes. |
DisruptorCommandBus.Builder |
publisherThreadCount(int publisherThreadCount)
Sets the number of Threads that should be used to store and publish the generated Events.
|
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.
|
DisruptorCommandBus.Builder |
rollbackConfiguration(RollbackConfiguration rollbackConfiguration)
Sets the
RollbackConfiguration which allows you to specify when a UnitOfWork should be rolled
back. |
DisruptorCommandBus.Builder |
transactionManager(TransactionManager transactionManager)
Sets the
TransactionManager to use to manage a transaction around the storage and publication of
events. |
protected void |
validate()
Validate whether the fields contained in this Builder as set accordingly.
|
DisruptorCommandBus.Builder |
waitStrategy(com.lmax.disruptor.WaitStrategy waitStrategy)
Sets the
WaitStrategy which is used to make dependent threads wait for tasks to be completed. |
public DisruptorCommandBus.Builder invokerInterceptors(List<MessageHandlerInterceptor<? super CommandMessage<?>>> invokerInterceptors)
MessageHandlerInterceptor of generic type CommandMessage to use with the DisruptorCommandBus during 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. See publisherInterceptors(java.util.List).invokerInterceptors - the MessageHandlerInterceptors to invoke when handling an incoming
commandpublic DisruptorCommandBus.Builder publisherInterceptors(List<MessageHandlerInterceptor<CommandMessage<?>>> publisherInterceptors)
MessageHandlerInterceptor of generic type CommandMessage to use with the
DisruptorCommandBus during the publication of changes. The interceptors are invoked by the thread
that also stores and publishes the events.publisherInterceptors - the MessageHandlerInterceptors to invoke when handling an incoming
commandpublic DisruptorCommandBus.Builder dispatchInterceptors(List<MessageDispatchInterceptor<CommandMessage<?>>> dispatchInterceptors)
MessageDispatchInterceptor of generic type CommandMessage to use with the DisruptorCommandBus when commands are dispatched. The interceptors are invoked by the thread that provides
the commands to the command bus.dispatchInterceptors - the MessageDispatchInterceptors dispatch interceptors to invoke when
dispatching a commandpublic DisruptorCommandBus.Builder executor(Executor executor)
Executor that provides the processing resources (Threads) for the components of the DisruptorCommandBus. 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 to null, causing the DisruptorCommandBus to create the necessary threads itself. In that
case, threads are created in the DisruptorCommandBus ThreadGroup.executor - the Executor that provides the processing resourcespublic DisruptorCommandBus.Builder rescheduleCommandsOnCorruptState(boolean rescheduleCommandsOnCorruptState)
true.rescheduleCommandsOnCorruptState - a boolean specifying whether or not to automatically
reschedule commands that failed due to potentially corrupted
aggregate state.public DisruptorCommandBus.Builder coolingDownPeriod(long coolingDownPeriod)
DisruptorCommandBus may 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).coolingDownPeriod - a long specifying the cooling down period for the shutdown of the DisruptorCommandBus, in milliseconds.public DisruptorCommandBus.Builder commandTargetResolver(CommandTargetResolver commandTargetResolver)
CommandTargetResolver that must be used to indicate which Aggregate instance will be invoked
by an incoming command. The DisruptorCommandBus only uses this value if invokerThreadCount(int)}, or publisherThreadCount(int) is greater than 1.
Defaults to an AnnotationCommandTargetResolver instance.commandTargetResolver - The CommandTargetResolver to use to indicate which Aggregate instance is
target of an incoming Commandpublic DisruptorCommandBus.Builder publisherThreadCount(int publisherThreadCount)
1.
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].publisherThreadCount - the number of Threads to use for publishing as an intpublic DisruptorCommandBus.Builder messageMonitor(MessageMonitor<? super CommandMessage<?>> messageMonitor)
MessageMonitor of generic type CommandMessage used the to monitor the command bus.
Defaults to a NoOpMessageMonitor.messageMonitor - a MessageMonitor used the message monitor to monitor the command buspublic DisruptorCommandBus.Builder transactionManager(TransactionManager transactionManager)
TransactionManager to 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.transactionManager - the TransactionManager to use to manage a transaction around the storage
and publication of eventspublic DisruptorCommandBus.Builder rollbackConfiguration(RollbackConfiguration rollbackConfiguration)
RollbackConfiguration which allows you to specify when a UnitOfWork should be rolled
back. Defaults to a RollbackConfigurationType.UNCHECKED_EXCEPTIONS, which triggers a rollback on all
unchecked exceptions.rollbackConfiguration - a RollbackConfiguration specifying when a UnitOfWork should be
rolled backpublic DisruptorCommandBus.Builder bufferSize(int bufferSize)
The default is 4096.
bufferSize - an int specifying the buffer size to usepublic DisruptorCommandBus.Builder producerType(com.lmax.disruptor.dsl.ProducerType producerType)
ProducerType to use by the Disruptor.
Defaults to a ProducerType.MULTI solution.
producerType - the ProducerType to use by the Disruptorpublic DisruptorCommandBus.Builder waitStrategy(com.lmax.disruptor.WaitStrategy waitStrategy)
WaitStrategy which 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
the DisruptorCommandBus being processed.
The BusySpinWaitStrategy provides the best throughput at the lowest latency, but
also put a big claim on available CPU resources. The SleepingWaitStrategy yields
lower performance, but leaves resources available for other processes to use.
Defaults to the BlockingWaitStrategy.waitStrategy - The WaitStrategy to useSleepingWaitStrategy,
BlockingWaitStrategy,
BusySpinWaitStrategy,
YieldingWaitStrategypublic DisruptorCommandBus.Builder invokerThreadCount(int invokerThreadCount)
1.
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 is 1 .. ([processor count] /
2).invokerThreadCount - an int specifying the number of Threads to use for Command Handler
invocationpublic DisruptorCommandBus.Builder cache(Cache cache)
Cache in 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 the EventStore.
By default, no cache is used.cache - the cache to store loaded aggregates inpublic DisruptorCommandBus.Builder duplicateCommandHandlerResolver(DuplicateCommandHandlerResolver duplicateCommandHandlerResolver)
DuplicateCommandHandlerResolver used to resolves the road to take when a duplicate command
handler is subscribed. Defaults to Log and
Override.duplicateCommandHandlerResolver - a DuplicateCommandHandlerResolver used to resolves the road to
take when a duplicate command handler is subscribedpublic DisruptorCommandBus.Builder defaultCommandCallback(CommandCallback<Object,Object> defaultCommandCallback)
DisruptorCommandBus.dispatch(CommandMessage). Defaults to a FailureLoggingCommandCallback, which logs failed commands
to a logger. Passing null will result in a NoOpCallback being used.defaultCommandCallback - the callback to invoke when no explicit callback is provided for a commandpublic DisruptorCommandBus build()
DisruptorCommandBus as specified through this Builder.DisruptorCommandBus as specified through this Builderprotected void validate()
AxonConfigurationException - if one field is asserted to be incorrect according to the Builder's
specificationsCopyright © 2010–2023. All rights reserved.