public class CallableQueueService extends Object implements Service, Instrumentable
XCallable
s for asynchronous execution.
Callables can be queued for immediate execution or for delayed execution (some time in the future).
Callables are consumed from the queue for execution based on their priority.
When the queues (for immediate execution and for delayed execution) are full, the callable queue service stops queuing callables.
A thread-pool is used to execute the callables asynchronously.
The following configuration parameters control the callable queue service:
CONF_QUEUE_SIZE
size of the immediate execution queue. Defaulf value is 10000.
CONF_THREADS
number of threads in the thread-pool used for asynchronous command execution. When this number
of threads is reached, commands remain the queue until threads become available. Sets up a priority queue for the
execution of Commands via a ThreadPool. Sets up a Delayed Queue to handle actions which will be ready for execution
sometime in the future.
Modifier and Type | Class and Description |
---|---|
class |
CallableQueueService.CallableWrapper<E> |
Modifier and Type | Field and Description |
---|---|
static int |
CONCURRENCY_DELAY |
static String |
CONF_CALLABLE_CONCURRENCY |
static String |
CONF_CALLABLE_INTERRUPT_MAP_MAX_SIZE |
static String |
CONF_CALLABLE_INTERRUPT_TYPES |
static String |
CONF_CALLABLE_NEXT_ELIGIBLE |
static String |
CONF_PREFIX |
static String |
CONF_QUEUE_SIZE |
static String |
CONF_THREADS |
static int |
SAFE_MODE_DELAY |
DEFAULT_LOCK_TIMEOUT, lockTimeout
Constructor and Description |
---|
CallableQueueService() |
Modifier and Type | Method and Description |
---|---|
Set<XCallable<?>> |
checkInterrupts(String lockKey)
check the interrupt map for the existence of an interrupt commands if
exist a List of Interrupt Callable for the same lock key will bereturned,
otherwise it will return null
|
void |
checkInterruptTypes(XCallable<?> callable)
check if the callable is of an interrupt type and insert it into the map
accordingly
|
void |
destroy()
Destroy the command queue service.
|
Class<? extends Service> |
getInterface()
Return the public interface for command queue service.
|
Set<String> |
getInterruptTypes() |
List<String> |
getQueueDump()
Get the list of strings of queue dump
|
List<String> |
getUniqueDump()
Get the list of strings of uniqueness map dump
|
void |
init(Services services)
Initialize the command queue service.
|
void |
insertCallableIntoInterruptMap(XCallable<?> callable)
insert a new callable in the Interrupt Command Map add a new element to
the list or create a new list accordingly
|
void |
instrument(Instrumentation instr)
Instruments the callable queue service.
|
<T> List<Future<T>> |
invokeAll(List<CallableQueueService.CallableWrapper<T>> tasks) |
boolean |
queue(XCallable<?> callable)
Queue a callable for asynchronous execution.
|
boolean |
queue(XCallable<?> callable,
long delay)
Queue a callable for asynchronous execution sometime in the future.
|
boolean |
queueSerial(List<? extends XCallable<?>> callables)
Queue a list of callables for serial execution.
|
boolean |
queueSerial(List<? extends XCallable<?>> callables,
long delay)
Queue a list of callables for serial execution sometime in the future.
|
int |
queueSize() |
public static final String CONF_PREFIX
public static final String CONF_QUEUE_SIZE
public static final String CONF_THREADS
public static final String CONF_CALLABLE_CONCURRENCY
public static final String CONF_CALLABLE_NEXT_ELIGIBLE
public static final String CONF_CALLABLE_INTERRUPT_TYPES
public static final String CONF_CALLABLE_INTERRUPT_MAP_MAX_SIZE
public static final int CONCURRENCY_DELAY
public static final int SAFE_MODE_DELAY
public CallableQueueService()
public void destroy()
public Class<? extends Service> getInterface()
getInterface
in interface Service
CallableQueueService
.public int queueSize()
public boolean queue(XCallable<?> callable)
callable
- callable to queue.true
if the callable was queued, false
if the queue is full and the callable
was not queued.public boolean queueSerial(List<? extends XCallable<?>> callables)
Useful to serialize callables that may compete with each other for resources.
All callables will be processed with the priority of the highest priority of all callables.
callables
- callables to be executed by the composite callable.true
if the callables were queued, false
if the queue is full and the callables
were not queued.public boolean queue(XCallable<?> callable, long delay)
callable
- callable to queue for delayed executiondelay
- time, in milliseconds, that the callable should be delayed.true
if the callable was queued, false
if the queue is full and the callable was not queued.public boolean queueSerial(List<? extends XCallable<?>> callables, long delay)
Useful to serialize callables that may compete with each other for resources.
All callables will be processed with the priority of the highest priority of all callables.
callables
- callables to be executed by the composite callable.delay
- time, in milliseconds, that the callable should be delayed.true
if the callables were queued, false
if the queue is full and the callables
were not queued.public void instrument(Instrumentation instr)
instrument
in interface Instrumentable
instr
- instance to instrument the callable queue service to.public Set<XCallable<?>> checkInterrupts(String lockKey)
public void checkInterruptTypes(XCallable<?> callable)
callable
- public void insertCallableIntoInterruptMap(XCallable<?> callable)
callable
- public List<String> getQueueDump()
public List<String> getUniqueDump()
public <T> List<Future<T>> invokeAll(List<CallableQueueService.CallableWrapper<T>> tasks) throws InterruptedException
InterruptedException
public Set<String> getInterruptTypes()
Copyright © 2018 Apache Software Foundation. All rights reserved.