T - This defines the type of object the queue will work on.public class GenericInMemoryQueue<T>
extends java.lang.Object
| Constructor and Description |
|---|
GenericInMemoryQueue(java.lang.String name)
Constructor of Generic in memory queue.
|
GenericInMemoryQueue(java.lang.String name,
int batchSize)
Constructor which also configures batch size which is used by batch consumers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.util.Collection<T> items)
This method adds list of items to be processed in queue.
|
void |
add(T item)
This method add an item to the queue.
|
protected void |
batchProcess(java.util.function.Consumer<java.util.List<T>> consumer,
java.lang.String consumerName)
This method gets from the queue and process.
|
protected java.lang.StringBuilder |
buildErrorMessage(java.lang.String consumerName)
Build error message using consumer name and queue name.
|
protected void |
clear(java.util.function.Consumer<java.util.Queue<T>>... preCleanHandlers)
This method clears the current queue and pass the data to the consumer.
|
protected void |
doNotify()
This method Notify all consumers.
|
int |
getBatchConsumerCount()
Get batch consumer count.
|
protected java.util.List<T> |
getBatchData()
Get batch data which will be used to pass to batch consumer.
|
int |
getBatchSize()
Batch size which will be used by batch consumers.
|
int |
getDirectConsumerCount()
Get number of direct consumers.
|
protected java.lang.String |
getExceptionMessage(java.lang.String consumerName,
java.util.List<T> items)
This method builds the exception message for batch consumer.
|
protected java.lang.String |
getExceptionMessage(java.lang.String consumerName,
T item)
This method prepares the exception message containing name of consumer and queue.
|
java.lang.Long |
getNumberOfItemsInQueue()
Get number of items in queue.
|
java.lang.String |
getQueueName()
Get queue name.
|
java.lang.Long |
getSleepPostConsumingAll() |
java.lang.Long |
getSleepPostConsumingEvery() |
int |
getWaitTimeout()
This is the wait time for which different consumers wait for some message.
|
boolean |
isHasShutdown()
Have this queue shutdown?
|
boolean |
isShouldSleepAfterEveryConsumption() |
boolean |
isShouldSleepConsumingAll() |
protected void |
notifyConsumers()
This method notify on addition of an item in the queue.
|
void |
register(java.util.function.Consumer<T> consumer,
java.lang.String consumerName)
This method register the direct consumer.
|
void |
registerBatchConsumer(java.util.function.Consumer<java.util.List<T>> consumer,
java.lang.String consumerName)
Register batch consumer
|
void |
removeAllBatchConsumers()
Remove all batch consumers.
|
void |
removeAllDirectConsumers()
Removes all direct consumers.
|
GenericInMemoryQueue<T> |
setBatchSize(int batchSize)
Setter Batch size which will be used by batch consumers.
|
GenericInMemoryQueue<T> |
setNumberOfItemsInQueue(java.util.concurrent.atomic.AtomicLong numberOfItemsInQueue)
Set number of items in queue.
|
GenericInMemoryQueue<T> |
setQueueName(java.lang.String queueName)
Set name of the queue
|
GenericInMemoryQueue<T> |
setSleepPostConsumingAll(java.lang.Long sleepPostConsumingAll)
This method sets sleepPostConsumingAll with the value passed.
|
GenericInMemoryQueue<T> |
setSleepPostConsumingEach(java.lang.Long sleepPostConsumingEvery)
This method sets sleepPostConsumingEvery with the value passed.
|
GenericInMemoryQueue<T> |
setWaitTimeout(int waitTimeout)
This is the wait time for which different consumers wait for some message.
|
void |
shutdown()
To cleanup, shutdown method should be called.
|
protected void |
singleItemProcess(java.util.function.Consumer<T> consumer,
java.lang.String consumerName)
This method polls from the queue and process the consumer with data found.
|
protected void |
sleepIfConfigured()
Sleep post consuming all messages if configured.
|
protected void |
sleepIfConfiguredPostEveryConsumption() |
protected void |
startConsumer(java.lang.Runnable executionLogic,
java.lang.String name)
This method starts the consumer.
|
protected void |
startListening(java.lang.Runnable consumerLogic,
java.lang.String consumerName,
java.util.Collection<java.lang.String> consumerList)
This method start listener.
|
void |
unregister(java.lang.String consumerName)
This method unregister the consumer.
|
public GenericInMemoryQueue(java.lang.String name)
name - Name of queuepublic GenericInMemoryQueue(java.lang.String name,
int batchSize)
name - Name of queuebatchSize - Batch sizepublic java.lang.Long getSleepPostConsumingEvery()
public GenericInMemoryQueue<T> setSleepPostConsumingEach(java.lang.Long sleepPostConsumingEvery)
sleepPostConsumingEvery - the sleepPostConsumingEvery to setpublic boolean isShouldSleepConsumingAll()
public boolean isShouldSleepAfterEveryConsumption()
public java.lang.Long getSleepPostConsumingAll()
public GenericInMemoryQueue<T> setSleepPostConsumingAll(java.lang.Long sleepPostConsumingAll)
sleepPostConsumingAll - the sleepPostConsumingAll to setpublic void register(java.util.function.Consumer<T> consumer, java.lang.String consumerName)
consumer - The instance of Consumer to setconsumerName - The consumer name.protected void singleItemProcess(java.util.function.Consumer<T> consumer, java.lang.String consumerName)
consumer - The Consumer instance to setconsumerName - The String consumer name to setprotected void sleepIfConfiguredPostEveryConsumption()
protected void sleepIfConfigured()
protected java.lang.String getExceptionMessage(java.lang.String consumerName,
T item)
consumerName - The String consumer nameitem - The item of T type to setString exception messageprotected java.lang.String getExceptionMessage(java.lang.String consumerName,
java.util.List<T> items)
consumerName - the consumerNameitems - the list of itemsprotected java.lang.StringBuilder buildErrorMessage(java.lang.String consumerName)
consumerName - Consumer namepublic void registerBatchConsumer(java.util.function.Consumer<java.util.List<T>> consumer, java.lang.String consumerName)
consumer - the consumerconsumerName - the consumer nameprotected void startListening(java.lang.Runnable consumerLogic,
java.lang.String consumerName,
java.util.Collection<java.lang.String> consumerList)
consumerLogic - The instance of Runnable to setconsumerName - The String consumer name to setconsumerList - consumersList direct or batchprotected void startConsumer(java.lang.Runnable executionLogic,
java.lang.String name)
executionLogic - Execution logicname - Name of consumer which will be set as name.protected void batchProcess(java.util.function.Consumer<java.util.List<T>> consumer, java.lang.String consumerName)
consumer - The Consumer instance to setconsumerName - The String consumer name to setprotected java.util.List<T> getBatchData()
public void unregister(java.lang.String consumerName)
consumerName - The String consumer name to removeprotected void doNotify()
public void shutdown()
public void add(T item)
item - The item to addprotected void notifyConsumers()
public void add(java.util.Collection<T> items)
items - The List of items to addpublic int getDirectConsumerCount()
public int getBatchConsumerCount()
public boolean isHasShutdown()
public java.lang.String getQueueName()
public GenericInMemoryQueue<T> setQueueName(java.lang.String queueName)
queueName - the queueName to setpublic int getBatchSize()
public GenericInMemoryQueue<T> setBatchSize(int batchSize)
batchSize - the batchSize to setpublic java.lang.Long getNumberOfItemsInQueue()
public GenericInMemoryQueue<T> setNumberOfItemsInQueue(java.util.concurrent.atomic.AtomicLong numberOfItemsInQueue)
numberOfItemsInQueue - the numberOfItemsInQueue to setprotected void clear(java.util.function.Consumer<java.util.Queue<T>>... preCleanHandlers)
preCleanHandlers - Cleanerspublic void removeAllDirectConsumers()
public void removeAllBatchConsumers()
public int getWaitTimeout()
public GenericInMemoryQueue<T> setWaitTimeout(int waitTimeout)
waitTimeout - wait time out to be set