Package com.github.ddth.queue.impl
Class InmemQueue<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.InmemQueue<ID,DATA>
-
- All Implemented Interfaces:
IQueue<ID,DATA>,AutoCloseable
- Direct Known Subclasses:
BaseUniversalInmemQueue
public class InmemQueue<ID,DATA> extends AbstractInmemEphemeralQueue<ID,DATA>
In-Memory implementation ofIQueue.Implementation:
- A
Queueas 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
-
-
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 InmemQueue()InmemQueue(int boundary)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Queue<IQueueMessage<ID,DATA>>createQueue(int boundary)This method will create aQueueinstance with the following rules: Ifboundaryis set and larger than1024, aLinkedBlockingQueueis created; ifboundaryis less than or equals to1024, anArrayBlockingQueueis created instead. Otherwise, aConcurrentLinkedQueueis created.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.intgetBoundary()Gets queue's boundary (max number of elements).InmemQueue<ID,DATA>init()Init method.intqueueSize()Get number of items currently in queue storage.InmemQueue<ID,DATA>setBoundary(int boundary)Sets queue's boundary (max number of elements).IQueueMessage<ID,DATA>take()Take a message out of queue.protected IQueueMessage<ID,DATA>takeFromQueue()Takes a message from the internal queue.-
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
-
getBoundary
public int getBoundary()
Gets queue's boundary (max number of elements).- Returns:
-
setBoundary
public InmemQueue<ID,DATA> setBoundary(int boundary)
Sets queue's boundary (max number of elements).- Parameters:
boundary- queue's max number of elements, a value less than1mean "no boundary".- Returns:
-
createQueue
protected Queue<IQueueMessage<ID,DATA>> createQueue(int boundary)
This method will create aQueueinstance with the following rules:- If
boundaryis set and larger than1024, aLinkedBlockingQueueis created; ifboundaryis less than or equals to1024, anArrayBlockingQueueis created instead. - Otherwise, a
ConcurrentLinkedQueueis created.
- Parameters:
boundary-- Returns:
- If
-
init
public InmemQueue<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.
-
takeFromQueue
protected IQueueMessage<ID,DATA> takeFromQueue()
Takes a message from the internal queue.- Returns:
-
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
-
-