Package com.github.ddth.queue.impl
Class DisruptorQueue<ID,DATA>
- java.lang.Object
-
- com.github.ddth.queue.impl.AbstractQueue<ID,DATA>
-
- com.github.ddth.queue.impl.AbstractEphemeralSupportQueue<ID,DATA>
-
- com.github.ddth.queue.impl.AbstractInmemEphemeralQueue<ID,DATA>
-
- com.github.ddth.queue.impl.DisruptorQueue<ID,DATA>
-
- All Implemented Interfaces:
IQueue<ID,DATA>,AutoCloseable
- Direct Known Subclasses:
BaseUniversalDisruptorQueue
public class DisruptorQueue<ID,DATA> extends AbstractInmemEphemeralQueue<ID,DATA>
In-Memory implementation ofIQueueusing LMAX Disruptor library.Implementation:
- A Disruptor's
RingBufferto be the queue storage. - A
ConcurrentMapas ephemeral storage.
Features:
- Queue-size support: yes
- Ephemeral storage support: yes
- Ephemeral-size support: yes
- Since:
- 0.4.0
- Author:
- Thanh Ba Nguyen
- See Also:
- LMAXDisruptor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.ddth.queue.impl.AbstractQueue
AbstractQueue.PutToQueueCase
-
-
Field Summary
-
Fields inherited from interface com.github.ddth.queue.IQueue
SIZE_NOT_SUPPORTED
-
-
Constructor Summary
Constructors Constructor Description DisruptorQueue()DisruptorQueue(int ringSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleandoPutToQueue(IQueueMessage<ID,DATA> msg, AbstractQueue.PutToQueueCase queueCase)Put a message to the queue storage.voidfinish(IQueueMessage<ID,DATA> msg)Called when finish processing the message to cleanup ephemeral storage.protected intgetRingSize()Size of the ring buffer, should be power of 2.DisruptorQueue<ID,DATA>init()Init method.intqueueSize()Get number of items currently in queue storage.DisruptorQueue<ID,DATA>setRingSize(int ringSize)Size of the ring buffer, should be power of 2.IQueueMessage<ID,DATA>take()Take a message out of queue.protected IQueueMessage<ID,DATA>takeFromRingBuffer()Take a message from the ring buffer.-
Methods inherited from class com.github.ddth.queue.impl.AbstractInmemEphemeralQueue
doPutToEphemeralStorage, doRemoveFromEphemeralStorage, ensureEphemeralSize, ephemeralSize, getOrphanMessages, initEphemeralStorage, setEphemeralDisabled
-
Methods inherited from class com.github.ddth.queue.impl.AbstractEphemeralSupportQueue
getEphemeralDisabled, getEphemeralMaxSize, isEphemeralDisabled, setEphemeralMaxSize
-
Methods inherited from class com.github.ddth.queue.impl.AbstractQueue
close, createMessage, createMessage, createMessage, deserialize, deserialize, destroy, getMessageFactory, getQueueName, getSerDeser, queue, requeue, requeueSilent, serialize, setMessageFactory, setQueueName, setSerDeser
-
-
-
-
Method Detail
-
getRingSize
protected int getRingSize()
Size of the ring buffer, should be power of 2.- Returns:
-
setRingSize
public DisruptorQueue<ID,DATA> setRingSize(int ringSize)
Size of the ring buffer, should be power of 2.- Parameters:
ringSize-- Returns:
-
init
public DisruptorQueue<ID,DATA> init() throws Exception
Init method.- Overrides:
initin classAbstractQueue<ID,DATA>- Returns:
- Throws:
Exception
-
doPutToQueue
protected boolean doPutToQueue(IQueueMessage<ID,DATA> msg, AbstractQueue.PutToQueueCase queueCase) throws QueueException.QueueIsFull
Put a message to the queue storage.Sub-class implements this method.
- Specified by:
doPutToQueuein classAbstractQueue<ID,DATA>- Returns:
- Throws:
QueueException.QueueIsFull
-
finish
public void finish(IQueueMessage<ID,DATA> msg)
Called when finish processing the message to cleanup ephemeral storage.Implementation flow:
- Remove message from ephemeral storage.
Note: ephemeral storage implementation is optional, depends on implementation.
-
takeFromRingBuffer
protected IQueueMessage<ID,DATA> takeFromRingBuffer()
Take a message from the ring buffer.- Returns:
- the available message or
nullif the ring buffer is empty
-
take
public IQueueMessage<ID,DATA> take() throws QueueException.EphemeralIsFull
Take a message out of queue.Implementation flow:
- Read message from head of queue storage.
- Write message to ephemeral storage.
- Remove message from queue storage.
Note: ephemeral storage implementation is optional, depends on implementation.
- Returns:
- Throws:
QueueException.EphemeralIsFull- if the ephemeral storage is full
-
queueSize
public int queueSize()
Get number of items currently in queue storage.- Returns:
- negative number if queue size can not be queried
-
-