public class InmemQueue extends Object implements IQueue, Closeable, AutoCloseable
IQueue.
Implementation:
Queue as queue storage.ConcurrentMap as ephemeral storage.| Constructor and Description |
|---|
InmemQueue() |
InmemQueue(int boundary) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected Queue<IQueueMessage> |
createQueue(int boundary)
This method will create a
Queue instance with the following
rules:
If boundary is set and larger than 1024, a
LinkedBlockingQueue is created; if boundary is less than
or equals to 1024, an ArrayBlockingQueue is created
instead.
Otherwise, a ConcurrentLinkedQueue is created.
|
void |
destroy()
Destroy method.
|
int |
ephemeralSize()
Gets ephemeral-storage's number of items.
|
void |
finish(IQueueMessage msg)
Called when finish processing the message to cleanup ephemeral storage.
|
int |
getBoundary()
Gets queue's boundary (max number of elements).
|
boolean |
getEphemeralDisabled()
Is ephemeral storage disabled?
|
Collection<IQueueMessage> |
getOrphanMessages(long thresholdTimestampMs)
Gets all orphan messages (messages that were left in ephemeral storage
for a long time).
|
InmemQueue |
init()
Init method.
|
boolean |
isEphemeralDisabled()
Is ephemeral storage disabled?
|
boolean |
moveFromEphemeralToQueueStorage(IQueueMessage _msg)
Moves a message from ephemeral back to queue storage.
|
protected boolean |
putToQueue(IQueueMessage msg)
Puts a message to the internal queue.
|
boolean |
queue(IQueueMessage _msg)
Queues a message.
|
int |
queueSize()
Gets queue's number of items.
|
boolean |
requeue(IQueueMessage _msg)
Re-queues a message.
|
boolean |
requeueSilent(IQueueMessage msg)
Silently re-queues a message.
|
InmemQueue |
setBoundary(int boundary)
Sets queue's boundary (max number of elements).
|
InmemQueue |
setEphemeralDisabled(boolean ephemeralDisabled)
Disables/Enables ephemeral storage.
|
IQueueMessage |
take()
Takes a message out of queue.
|
protected IQueueMessage |
takeFromQueue()
Takes a message from the internal queue.
|
public boolean getEphemeralDisabled()
public boolean isEphemeralDisabled()
public InmemQueue setEphemeralDisabled(boolean ephemeralDisabled)
ephemeralDisabled - true to disable ephemeral storage, false
otherwise.public int getBoundary()
public InmemQueue setBoundary(int boundary)
boundary - queue's max number of elements, a value less than 1
mean "no boundary".protected Queue<IQueueMessage> createQueue(int boundary)
Queue instance with the following
rules:
boundary is set and larger than 1024, a
LinkedBlockingQueue is created; if boundary is less than
or equals to 1024, an ArrayBlockingQueue is created
instead.ConcurrentLinkedQueue is created.boundary - public InmemQueue init()
public void destroy()
public void close()
close in interface Closeableclose in interface AutoCloseableprotected boolean putToQueue(IQueueMessage msg)
msg - public boolean queue(IQueueMessage _msg)
Implementation flow:
public boolean requeue(IQueueMessage _msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
public boolean requeueSilent(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
requeueSilent in interface IQueuepublic void finish(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
protected IQueueMessage takeFromQueue()
public IQueueMessage take()
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
public Collection<IQueueMessage> getOrphanMessages(long thresholdTimestampMs)
getOrphanMessages in interface IQueuethresholdTimestampMs - public boolean moveFromEphemeralToQueueStorage(IQueueMessage _msg)
Implementation flow:
moveFromEphemeralToQueueStorage in interface IQueuetrue if a move has been made, false otherwise
(e.g. the message didn't exist in ephemeral storage)public int queueSize()
public int ephemeralSize()
Note: ephemeral storage implementation is optional, depends on implementation.
ephemeralSize in interface IQueueCopyright © 2016 DDTH. All rights reserved.