Class PooledStreamingEventProcessor.Builder
- Enclosing class:
PooledStreamingEventProcessor
PooledStreamingEventProcessor.
Upon initialization of this builder, the following fields are defaulted:
- The
RollbackConfigurationTypedefaults to aRollbackConfigurationType.ANY_THROWABLE. - The
ErrorHandleris defaulted to aPropagatingErrorHandler. - The
MessageMonitordefaults to aNoOpMessageMonitor. - The
initialSegmentCountdefaults to16. - The
initialTokenfunction defaults to aReplayTokenthat starts streaming from thetailwith the replay flag enabled until theheadat the moment of initialization is reached. - The
tokenClaimIntervaldefaults to5000milliseconds. - The
MaxSegmentProvider(used byPooledStreamingEventProcessor.maxCapacity()) defaults toMaxSegmentProvider.maxShort(). - The
claimExtensionThresholddefaults to5000milliseconds. - The
batchSizedefaults to1. - The
Clockdefaults toGenericEventMessage.clock. - The
EventProcessorSpanFactorydefaults to aDefaultEventProcessorSpanFactorybacked by aNoOpSpanFactory. - The
coordinatorExtendsClaimsdefaults to afalse.
- The name of this
EventProcessor. - An
EventHandlerInvokerwhich will be given the events handled by this processor - A
StreamableMessageSourceused to retrieve events. - A
TokenStoreto store the progress of this processor in. - A
ScheduledExecutorServiceto coordinate events and segment operations. - A
ScheduledExecutorServiceto process work packages.
-
Field Summary
Fields inherited from class org.axonframework.eventhandling.AbstractEventProcessor.Builder
name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbatchSize(int batchSize) Specifies the number of events to be processed inside a single transaction.build()Initializes aPooledStreamingEventProcessoras specified through this Builder.claimExtensionThreshold(long claimExtensionThreshold) Specifies a time in milliseconds the work packages of this processor should extend the claim on aTrackingToken.Defines theClockused for time dependent operation by thisEventProcessor.coordinatorExecutor(ScheduledExecutorService coordinatorExecutor) Specifies theScheduledExecutorServiceused by the coordinator of thisPooledStreamingEventProcessor.coordinatorExecutor(Function<String, ScheduledExecutorService> coordinatorExecutorBuilder) Specifies a builder to construct aScheduledExecutorServiceused by the coordinator of thisPooledStreamingEventProcessor.Enables theCoordinatortoextend the claimsof itsWorkPackages.errorHandler(ErrorHandler errorHandler) Sets theErrorHandlerinvoked when anUnitOfWorkis rolled back during processing.eventHandlerInvoker(EventHandlerInvoker eventHandlerInvoker) Sets theEventHandlerInvokerwhich will handle all the individualEventMessages.initialSegmentCount(int initialSegmentCount) Sets the initial segment count used to create segments on start up.initialToken(Function<StreamableMessageSource<TrackedEventMessage<?>>, TrackingToken> initialToken) Specifies theFunctionused to generate the initialTrackingTokens.maxClaimedSegments(int maxClaimedSegments) Sets the maximum number of segments this instance may claim.maxSegmentProvider(MaxSegmentProvider maxSegmentProvider) Defines the maximum number of segment thisStreamingEventProcessormay claim per instance.messageMonitor(MessageMonitor<? super EventMessage<?>> messageMonitor) Sets theMessageMonitorto monitorEventMessages before and after they're processed.messageSource(StreamableMessageSource<TrackedEventMessage<?>> messageSource) name()Returns the name of thisPooledStreamingEventProcessor.Sets thenameof thisEventProcessorimplementation.rollbackConfiguration(RollbackConfiguration rollbackConfiguration) Sets theRollbackConfigurationspecifying the rollback behavior of theUnitOfWorkwhile processing a batch of events.spanFactory(EventProcessorSpanFactory spanFactory) Sets theEventProcessorSpanFactoryimplementation to use for providing tracing capabilities.spanFactory(SpanFactory spanFactory) Deprecated.tokenClaimInterval(long tokenClaimInterval) Specifies the time in milliseconds the processor's coordinator should wait after a failed attempt to claim any segments for processing.tokenStore(TokenStore tokenStore) Sets theTokenStoreused to store and fetch event tokens that enable thisEventProcessorto track its progress.transactionManager(TransactionManager transactionManager) Sets theTransactionManagerused when processingEventMessages.protected voidvalidate()Validates whether the fields contained in this Builder are set accordingly.workerExecutor(ScheduledExecutorService workerExecutor) Specifies theScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor.workerExecutor(Function<String, ScheduledExecutorService> workerExecutorBuilder) Specifies a builder to construct aScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor.workerExecutorService(ScheduledExecutorService workerExecutor) Deprecated.
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
name
Description copied from class:AbstractEventProcessor.BuilderSets thenameof thisEventProcessorimplementation.- Overrides:
namein classAbstractEventProcessor.Builder- Parameters:
name- aStringdefining thisEventProcessorimplementation- Returns:
- the current Builder instance, for fluent interfacing
-
eventHandlerInvoker
public PooledStreamingEventProcessor.Builder eventHandlerInvoker(@Nonnull EventHandlerInvoker eventHandlerInvoker) Description copied from class:AbstractEventProcessor.BuilderSets theEventHandlerInvokerwhich will handle all the individualEventMessages.- Overrides:
eventHandlerInvokerin classAbstractEventProcessor.Builder- Parameters:
eventHandlerInvoker- theEventHandlerInvokerwhich will handle all the individualEventMessages- Returns:
- the current Builder instance, for fluent interfacing
-
rollbackConfiguration
public PooledStreamingEventProcessor.Builder rollbackConfiguration(@Nonnull RollbackConfiguration rollbackConfiguration) Description copied from class:AbstractEventProcessor.BuilderSets theRollbackConfigurationspecifying the rollback behavior of theUnitOfWorkwhile processing a batch of events.- Overrides:
rollbackConfigurationin classAbstractEventProcessor.Builder- Parameters:
rollbackConfiguration- theRollbackConfigurationspecifying the rollback behavior of theUnitOfWorkwhile processing a batch of events.- Returns:
- the current Builder instance, for fluent interfacing
-
errorHandler
Description copied from class:AbstractEventProcessor.BuilderSets theErrorHandlerinvoked when anUnitOfWorkis rolled back during processing. Defaults to aPropagatingErrorHandler.- Overrides:
errorHandlerin classAbstractEventProcessor.Builder- Parameters:
errorHandler- theErrorHandlerinvoked when anUnitOfWorkis rolled back during processing- Returns:
- the current Builder instance, for fluent interfacing
-
messageMonitor
public PooledStreamingEventProcessor.Builder messageMonitor(@Nonnull MessageMonitor<? super EventMessage<?>> messageMonitor) Description copied from class:AbstractEventProcessor.BuilderSets theMessageMonitorto monitorEventMessages before and after they're processed. Defaults to aNoOpMessageMonitor.- Overrides:
messageMonitorin classAbstractEventProcessor.Builder- Parameters:
messageMonitor- aMessageMonitorto monitorEventMessages before and after they're processed- Returns:
- the current Builder instance, for fluent interfacing
-
spanFactory
public PooledStreamingEventProcessor.Builder spanFactory(@Nonnull EventProcessorSpanFactory spanFactory) Description copied from class:AbstractEventProcessor.BuilderSets theEventProcessorSpanFactoryimplementation to use for providing tracing capabilities. Defaults to aDefaultEventProcessorSpanFactorybacked by aNoOpSpanFactoryby default, which provides no tracing capabilities.- Overrides:
spanFactoryin classAbstractEventProcessor.Builder- Parameters:
spanFactory- TheSpanFactoryimplementation- Returns:
- The current Builder instance, for fluent interfacing.
-
spanFactory
@Deprecated public PooledStreamingEventProcessor.Builder spanFactory(@Nonnull SpanFactory spanFactory) Deprecated.Description copied from class:AbstractEventProcessor.BuilderSets theSpanFactoryimplementation to use for providing tracing capabilities. Defaults to aNoOpSpanFactoryby default, which provides no tracing capabilities.- Overrides:
spanFactoryin classAbstractEventProcessor.Builder- Parameters:
spanFactory- TheSpanFactoryimplementation- Returns:
- The current Builder instance, for fluent interfacing.
-
messageSource
public PooledStreamingEventProcessor.Builder messageSource(@Nonnull StreamableMessageSource<TrackedEventMessage<?>> messageSource) - Parameters:
messageSource- theStreamableMessageSource(e.g. theEventStore) which thisEventProcessorwill track- Returns:
- the current Builder instance, for fluent interfacing
-
tokenStore
Sets theTokenStoreused to store and fetch event tokens that enable thisEventProcessorto track its progress.- Parameters:
tokenStore- theTokenStoreused to store and fetch event tokens that enable thisEventProcessorto track its progress- Returns:
- the current Builder instance, for fluent interfacing
-
transactionManager
public PooledStreamingEventProcessor.Builder transactionManager(@Nonnull TransactionManager transactionManager) Sets theTransactionManagerused when processingEventMessages.- Parameters:
transactionManager- theTransactionManagerused when processingEventMessages- Returns:
- the current Builder instance, for fluent interfacing
-
coordinatorExecutor
public PooledStreamingEventProcessor.Builder coordinatorExecutor(@Nonnull ScheduledExecutorService coordinatorExecutor) Specifies theScheduledExecutorServiceused by the coordinator of thisPooledStreamingEventProcessor.- Parameters:
coordinatorExecutor- theScheduledExecutorServiceto be used by the the coordinator of thisPooledStreamingEventProcessor- Returns:
- the current Builder instance, for fluent interfacing
-
coordinatorExecutor
public PooledStreamingEventProcessor.Builder coordinatorExecutor(@Nonnull Function<String, ScheduledExecutorService> coordinatorExecutorBuilder) Specifies a builder to construct aScheduledExecutorServiceused by the coordinator of thisPooledStreamingEventProcessor.- Parameters:
coordinatorExecutorBuilder- a builder function to construct aScheduledExecutorService, providing thePooledStreamingEventProcessor- Returns:
- the current Builder instance, for fluent interfacing
-
workerExecutorService
@Deprecated public PooledStreamingEventProcessor.Builder workerExecutorService(@Nonnull ScheduledExecutorService workerExecutor) Deprecated.in favor ofworkerExecutor(ScheduledExecutorService)Specifies theScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor.- Parameters:
workerExecutor- theScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor- Returns:
- the current Builder instance, for fluent interfacing
-
workerExecutor
public PooledStreamingEventProcessor.Builder workerExecutor(@Nonnull ScheduledExecutorService workerExecutor) Specifies theScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor.- Parameters:
workerExecutor- theScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor- Returns:
- the current Builder instance, for fluent interfacing
-
workerExecutor
public PooledStreamingEventProcessor.Builder workerExecutor(@Nonnull Function<String, ScheduledExecutorService> workerExecutorBuilder) Specifies a builder to construct aScheduledExecutorServiceto be provided to theWorkPackages created by thisPooledStreamingEventProcessor.- Parameters:
workerExecutorBuilder- a builder function to construct aScheduledExecutorService, providing thePooledStreamingEventProcessor- Returns:
- the current Builder instance, for fluent interfacing
-
initialSegmentCount
Sets the initial segment count used to create segments on start up. Only used whenever there are not segments stored in the configuredTokenStoreupon start up of thisStreamingEventProcessor. The given value should at least be1. Defaults to16.- Parameters:
initialSegmentCount- anintspecifying the initial segment count used to create segments on start up- Returns:
- the current Builder instance, for fluent interfacing
-
initialToken
public PooledStreamingEventProcessor.Builder initialToken(@Nonnull Function<StreamableMessageSource<TrackedEventMessage<?>>, TrackingToken> initialToken) Specifies theFunctionused to generate the initialTrackingTokens. The function will be given the configuredStreamableMessageSource' so that its methods can be invoked for token creation.Defaults to an automatic replay since the start of the stream.
More specifically, it defaults to a
ReplayTokenthat starts streaming from thetailwith the replay flag enabled until theheadat the moment of initialization is reached.- Parameters:
initialToken- aFunctiongenerating the initialTrackingTokenbased on a givenStreamableMessageSource- Returns:
- the current Builder instance, for fluent interfacing
-
tokenClaimInterval
Specifies the time in milliseconds the processor's coordinator should wait after a failed attempt to claim any segments for processing. Generally, this means all segments are claimed. Defaults to5000milliseconds.- Parameters:
tokenClaimInterval- the time in milliseconds the processor's coordinator should wait after a failed attempt to claim any segments for processing- Returns:
- the current Builder instance, for fluent interfacing
-
maxClaimedSegments
Sets the maximum number of segments this instance may claim.- Parameters:
maxClaimedSegments- The maximum number of segments this instance may claim.- Returns:
- The current Builder instance, for fluent interfacing.
-
maxSegmentProvider
public PooledStreamingEventProcessor.Builder maxSegmentProvider(MaxSegmentProvider maxSegmentProvider) Defines the maximum number of segment thisStreamingEventProcessormay claim per instance. Defaults toMaxSegmentProvider.maxShort().- Parameters:
maxSegmentProvider- AMaxSegmentProviderproviding the maximum number segments thisStreamingEventProcessormay claim per instance.- Returns:
- The current Builder instance, for fluent interfacing.
-
claimExtensionThreshold
Specifies a time in milliseconds the work packages of this processor should extend the claim on aTrackingToken. The threshold will only be met in absence of regular event processing, since that updates theTrackingTokenautomatically. Defaults to5000milliseconds.- Parameters:
claimExtensionThreshold- a time in milliseconds the work packages of this processor should extend the claim on aTrackingToken.- Returns:
- the current Builder instance, for fluent interfacing
-
batchSize
Specifies the number of events to be processed inside a single transaction. Defaults to a batch size of1.Increasing this value with increase the processing speed dramatically, but requires certainty that the operations performed during event handling can be rolled back.
- Parameters:
batchSize- the number of events to be processed inside a single transaction- Returns:
- the current Builder instance, for fluent interfacing
-
clock
Defines theClockused for time dependent operation by thisEventProcessor. Used by theCoordinatorandWorkPackagethreads to decide when to perform certain tasks, like updatingTrackingTokenclaims or when to unmark aSegmentas "unclaimable". Defaults toGenericEventMessage.clock.- Parameters:
clock- theClockused for time dependent operation by thisEventProcessor- Returns:
- the current Builder instance, for fluent interfacing
-
enableCoordinatorClaimExtension
Enables theCoordinatortoextend the claimsof itsWorkPackages.Enabling "coordinator claim extension" is an optimization as it relieves this effort from the
WorkPackage. Toggling this feature may be particularly useful whenever the event handling task of theWorkPackageis lengthy. Either because of a hefty event handling component or because of a largebatchSize(int).An example of a lengthy processing tasks is whenever handling a batch of events exceeds half the
claimTimeoutof theTokenStore. TheclaimTimeoutdefaults to 10 seconds for all durableTokenStoreimplementations.In both scenarios, there's a window of opportunity that the
WorkPackageis not fast enough in extending the claim itself. Not being able to do so potentially causes token stealing by other instances of thisPooledStreamingEventProcessor, thus overburdening the overall event processing task.Note that enabling this feature will result in more frequent invocation of the
TokenStoreto update the tokens.- Returns:
- The current Builder instance, for fluent interfacing.
-
build
Initializes aPooledStreamingEventProcessoras specified through this Builder.- Returns:
- a
PooledStreamingEventProcessoras specified through this Builder
-
validate
Description copied from class:AbstractEventProcessor.BuilderValidates whether the fields contained in this Builder are set accordingly.- Overrides:
validatein classAbstractEventProcessor.Builder- Throws:
AxonConfigurationException- if one field is asserted to be incorrect according to the Builder's specifications
-
name
Returns the name of thisPooledStreamingEventProcessor.- Returns:
- the name of this
PooledStreamingEventProcessor
-
workerExecutor(ScheduledExecutorService)