Class DisruptorDispatcher<T extends DispatcherContainer<T>>

  • Type Parameters:
    T - Specifies the type used by disruptor to store unprocessed messages.
    Direct Known Subclasses:
    LiveScoutDisruptorDispatcher

    public abstract class DisruptorDispatcher<T extends DispatcherContainer<T>>
    extends Object
    A base class for dispatcher classes which internally uses a disruptor pattern for dispatching.
    • Field Detail

      • sdkLogger

        protected final SdkLogger sdkLogger
        The SdkLogger instance used for structured logging.
      • dispatcherCount

        protected final int dispatcherCount
        The number of the dispatchers
      • dispatcherQueueSize

        protected final int dispatcherQueueSize
        The size of the disruptor
      • halfDispatcherQueueSize

        protected final long halfDispatcherQueueSize
        The half size of the disruptor
    • Constructor Detail

      • DisruptorDispatcher

        protected DisruptorDispatcher​(ExecutorService executor,
                                      int dispatcherCount,
                                      int dispatcherQueueSize)
        Initializes a new instance of the DisruptorDispatcher class.
        Parameters:
        executor - The ExecutorService used to spawn background threads
        dispatcherCount - The number of the dispatchers.
        dispatcherQueueSize - The size of the disruptor.
    • Method Detail

      • publish

        protected void publish​(T container)
                        throws com.lmax.disruptor.InsufficientCapacityException
        Publishes the passed container to the ring buffer.
        Parameters:
        container - The container to be published
        Throws:
        IllegalStateException - The dispatcher is stopped.
        IllegalArgumentException - The container is a null reference.
        com.lmax.disruptor.InsufficientCapacityException - Ring buffer is full.
      • startDisruptor

        protected void startDisruptor​(com.lmax.disruptor.EventFactory<T> containerFactory)

        Constructs and starts the disruptor and associated elements

        Notice that method is not thread safe and should only be called within critical region.

        Parameters:
        containerFactory - A EventFactory implementation used to construct containers
        Throws:
        IllegalStateException - the DisruptorDispatcher is already started.
      • buildConsumers

        protected abstract com.lmax.disruptor.EventHandler[] buildConsumers()
      • stopDisruptor

        protected void stopDisruptor​(long timeout,
                                     TimeUnit timeUnit)
        Gracefully stops the disruptor in given interval and disposes resources associated with the current DisruptorDispatcher instance.
        Parameters:
        timeout - timeout
        timeUnit - timeUnit