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
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 Summary
Fields Modifier and Type Field Description protected int
dispatcherCount
The number of the dispatchersprotected int
dispatcherQueueSize
The size of the disruptorprotected long
halfDispatcherQueueSize
The half size of the disruptorprotected SdkLogger
sdkLogger
TheSdkLogger
instance used for structured logging.
-
Constructor Summary
Constructors Modifier Constructor Description protected
DisruptorDispatcher(ExecutorService executor, int dispatcherCount, int dispatcherQueueSize)
Initializes a new instance of theDisruptorDispatcher
class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract com.lmax.disruptor.EventHandler[]
buildConsumers()
protected void
publish(T container)
Publishes the passedcontainer
to the ring buffer.protected void
startDisruptor(com.lmax.disruptor.EventFactory<T> containerFactory)
Constructs and starts the disruptor and associated elementsprotected void
stopDisruptor(long timeout, TimeUnit timeUnit)
Gracefully stops the disruptor in given interval and disposes resources associated with the currentDisruptorDispatcher
instance.
-
-
-
Constructor Detail
-
DisruptorDispatcher
protected DisruptorDispatcher(ExecutorService executor, int dispatcherCount, int dispatcherQueueSize)
Initializes a new instance of theDisruptorDispatcher
class.- Parameters:
executor
- TheExecutorService
used to spawn background threadsdispatcherCount
- 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 passedcontainer
to the ring buffer.- Parameters:
container
- The container to be published- Throws:
IllegalStateException
- The dispatcher is stopped.IllegalArgumentException
- Thecontainer
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
- AEventFactory
implementation used to construct containers- Throws:
IllegalStateException
- theDisruptorDispatcher
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 currentDisruptorDispatcher
instance.- Parameters:
timeout
- timeouttimeUnit
- timeUnit
-
-