Package org.apache.commons.jcs3.engine
Class PooledCacheEventQueue<K,V>
java.lang.Object
org.apache.commons.jcs3.engine.AbstractCacheEventQueue<K,V>
org.apache.commons.jcs3.engine.PooledCacheEventQueue<K,V>
- All Implemented Interfaces:
ICacheEventQueue<K,V>
- Direct Known Subclasses:
CacheEventQueue
An event queue is used to propagate ordered cache events to one and only one target listener.
This is a modified version of the experimental version. It uses a PooledExecutor and a BoundedBuffer to queue up events and execute them as threads become available.
The PooledExecutor is static, because presumably these processes will be IO bound, so throwing more than a few threads at them will serve no purpose other than to saturate the IO interface. In light of this, having one thread per region seems unnecessary. This may prove to be false.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.jcs3.engine.AbstractCacheEventQueue
AbstractCacheEventQueue.AbstractCacheEvent, AbstractCacheEventQueue.DisposeEvent, AbstractCacheEventQueue.PutEvent, AbstractCacheEventQueue.RemoveAllEvent, AbstractCacheEventQueue.RemoveEventNested classes/interfaces inherited from interface org.apache.commons.jcs3.engine.behavior.ICacheEventQueue
ICacheEventQueue.QueueType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExecutorServiceThe Thread Pool to execute events with.protected BlockingQueue<Runnable>The Thread Pool queueFields inherited from class org.apache.commons.jcs3.engine.AbstractCacheEventQueue
DEFAULT_WAIT_TO_DIE_MILLIS -
Constructor Summary
ConstructorsConstructorDescriptionPooledCacheEventQueue(ICacheListener<K, V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry, String threadPoolName) Constructor for the CacheEventQueue object -
Method Summary
Modifier and TypeMethodDescriptionprotected ExecutorServicecreatePool(String threadPoolName) Create the thread pool.voiddestroy()Destroy the queue.Return the type of event queue we are using, either single or pooled.Returns the historical and statistical data for an event queue cache.protected voidinitialize(ICacheListener<K, V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry, String threadPoolName) Initializes the queue.booleanisEmpty()If the Queue is using a bounded channel we can determine the size.protected voidput(AbstractCacheEventQueue<K, V>.AbstractCacheEvent event) Adds an event to the queue.intsize()Returns the number of elements in the queue.Methods inherited from class org.apache.commons.jcs3.engine.AbstractCacheEventQueue
addDisposeEvent, addPutEvent, addRemoveAllEvent, addRemoveEvent, getCacheName, getListenerId, getWaitToDieMillis, initialize, isWorking, setWaitToDieMillis, setWorking, toString
-
Field Details
-
pool
The Thread Pool to execute events with. -
queue
The Thread Pool queue
-
-
Constructor Details
-
PooledCacheEventQueue
public PooledCacheEventQueue(ICacheListener<K, V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry, String threadPoolName) Constructor for the CacheEventQueue object- Parameters:
listener-listenerId-cacheName-maxFailure-waitBeforeRetry-threadPoolName-
-
-
Method Details
-
initialize
protected void initialize(ICacheListener<K, V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry, String threadPoolName) Initializes the queue.- Parameters:
listener-listenerId-cacheName-maxFailure-waitBeforeRetry-threadPoolName-
-
createPool
Create the thread pool.- Parameters:
threadPoolName-- Since:
- 3.1
-
getQueueType
Description copied from interface:ICacheEventQueueReturn the type of event queue we are using, either single or pooled.- Returns:
- the queue type
-
destroy
Destroy the queue. Interrupt all threads. -
put
Adds an event to the queue.- Specified by:
putin classAbstractCacheEventQueue<K,V> - Parameters:
event-
-
getStatistics
Description copied from interface:ICacheEventQueueReturns the historical and statistical data for an event queue cache.- Returns:
- IStats
-
isEmpty
If the Queue is using a bounded channel we can determine the size. If it is zero or we can't determine the size, we return true.- Returns:
- whether or not there are items in the queue
-
size
Returns the number of elements in the queue. If the queue cannot determine the size accurately it will return 0.- Returns:
- number of items in the queue.
-