Class TrackingEventProcessorConfiguration

java.lang.Object
org.axonframework.eventhandling.TrackingEventProcessorConfiguration

public class TrackingEventProcessorConfiguration extends Object
Configuration object for the 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 Details

    • forSingleThreadedProcessing

      public static TrackingEventProcessorConfiguration forSingleThreadedProcessing()
      Initialize a configuration with single threaded processing.
      Returns:
      A Configuration prepared for single threaded processing.
    • forParallelProcessing

      public static TrackingEventProcessorConfiguration forParallelProcessing(int threadCount)
      Initialize a configuration instance with the given threadCount. 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

      public TrackingEventProcessorConfiguration andBatchSize(int batchSize)
      Set the maximum number of events that may be processed in a single transaction. Defaults to 1.
      Parameters:
      batchSize - The maximum number of events to process in a single batch.
      Returns:
      this for method chaining.
    • andInitialSegmentsCount

      public TrackingEventProcessorConfiguration andInitialSegmentsCount(int segmentsSize)
      Sets the initial number of segments for asynchronous processing. Will be combined with the initial tracking token builder method for fresh TrackingEventProcessors.

      This value is only used whenever there are no TrackingTokens present for the TrackingEventProcessor this configuration is used on.

      Parameters:
      segmentsSize - The number of segments requested for handling asynchronous processing of events.
      Returns:
      this for method chaining.
    • andThreadFactory

      public TrackingEventProcessorConfiguration andThreadFactory(@Nonnull Function<String,ThreadFactory> threadFactory)
      Sets the ThreadFactory to use to create the Threads to process events on. Each segment will be processed by a separate thread.
      Parameters:
      threadFactory - The ThreadFactory to create Threads with.
      Returns:
      this for 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_VALUE milliseconds.

      Parameters:
      interval - The interval in which claims on segments need to be extended.
      unit - The unit in which the interval is expressed.
      Returns:
      this for method chaining.
    • andInitialTrackingToken

      public TrackingEventProcessorConfiguration andInitialTrackingToken(@Nonnull Function<StreamableMessageSource<TrackedEventMessage<?>>,TrackingToken> initialTrackingTokenBuilder)
      Sets the builder to use to create the initial TrackingToken. 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 ReplayToken that starts streaming from the tail with the replay flag enabled until the head at the moment of initialization is reached.

      Parameters:
      initialTrackingTokenBuilder - The builder of the initial TrackingToken.
      Returns:
      this for 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:
      this for method chaining.
    • andAutoStart

      public TrackingEventProcessorConfiguration andAutoStart(boolean autoStart)
      Whether to automatically start the processor when event processing is initialized. If set to false, 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 - true to automatically start the processor (the default), false if the application will start the processor itself.
      Returns:
      this for method chaining.
    • andEventTrackerStatusChangeListener

      public TrackingEventProcessorConfiguration andEventTrackerStatusChangeListener(@Nonnull EventTrackerStatusChangeListener eventTrackerStatusChangeListener)
      Parameters:
      eventTrackerStatusChangeListener - The EventTrackerStatusChangeListener to use.
      Returns:
      this for method chaining.
    • andWorkerTerminationTimeout

      @Deprecated public TrackingEventProcessorConfiguration andWorkerTerminationTimeout(long workerTerminationTimeoutInMilliseconds)
      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:
      this for 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:
      this for 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 initial TrackingToken.
      Returns:
      The builder of initial TrackingToken.
    • getMaxThreadCount

      public int getMaxThreadCount()
      Return the pool size of core threads as per ThreadPoolExecutor.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

      public ThreadFactory getThreadFactory(String processorName)
      Provides the ThreadFactory to use to construct Threads for the processor with given processorName.
      Parameters:
      processorName - The name of the processor for which to return the ThreadFactory.
      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 a boolean dictating whether the processor should start automatically when the application starts.
      Returns:
      true if the processor should be started automatically by the framework.
    • getEventTrackerStatusChangeListener

      public EventTrackerStatusChangeListener getEventTrackerStatusChangeListener()
      Returns the EventTrackerStatusChangeListener defined in this configuration, to be called whenever an EventTrackerStatus change occurs.
      Returns:
      The EventTrackerStatusChangeListener defined in this configuration.
    • getWorkerTerminationTimeout

      public long getWorkerTerminationTimeout()
      Returns the timeout to terminate workers during a TrackingEventProcessor.shutDown().
      Returns:
      The timeout to terminate workers during a TrackingEventProcessor.shutDown().