org.apache.jcs.engine
Class CacheEventQueue<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by org.apache.jcs.engine.AbstractCacheEventQueue<K,V>
      extended by org.apache.jcs.engine.CacheEventQueue<K,V>
All Implemented Interfaces:
ICacheEventQueue<K,V>

public class CacheEventQueue<K extends Serializable,V extends Serializable>
extends AbstractCacheEventQueue<K,V>

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 should lazy initialize the processor thread, and kill the thread if the queue goes empty for a specified period, now set to 1 minute. If something comes in after that a new processor thread should be created.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.jcs.engine.AbstractCacheEventQueue
AbstractCacheEventQueue.AbstractCacheEvent, AbstractCacheEventQueue.DisposeEvent, AbstractCacheEventQueue.Node, AbstractCacheEventQueue.PutEvent, AbstractCacheEventQueue.RemoveAllEvent, AbstractCacheEventQueue.RemoveEvent
 
Field Summary
protected  Object queueLock
          sync
 
Fields inherited from class org.apache.jcs.engine.AbstractCacheEventQueue
cacheName, DEFAULT_WAIT_TO_DIE_MILLIS, destroyed, listener, listenerId, log, maxFailure, waitBeforeRetry, waitToDieMillis, working
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheEventQueue
POOLED_QUEUE_TYPE, SINGLE_QUEUE_TYPE
 
Constructor Summary
CacheEventQueue(ICacheListener<K,V> listener, long listenerId, String cacheName)
          Constructs with the specified listener and the cache name.
CacheEventQueue(ICacheListener<K,V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry)
          Constructor for the CacheEventQueue object
 
Method Summary
 void destroy()
          Event Q is empty.
 String getQueueType()
          What type of queue is this.
 IStats getStatistics()
          This method returns semi-structured data on this queue.
 void initialize(ICacheListener<K,V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry, String threadPoolName)
          Initializes the queue.
 boolean isEmpty()
          Are there elements in the queue.
protected  void put(AbstractCacheEventQueue.AbstractCacheEvent event)
          Adds an event to the queue.
 int size()
          Returns the number of elements in the queue.
 void stopProcessing()
          Kill the processor thread and indicate that the queue is destroyed and no longer alive, but it can still be working.
protected  AbstractCacheEventQueue.AbstractCacheEvent take()
          Returns the next cache event from the queue or null if there are no events in the queue.
 
Methods inherited from class org.apache.jcs.engine.AbstractCacheEventQueue
addDisposeEvent, addPutEvent, addRemoveAllEvent, addRemoveEvent, getListenerId, getWaitToDieMillis, isAlive, isWorking, setAlive, setWaitToDieMillis, setWorking, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

queueLock

protected final Object queueLock
sync

Constructor Detail

CacheEventQueue

public CacheEventQueue(ICacheListener<K,V> listener,
                       long listenerId,
                       String cacheName)
Constructs with the specified listener and the cache name.

Parameters:
listener -
listenerId -
cacheName -

CacheEventQueue

public CacheEventQueue(ICacheListener<K,V> listener,
                       long listenerId,
                       String cacheName,
                       int maxFailure,
                       int waitBeforeRetry)
Constructor for the CacheEventQueue object

Parameters:
listener -
listenerId -
cacheName -
maxFailure -
waitBeforeRetry -
Method Detail

initialize

public 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 -

getQueueType

public String getQueueType()
What type of queue is this.

Returns:
queueType

stopProcessing

public void stopProcessing()
Kill the processor thread and indicate that the queue is destroyed and no longer alive, but it can still be working.


destroy

public void destroy()
Event Q is empty.

Calling destroy interrupts the processor thread.


put

protected void put(AbstractCacheEventQueue.AbstractCacheEvent event)
Adds an event to the queue.

Specified by:
put in class AbstractCacheEventQueue<K extends Serializable,V extends Serializable>
Parameters:
event -

take

protected AbstractCacheEventQueue.AbstractCacheEvent take()
Returns the next cache event from the queue or null if there are no events in the queue.

We have an empty node at the head and the tail. When we take an item from the queue we move the next node to the head and then clear the value from that node. This value is returned.

When the queue is empty the head node is the same as the tail node.

Returns:
An event to process.

getStatistics

public IStats getStatistics()
This method returns semi-structured data on this queue.

Returns:
information on the status and history of the queue
See Also:
ICacheEventQueue.getStatistics()

isEmpty

public boolean isEmpty()
Description copied from interface: ICacheEventQueue
Are there elements in the queue.

Returns:
whether there are any items in the queue.

size

public int size()
Returns the number of elements in the queue.

Returns:
number of items in the queue.


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.