public abstract class QueueBackedScheduledService<E>
extends com.google.common.util.concurrent.AbstractScheduledService
AbstractScheduledService that maintains a queue of tasks and executes them in a single thread by constantly
pulling the tasks from the head of the queue.
By default, if the queue capacity is full, tasks are dropped and a warning is logged.
Note that start() must be called in order to start processing the queue and stop() should be called
before the application is shut down.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_QUEUE_CAPACITY |
protected LinkedBlockingDeque<E> |
queue |
| Modifier | Constructor and Description |
|---|---|
protected |
QueueBackedScheduledService()
Construct a new service with a default queue capacity of
DEFAULT_QUEUE_CAPACITY. |
protected |
QueueBackedScheduledService(int queueCapacity)
Construct a new service.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
int |
hashCode() |
protected boolean |
logEmptyQueue()
Return
true iff empty queue should be logged. |
protected long |
loggingFrequencyMs()
How often in ms should the queue size be reported to the log.
|
protected boolean |
offer(E futureTask)
Offer a task to the queue for processing.
|
protected com.google.common.util.concurrent.AbstractScheduledService.Scheduler |
scheduler() |
protected void |
shutDown() |
void |
start()
Start the processing of tasks.
|
void |
stop()
Stop the processing of tasks.
|
public static final int DEFAULT_QUEUE_CAPACITY
protected final LinkedBlockingDeque<E> queue
protected QueueBackedScheduledService()
DEFAULT_QUEUE_CAPACITY.protected QueueBackedScheduledService(int queueCapacity)
queueCapacity - capacity of the queue.public void start()
public void stop()
protected void shutDown()
throws Exception
shutDown in class com.google.common.util.concurrent.AbstractScheduledServiceExceptionprotected boolean offer(E futureTask)
false in
case the queue is full, otherwise return true.futureTask - to offer to the queue.protected boolean logEmptyQueue()
true iff empty queue should be logged. Defaults to false, intended to be overridden.protected long loggingFrequencyMs()
LOGGING_INTERVAL_MS, intended to be overridden.protected com.google.common.util.concurrent.AbstractScheduledService.Scheduler scheduler()
scheduler in class com.google.common.util.concurrent.AbstractScheduledServiceCopyright © 2013-2016–2020 Graph Aware Limited. All rights reserved.