T - Type of queue.public class DynamicSettings<T>
extends java.lang.Object
InMemoryQueueTuner to tune as per configuration set by user.
As name suggest, this enables dynamic settings like increasing and decreasing consumer count on basis of number of messages.
Actual queue will be wrapped inside the settings.
| Constructor and Description |
|---|
DynamicSettings() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addItemInQueue(T item)
This method is responsible of adding data in queue.
|
boolean |
addItemsInQueue(java.util.Collection<T> list)
This method is responsible of adding data in list in queue.
|
DynamicSettings<T> |
addPreCleanHandler(java.util.function.Consumer<java.util.Queue<T>> preCleanHandler)
Add pre clean handler.
|
protected boolean |
addStillAllowed()
This method tells if we can still add in the queue.
|
void |
adjust()
This method handles the increase/decrease of consumers.
|
protected void |
decreaseConsumerIfPossible()
Decrease consumer if low limit attained back and we still have more consumers than minimum consumers.
|
protected java.util.function.Consumer<java.util.Queue<T>>[] |
getCleaners()
Get registered cleaners.
|
java.lang.Long |
getHighLimitWhenToIncreaseConsumer()
Get high limit when increase of consumer is tried.
|
java.lang.Long |
getLowLimitWhenToDecreseConsumer()
Get low limit when decrease of consumer is tried.
|
java.lang.Integer |
getMaxBatchConsumer()
Maximum batch consumers which can be created.
|
java.lang.Integer |
getMaxDirectConsumer()
Maximum direct consumers which can be created.
|
java.lang.Integer |
getMinBatchConsumer()
Minimum batch consumers which can be reduced to.
|
java.lang.Integer |
getMinDirectConsumer()
Minimum direct consumers which can be reduced to.
|
java.lang.Long |
getNumberOfRetriesToWait()
Number of retries while adding at threshold.
|
InMemoryQueue<T> |
getQueue() |
java.lang.Boolean |
getShouldClearQueueAtThreshold()
Should clear the queue if threshold reached.
|
java.lang.Boolean |
getShouldRetrySenderTillThresholdNotRecovered()
Is retry enabled while adding if threshold is reached.
|
java.lang.Boolean |
getShouldStopAddingAtThreshold()
Should stop adding at threshold.
|
java.lang.Boolean |
getShouldThrowExceptionPostRetry()
Should throw exception post retries.
|
java.lang.Boolean |
getShouldThrowExceptionWhenThresholdAtAdd()
Should throw exception when threshold reached in add process.
|
java.lang.Long |
getThresholdWhenNoMoreItemsShouldBeHandled()
Threshold when more item should not be added.
|
java.lang.Long |
getWaitForRetryThresholdLimit()
Wait time for retries.
|
protected boolean |
handleStopAddingAtThreshold()
This method is to handle in situation where we need to continue even when threshold reached.
|
protected void |
increaseConsumerIfPossible()
Increase consumers if high limit is reached and we still have number of consumers less than total current consumers.
|
protected <K> boolean |
processAddItem(java.util.function.Consumer<K> consumer,
K item)
Checks if add item allowed and add the item to queue.
|
DynamicSettings<T> |
setHighLimitWhenToIncreaseConsumer(java.lang.Long highLimitWhenToIncreaseConsumer)
Set high limit when increase of consumer is tried.
|
DynamicSettings<T> |
setLowLimitWhenToDecreseConsumer(java.lang.Long lowLimitWhenToDecreseConsumer)
Set low limit when decrease of consumer is tried.
|
DynamicSettings<T> |
setMaxBatchConsumer(java.lang.Integer maxBatchConsumer)
Set the number of maximum batch consumers which can be created.
|
DynamicSettings<T> |
setMaxDirectConsumer(java.lang.Integer maxDirectConsumer)
Set the number of maximum direct consumers which can be created.
|
DynamicSettings<T> |
setMinBatchConsumer(java.lang.Integer minBatchConsumer)
Setter of minimum batch consumers till which consumers count be reduced to.
|
DynamicSettings<T> |
setMinDirectConsumer(java.lang.Integer minDirectConsumer)
Setter of mimimum direct consumers till which consumers count be reduced to.
|
DynamicSettings<T> |
setNumberOfRetriesToWait(java.lang.Long numberOfRetriesToWait)
Setter of Number of retries while adding at threshold.
|
DynamicSettings<T> |
setQueue(InMemoryQueue<T> queue)
Setting queue to be worked upon.
|
DynamicSettings<T> |
setShouldClearQueueAtThreshold(java.lang.Boolean shouldClearQueueAtThreshold)
Configures to if should clear queue at threshold.
|
DynamicSettings<T> |
setShouldRetrySenderTillThresholdNotRecovered(java.lang.Boolean shouldPauseSenderTillThresholdNotRecovered)
Setter of retry enabled while adding if threshold is reached.
|
DynamicSettings<T> |
setShouldStopAddingAtThreshold(java.lang.Boolean shouldStopAddingAtThreshold)
Setter of should stop adding at threshold.
|
DynamicSettings<T> |
setShouldThrowExceptionPostRetry(java.lang.Boolean shouldThrowExceptionPostRetry)
Set if exception should be thrown to producers if threshold is reached and configured amount of retries are also taken.
|
DynamicSettings<T> |
setShouldThrowExceptionWhenThresholdAtAdd(java.lang.Boolean shouldThrowExceptionWhenThresholdAtAdd)
Setter of Should throw exception when threshold reached in add process.
|
DynamicSettings<T> |
setThresholdWhenNoMoreItemsShouldBeHandled(java.lang.Long thresholdWheNoMoreItemsShouldBeHandled)
Threshold when more item should not be added.
|
DynamicSettings<T> |
setWaitForRetryThresholdLimit(java.lang.Long waitForRetryThresholdLimit)
Set wait time for retry.
|
void |
shutdown()
Shutdown underlying queue.
|
static void |
sleep(java.lang.Long sleepTime)
Sleep for configured amount.
|
protected void |
tryIfCanFreeUp()
It verifies if it can free up messages based on configurations and condition.
|
protected boolean |
waitForRetriesIfAny()
This method waits for configured number and for given time if allowed to wait.
|
public InMemoryQueue<T> getQueue()
public DynamicSettings<T> setQueue(InMemoryQueue<T> queue)
queue - Queue which needs to be worked uponpublic java.lang.Boolean getShouldThrowExceptionPostRetry()
public DynamicSettings<T> setShouldThrowExceptionPostRetry(java.lang.Boolean shouldThrowExceptionPostRetry)
shouldThrowExceptionPostRetry - Boolean value to setpublic static void sleep(java.lang.Long sleepTime)
sleepTime - Sleep time for which we want to sleeppublic java.lang.Integer getMaxDirectConsumer()
public DynamicSettings<T> setMaxDirectConsumer(java.lang.Integer maxDirectConsumer)
maxDirectConsumer - Maximum direct consumerpublic java.lang.Integer getMinDirectConsumer()
public DynamicSettings<T> setMinDirectConsumer(java.lang.Integer minDirectConsumer)
minDirectConsumer - Minimum direct consumer count to be setpublic java.lang.Integer getMaxBatchConsumer()
public DynamicSettings<T> setMaxBatchConsumer(java.lang.Integer maxBatchConsumer)
maxBatchConsumer - Maximum batch consumerpublic java.lang.Integer getMinBatchConsumer()
public DynamicSettings<T> setMinBatchConsumer(java.lang.Integer minBatchConsumer)
minBatchConsumer - Minimum direct consumer count to be setpublic java.lang.Long getHighLimitWhenToIncreaseConsumer()
public DynamicSettings<T> setHighLimitWhenToIncreaseConsumer(java.lang.Long highLimitWhenToIncreaseConsumer)
highLimitWhenToIncreaseConsumer - High limit when increase of consumer should be triedpublic java.lang.Long getLowLimitWhenToDecreseConsumer()
public DynamicSettings<T> setLowLimitWhenToDecreseConsumer(java.lang.Long lowLimitWhenToDecreseConsumer)
lowLimitWhenToDecreseConsumer - Low limit which should be taken in considerationpublic java.lang.Long getThresholdWhenNoMoreItemsShouldBeHandled()
public DynamicSettings<T> setThresholdWhenNoMoreItemsShouldBeHandled(java.lang.Long thresholdWheNoMoreItemsShouldBeHandled)
thresholdWheNoMoreItemsShouldBeHandled - Threshold value to be configured topublic java.lang.Boolean getShouldClearQueueAtThreshold()
public DynamicSettings<T> setShouldClearQueueAtThreshold(java.lang.Boolean shouldClearQueueAtThreshold)
shouldClearQueueAtThreshold - boolean valuepublic java.lang.Boolean getShouldStopAddingAtThreshold()
public DynamicSettings<T> setShouldStopAddingAtThreshold(java.lang.Boolean shouldStopAddingAtThreshold)
shouldStopAddingAtThreshold - value to be setpublic java.lang.Boolean getShouldRetrySenderTillThresholdNotRecovered()
public DynamicSettings<T> setShouldRetrySenderTillThresholdNotRecovered(java.lang.Boolean shouldPauseSenderTillThresholdNotRecovered)
shouldPauseSenderTillThresholdNotRecovered - value to be setpublic java.lang.Long getWaitForRetryThresholdLimit()
public DynamicSettings<T> setWaitForRetryThresholdLimit(java.lang.Long waitForRetryThresholdLimit)
waitForRetryThresholdLimit - Wait for retry value to be setpublic java.lang.Long getNumberOfRetriesToWait()
public DynamicSettings<T> setNumberOfRetriesToWait(java.lang.Long numberOfRetriesToWait)
numberOfRetriesToWait - Number of retriespublic void adjust()
protected void tryIfCanFreeUp()
protected java.util.function.Consumer<java.util.Queue<T>>[] getCleaners()
protected void increaseConsumerIfPossible()
protected void decreaseConsumerIfPossible()
public java.lang.Boolean getShouldThrowExceptionWhenThresholdAtAdd()
public DynamicSettings<T> setShouldThrowExceptionWhenThresholdAtAdd(java.lang.Boolean shouldThrowExceptionWhenThresholdAtAdd)
shouldThrowExceptionWhenThresholdAtAdd - Value to be setpublic boolean addItemInQueue(T item)
item - Item to be added to queueprotected <K> boolean processAddItem(java.util.function.Consumer<K> consumer,
K item)
K - type of item to be addedconsumer - Consumer which will actually add item in queueitem - Item to be addedpublic boolean addItemsInQueue(java.util.Collection<T> list)
list - List containing data to be saved in queueprotected boolean addStillAllowed()
protected boolean handleStopAddingAtThreshold()
ThresholdReachedException in case all retries are over and still threshold is there.protected boolean waitForRetriesIfAny()
public DynamicSettings<T> addPreCleanHandler(java.util.function.Consumer<java.util.Queue<T>> preCleanHandler)
preCleanHandler - Hanlder to be called before clearpublic void shutdown()