Class TrackingEventProcessorConfiguration
TrackingEventProcessor. The TrackingEventProcessorConfiguration provides
access to the options to tweak various settings. Instances are not thread-safe and should not be altered after they
have been used to initialize a TrackingEventProcessor.- Since:
- 3.1
- Author:
- Christophe Bouhier, Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptionandAutoStart(boolean autoStart) Whether to automatically start the processor when event processing is initialized.andBatchSize(int batchSize) Set the maximum number of events that may be processed in a single transaction.andEventAvailabilityTimeout(long interval, TimeUnit unit) Set the duration where a Tracking Processor will wait for the availability of Events, in each cycle, before extending the claim on the tokens it owns.andEventTrackerStatusChangeListener(EventTrackerStatusChangeListener eventTrackerStatusChangeListener) Sets theEventTrackerStatusChangeListenerwhich will be called onEventTrackerStatuschanges.andInitialSegmentsCount(int segmentsSize) Sets the initial number of segments for asynchronous processing.andInitialTrackingToken(Function<StreamableMessageSource<TrackedEventMessage<?>>, TrackingToken> initialTrackingTokenBuilder) Sets the builder to use to create the initialTrackingToken.andThreadFactory(Function<String, ThreadFactory> threadFactory) Sets theThreadFactoryto use to create theThreadsto process events on.andTokenClaimInterval(long tokenClaimInterval, TimeUnit timeUnit) Sets the time to wait after a failed attempt to claim any token, before making another attempt.andWorkerTerminationTimeout(long workerTerminationTimeoutInMilliseconds) Deprecated.andWorkerTerminationTimeout(long workerTerminationTimeout, TimeUnit timeUnit) Sets the shutdown timeout to terminate active workers.forParallelProcessing(int threadCount) Initialize a configuration instance with the giventhreadCount.Initialize a configuration with single threaded processing.intReturn the maximum number of events to process in a single batch.intReturn the time, in milliseconds, that a processor should wait for available events before going into a cycle of updating claims and checking for incoming instructions.Returns theEventTrackerStatusChangeListenerdefined in this configuration, to be called whenever anEventTrackerStatuschange occurs.intReturn the number of segments requested for handling asynchronous processing of events.Return the builder function of the initialTrackingToken.intReturn the pool size of core threads as perThreadPoolExecutor.getCorePoolSize().getThreadFactory(String processorName) longReturns the time, in milliseconds, the processor should wait after a failed attempt to claim any segments for processing.longReturns the timeout to terminate workers during aTrackingEventProcessor.shutDown().booleanReturn abooleandictating whether the processor should start automatically when the application starts.
-
Method Details
-
forSingleThreadedProcessing
Initialize a configuration with single threaded processing.- Returns:
- A Configuration prepared for single threaded processing.
-
forParallelProcessing
Initialize a configuration instance with the giventhreadCount. This is both the number of threads that a processor will start for processing, as well as the initial number of segments that will be created when the processor is first started.- Parameters:
threadCount- The number of segments to process in parallel.- Returns:
- A newly created configuration.
-
andBatchSize
Set the maximum number of events that may be processed in a single transaction. Defaults to1.- Parameters:
batchSize- The maximum number of events to process in a single batch.- Returns:
thisfor method chaining.
-
andInitialSegmentsCount
Sets the initial number of segments for asynchronous processing. Will be combined with theinitial tracking tokenbuilder method for freshTrackingEventProcessors.This value is only used whenever there are no
TrackingTokenspresent for theTrackingEventProcessorthis configuration is used on.- Parameters:
segmentsSize- The number of segments requested for handling asynchronous processing of events.- Returns:
thisfor method chaining.
-
andThreadFactory
public TrackingEventProcessorConfiguration andThreadFactory(@Nonnull Function<String, ThreadFactory> threadFactory) Sets theThreadFactoryto use to create theThreadsto process events on. Each segment will be processed by a separate thread.- Parameters:
threadFactory- TheThreadFactoryto createThreadswith.- Returns:
thisfor method chaining.
-
andEventAvailabilityTimeout
public TrackingEventProcessorConfiguration andEventAvailabilityTimeout(long interval, TimeUnit unit) Set the duration where a Tracking Processor will wait for the availability of Events, in each cycle, before extending the claim on the tokens it owns.Note that some storage engines for the EmbeddedEventStore do not support streaming. They may poll for messages once on an
BlockingStream.hasNextAvailable(int, TimeUnit)invocation, and wait for the timeout to occur.This value should be significantly shorter than the claim timeout configured on the Token Store. Failure to do so may cause claims to be stolen while a tread is waiting for events. Also, with very long timeouts, it will take longer for threads to pick up the instructions they need to process.
Defaults to 1 second.
The given value must be strictly larger than 0, and may not exceed
Integer.MAX_VALUEmilliseconds.- Parameters:
interval- The interval in which claims on segments need to be extended.unit- The unit in which the interval is expressed.- Returns:
thisfor method chaining.
-
andInitialTrackingToken
public TrackingEventProcessorConfiguration andInitialTrackingToken(@Nonnull Function<StreamableMessageSource<TrackedEventMessage<?>>, TrackingToken> initialTrackingTokenBuilder) Sets the builder to use to create the initialTrackingToken. This token is used by the processor as a starting point.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:
initialTrackingTokenBuilder- The builder of the initialTrackingToken.- Returns:
thisfor method chaining.
-
andTokenClaimInterval
public TrackingEventProcessorConfiguration andTokenClaimInterval(long tokenClaimInterval, @Nonnull TimeUnit timeUnit) Sets the time to wait after a failed attempt to claim any token, before making another attempt.- Parameters:
tokenClaimInterval- The time to wait in between attempts to claim a token.timeUnit- The unit of time.- Returns:
thisfor method chaining.
-
andAutoStart
Whether to automatically start the processor when event processing is initialized. If set tofalse, the application must explicitly start the processor. This can be useful if the application needs to perform its own initialization before it begins processing new events.The autostart setting does not impact the shutdown process of the processor. It will always be triggered when the framework receives a signal to shut down.
- Parameters:
autoStart-trueto automatically start the processor (the default),falseif the application will start the processor itself.- Returns:
thisfor method chaining.
-
andEventTrackerStatusChangeListener
public TrackingEventProcessorConfiguration andEventTrackerStatusChangeListener(@Nonnull EventTrackerStatusChangeListener eventTrackerStatusChangeListener) Sets theEventTrackerStatusChangeListenerwhich will be called onEventTrackerStatuschanges.Defaults to
EventTrackerStatusChangeListener.noOp().- Parameters:
eventTrackerStatusChangeListener- TheEventTrackerStatusChangeListenerto use.- Returns:
thisfor method chaining.
-
andWorkerTerminationTimeout
@Deprecated public TrackingEventProcessorConfiguration andWorkerTerminationTimeout(long workerTerminationTimeoutInMilliseconds) Deprecated.UseandWorkerTerminationTimeout(long, TimeUnit)instead.Sets the shutdown timeout to terminate active workers.This is used for both the graceful termination and the potential forced termination of active workers. It is thus possible that it is used twice during the shutdown phase. Defaults to 5000ms.
- Parameters:
workerTerminationTimeoutInMilliseconds- The timeout for workers to terminate on a shutdown in milliseconds.- Returns:
thisfor method chaining.
-
andWorkerTerminationTimeout
public TrackingEventProcessorConfiguration andWorkerTerminationTimeout(long workerTerminationTimeout, TimeUnit timeUnit) Sets the shutdown timeout to terminate active workers.This is used for both the graceful termination and the potential forced termination of active workers. It is thus possible that it is used twice during the shutdown phase. Defaults to 5000ms.
- Parameters:
workerTerminationTimeout- The timeout for workers to terminate on a shutdown.timeUnit- The unit of time.- Returns:
thisfor method chaining.
-
getBatchSize
public int getBatchSize()Return the maximum number of events to process in a single batch.- Returns:
- The maximum number of events to process in a single batch.
-
getInitialSegmentsCount
public int getInitialSegmentsCount()Return the number of segments requested for handling asynchronous processing of events.- Returns:
- The number of segments requested for handling asynchronous processing of events.
-
getInitialTrackingToken
public Function<StreamableMessageSource<TrackedEventMessage<?>>,TrackingToken> getInitialTrackingToken()Return the builder function of the initialTrackingToken.- Returns:
- The builder of initial
TrackingToken.
-
getMaxThreadCount
public int getMaxThreadCount()Return the pool size of core threads as perThreadPoolExecutor.getCorePoolSize().- Returns:
- the pool size of core threads as per
ThreadPoolExecutor.getCorePoolSize().
-
getEventAvailabilityTimeout
public int getEventAvailabilityTimeout()Return the time, in milliseconds, that a processor should wait for available events before going into a cycle of updating claims and checking for incoming instructions.- Returns:
- The time, in milliseconds, that a processor should wait for available events before going into a cycle of updating claims and checking for incoming instructions.
-
getThreadFactory
- Parameters:
processorName- The name of the processor for which to return theThreadFactory.- Returns:
- The configured
ThreadFactory.
-
getTokenClaimInterval
public long getTokenClaimInterval()Returns the time, in milliseconds, the processor should wait after a failed attempt to claim any segments for processing. Generally, this means all segments are claimed.- Returns:
- The time, in milliseconds, to wait in between attempts to claim a token.
- See Also:
-
isAutoStart
public boolean isAutoStart()Return abooleandictating whether the processor should start automatically when the application starts.- Returns:
trueif the processor should be started automatically by the framework.
-
getEventTrackerStatusChangeListener
Returns theEventTrackerStatusChangeListenerdefined in this configuration, to be called whenever anEventTrackerStatuschange occurs.- Returns:
- The
EventTrackerStatusChangeListenerdefined in this configuration.
-
getWorkerTerminationTimeout
public long getWorkerTerminationTimeout()Returns the timeout to terminate workers during aTrackingEventProcessor.shutDown().- Returns:
- The timeout to terminate workers during a
TrackingEventProcessor.shutDown().
-
andWorkerTerminationTimeout(long, TimeUnit)instead.