Class DisruptorDispatcher<T extends DispatcherContainer<T>>
java.lang.Object
com.sportradar.livedata.sdk.dispatch.DisruptorDispatcher<T>
- Type Parameters:
T- Specifies the type used by disruptor to store unprocessed messages.
- Direct Known Subclasses:
LiveScoutDisruptorDispatcher
A base class for dispatcher classes which internally uses a disruptor pattern for dispatching.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDisruptorDispatcher(ExecutorService executor, int dispatcherCount, int dispatcherQueueSize) Initializes a new instance of theDisruptorDispatcherclass. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract com.lmax.disruptor.EventHandler[]protected voidPublishes the passedcontainerto the ring buffer.protected voidstartDisruptor(com.lmax.disruptor.EventFactory<T> containerFactory) Constructs and starts the disruptor and associated elementsprotected voidstopDisruptor(long timeout, TimeUnit timeUnit) Gracefully stops the disruptor in given interval and disposes resources associated with the currentDisruptorDispatcherinstance.
-
Field Details
-
sdkLogger
TheSdkLoggerinstance used for structured logging. -
dispatcherCount
protected final int dispatcherCountThe number of the dispatchers -
dispatcherQueueSize
protected final int dispatcherQueueSizeThe size of the disruptor -
halfDispatcherQueueSize
protected final long halfDispatcherQueueSizeThe half size of the disruptor
-
-
Constructor Details
-
DisruptorDispatcher
protected DisruptorDispatcher(ExecutorService executor, int dispatcherCount, int dispatcherQueueSize) Initializes a new instance of theDisruptorDispatcherclass.- Parameters:
executor- TheExecutorServiceused to spawn background threadsdispatcherCount- The number of the dispatchers.dispatcherQueueSize- The size of the disruptor.
-
-
Method Details
-
publish
Publishes the passedcontainerto the ring buffer.- Parameters:
container- The container to be published- Throws:
IllegalStateException- The dispatcher is stopped.IllegalArgumentException- Thecontaineris a null reference.com.lmax.disruptor.InsufficientCapacityException- Ring buffer is full.
-
startDisruptor
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- AEventFactoryimplementation used to construct containers- Throws:
IllegalStateException- theDisruptorDispatcheris already started.
-
buildConsumers
protected abstract com.lmax.disruptor.EventHandler[] buildConsumers() -
stopDisruptor
Gracefully stops the disruptor in given interval and disposes resources associated with the currentDisruptorDispatcherinstance.- Parameters:
timeout- timeouttimeUnit- timeUnit
-