xmlBlaster 2.2.0 API

org.xmlBlaster.util.queue.cache
Class CacheQueueInterceptorPlugin

java.lang.Object
  extended by org.xmlBlaster.util.queue.cache.CacheQueueInterceptorPlugin
All Implemented Interfaces:
I_AdminPlugin, I_AdminQueue, I_AdminUsage, I_Plugin, CacheQueueInterceptorPluginMBean, I_Queue, I_Storage, I_StoragePlugin, I_StorageProblemListener, I_StorageProblemNotifier

public class CacheQueueInterceptorPlugin
extends java.lang.Object
implements I_Queue, I_StoragePlugin, I_StorageProblemListener, CacheQueueInterceptorPluginMBean

Implements a queue cache. Internally it utilizes a RAM queue and a JDBC queue and manages the cache logic.

Author:
michele@laghi.eu, xmlBlaster@marcelruff.info
See Also:
The queue.cache requirement

Field Summary
private  ContextNode contextNode
           
private  Global glob
           
private  boolean isConnected
           
(package private)  boolean isDown
           
private static java.util.logging.Logger log
           
private  long maxFetchSize
           
private  java.lang.Object mbeanHandle
          My JMX registration
private  java.lang.String ME
           
private  boolean notifiedAboutAddOrRemove
           
private  java.lang.Object peekSync
          this is the sync between the peaks and the swapping: no peak should be allowed while swapping
private  I_Queue persistentQueue
           
private  PluginInfo pluginInfo
          object used to control the swapping performance
private  QueuePropertyBase property
           
private  I_QueuePutListener putListener
           
private  StorageId queueId
           
private  StorageSizeListenerHelper storageSizeListenerHelper
           
private  I_Queue transientQueue
           
 
Fields inherited from interface org.xmlBlaster.util.queue.I_Queue
IGNORE_PUT_INTERCEPTOR, USE_PUT_INTERCEPTOR
 
Fields inherited from interface org.xmlBlaster.util.queue.I_StorageProblemListener
AVAILABLE, UNAVAILABLE, UNDEF
 
Constructor Summary
CacheQueueInterceptorPlugin()
           
 
Method Summary
 void addPutListener(I_QueuePutListener l)
          Register a listener which wants to be informed on put() events.
 void addStorageSizeListener(I_StorageSizeListener listener)
          Adds a storage size listener to the storage.
private  long checkEntriesAvailable(I_Queue queue, long valueToCheckAgainst, boolean ifFullThrowException, java.lang.String extraTxt)
           
private  long checkSpaceAvailable(I_Queue queue, long valueToCheckAgainst, boolean ifFullThrowException, java.lang.String extraTxt)
          Helper method to check the space left on a given queue.
 long clear()
          Clears everything and removes the queue (i.e.
private  QueuePropertyBase createRamCopy(QueuePropertyBase queuePropertyBase)
          We set the cache props to the real props for RAM queue running under a cacheQueue
 java.lang.String dumpEmbeddedObjects()
          Currently ONLY PERSISTENT entries are dumped (TODO add transients) Currently PRIORITY is always set to 5 (see ClientEntryFactory#createEntry as ref is null and guessed
 java.lang.String dumpEmbeddedObjectsToFile(java.lang.String fileName)
          Currently ONLY PERSISTENT entries are dumped (TODO add transients) Currently PRIORITY is always set to 5 (see ClientEntryFactory#createEntry as ref is null and guessed
 long embeddedObjectsToXml(java.io.OutputStream out, java.util.Properties props)
          Currently ONLY PERSISTENT entries are dumped (TODO add transients) Currently PRIORITY is always set to 5 (see ClientEntryFactory#createEntry as ref is null and guessed
 long embeddedQueueObjectsToXml(java.io.OutputStream out, java.util.Properties props)
          NOTE: rename from embeddedObjectsToXml to embeddedQueueObjectsToXml as it used the map lookup and lost priority info Dump all entries of this queue to the given output stream.
 java.util.List<I_Entry> getEntries(I_EntryFilter entryFilter)
          Gets a copy of the entries (e.g the messages) in the queue.
 long[] getEntryReferences()
          Gets the references of the entries in the queue.
 PluginInfo getInfo()
          Enforced by I_StoragePlugin
 long getMaxNumOfBytes()
          Access the configured capacity (maximum bytes) for this queue
 long getMaxNumOfEntries()
          Returns the maximum number of elements for this queue
 long getNumOfBytes()
          Returns the amount of bytes currently in the queue.
 long getNumOfEntries()
          It returns the size of the queue.
 long getNumOfPersistentBytes()
          Returns the amount of bytes used by the persistent entries in the queue If the implementation of this interface is not able to return the correct number of entries (for example if the implementation must make a remote call to a DB which is temporarly not available) it will return -1.
 long getNumOfPersistentEntries()
          It returns the size of persistent entries in the queue.
 I_Queue getPersistentQueue()
          returns the persistent queue (null if no one defined)
 java.lang.Object getProperties()
          Access the current queue configuration
 java.lang.String getPropertyStr()
          Access the current queue configuration
 java.lang.String getQueueName()
          Returns the unique ID of this queue as found in the database XB_ENTRIES.queueName column.
 StorageId getStorageId()
          Returns the unique ID of this queue
 I_StorageSizeListener[] getStorageSizeListeners()
           
 I_Queue getTransientQueue()
          returns the transient queue (null if no one defined)
 java.lang.String getType()
          Enforced by I_Plugin
 java.lang.String getUsageUrl()
           
 java.lang.String getVersion()
          Enforced by I_Plugin
 boolean hasStorageSizeListener(I_StorageSizeListener listener)
          Checks wether the specified listener is registered.
private  boolean hasTransientsSwapped()
           
private  boolean hasUncachedEntries()
           
 void init(Global glob, PluginInfo pluginInfo)
          Enforced by I_Plugin
 void initialize(StorageId uniqueQueueId, java.lang.Object userData)
          Is called after the instance is created.
 boolean isNotifiedAboutAddOrRemove()
          Defaults to false.
private  boolean isPersistenceAvailable()
           
 boolean isShutdown()
          Check status
 boolean isTransient()
           
private  int loadFromPersistence()
          Loads from the persistence so much data as it fits into the transient queue.
 I_QueueEntry peek()
          Returns the first element in the queue but does not remove it from that queue (leaves it untouched).
 java.util.List<I_Entry> peek(int numOfEntries, long numOfBytes)
          Returns maximum the first num element in the queue but does not remove it from that queue (leaves it untouched).
 java.lang.String[] peekEntries(int numOfEntries)
          Returns maximum the first num element in the queue but does not remove it from that queue (leaves it untouched).
 java.util.List<I_Entry> peekLowest(int numOfEntries, long numOfBytes, I_QueueEntry limitEntry, boolean leaveOne)
          Aware: peekLowest is not implemented!!
 java.util.List<I_Entry> peekSamePriority(int numOfEntries, long numOfBytes)
          Returns maximum the first num element in the queue of highest priority but does not remove it from that queue (leaves it untouched).
 java.util.List<I_Entry> peekStartAt(int numOfEntries, long numOfBytes, I_QueueEntry firstEntryExlusive)
          Returns maximum the first num element in the queue but does not remove it from that queue (leaves it untouched).
 java.lang.String peekStr()
          Returns the first element in the queue but does not remove it from that queue (leaves it untouched).
 java.util.List<I_Entry> peekWithLimitEntry(I_QueueEntry limitEntry)
          Deprecated.  
 java.util.List<I_Entry> peekWithPriority(int numOfEntries, long numOfBytes, int minPriority, int maxPriority)
          Returns maximum given number of entries from the queue (none blocking).
 void put(I_QueueEntry[] queueEntries, boolean ignorePutInterceptor)
          All entries are stored into the transient queue.
 void put(I_QueueEntry queueEntry, boolean ignorePutInterceptor)
          Puts one queue entry on top of the queue.
 boolean registerStorageProblemListener(I_StorageProblemListener listener)
          registers a new listener to be notified.
 int remove()
          Removes the first element in the queue This method does not block.
 long removeHead(I_QueueEntry toEntry)
          removes the head of the queue until (but not included) the entry specified as the argument.
 long removeNum(long numOfEntries)
          Removes max num messages.
private  boolean[] removePossibleSwappedEntries(boolean[] ret, I_Entry[] queueEntries)
          The given ret array will be updated with the result of the removing from the persistent queue.
 void removePutListener(I_QueuePutListener l)
          Remove the listener which wanted to be informed on put() events.
 int removeRandom(I_Entry entry)
          Removes the given entry.
 boolean[] removeRandom(I_Entry[] queueEntries)
          Removes the given entries.
 int removeRandom(long dataId)
          Removes the given entry.
 long removeRandom(long[] dataIdArray)
          Removes the given entries.
private  boolean[] removeRandomNoNotify(I_Entry[] queueEntries)
           
 void removeStorageSizeListener(I_StorageSizeListener listener)
          Removes the specified listener from the queue.
 int removeTransient()
          Removes all the transient entries (the ones which have the flag 'persistent' set to false.
 long removeWithLimitEntry(I_QueueEntry limitEntry, boolean inclusive)
          It removes the entries which are higher than the entry specified in the argument list.
 long removeWithPriority(long numOfEntries, long numOfBytes, int minPriority, int maxPriority)
          Removes max numOfEntries messages (or less depending on the numOfBytes).
 void setNotifiedAboutAddOrRemove(boolean notify)
           
 void setProperties(java.lang.Object userData)
          Allows to overwrite properties which where passed on initialize() The properties which support hot configuration are depending on the used implementation
 void setUsageUrl(java.lang.String url)
           
 void shutdown()
          Shutdown the implementation, sync with data store
 void storageAvailable(int oldStatus)
          Invoked by the I_StorageProblemNotifier when the storage becomes available again (for example on a DB when the jdbc connection is broken).
 void storageUnavailable(int oldStatus)
          Invoked by the I_StorageProblemNotifier when the storage becomes unavailable (for example on a DB when the jdbc connection is broken).
 java.util.List<I_Entry> takeLowest(int numOfEntries, long numOfBytes, I_QueueEntry limitEntry, boolean leaveOne)
          Aware: takeLowest for more than one entry is not implemented!!
 java.util.List<I_Entry> takeWithPriority(int numOfEntries, long numOfBytes, int minPriority, int maxPriority)
          Takes given number of entries out of the queue.
 java.lang.String toXml()
          Dump state to XML string.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state to XML string.
 boolean unRegisterStorageProblemListener(I_StorageProblemListener listener)
          unregisters a listener.
 int update(I_QueueEntry queueEntry)
          Updates the given message queue entry with a new value.
 java.lang.String usage()
          JMX help
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

ME

private java.lang.String ME

contextNode

private ContextNode contextNode

property

private QueuePropertyBase property

notifiedAboutAddOrRemove

private boolean notifiedAboutAddOrRemove

isDown

boolean isDown

queueId

private StorageId queueId

putListener

private I_QueuePutListener putListener

transientQueue

private I_Queue transientQueue

persistentQueue

private I_Queue persistentQueue

glob

private Global glob

isConnected

private boolean isConnected

pluginInfo

private PluginInfo pluginInfo
object used to control the swapping performance


peekSync

private java.lang.Object peekSync
this is the sync between the peaks and the swapping: no peak should be allowed while swapping


mbeanHandle

private java.lang.Object mbeanHandle
My JMX registration


maxFetchSize

private long maxFetchSize

storageSizeListenerHelper

private StorageSizeListenerHelper storageSizeListenerHelper
Constructor Detail

CacheQueueInterceptorPlugin

public CacheQueueInterceptorPlugin()
Method Detail

isTransient

public boolean isTransient()
Specified by:
isTransient in interface I_AdminQueue
Specified by:
isTransient in interface I_Storage
Returns:
true for RAM based queue, false for other types like CACHE and JDBC queues

checkSpaceAvailable

private final long checkSpaceAvailable(I_Queue queue,
                                       long valueToCheckAgainst,
                                       boolean ifFullThrowException,
                                       java.lang.String extraTxt)
                                throws XmlBlasterException
Helper method to check the space left on a given queue.

Parameters:
queue - the queue on which to calculate the space left.
valueToCheckAgainst - the amount of bytes which are subtracted (needed in the queue) in this check.
ifFullThrowException - if 'true' this method will throw an exception if the return value would be negative
Returns:
long the space left on the specified queue after having occupied the queue with what is specified in 'valueToCheckAgainst'
Throws:
XmlBlasterException - if the 'ifFullThrowException' flag has been set to 'true' and the return value would be negative.

checkEntriesAvailable

private final long checkEntriesAvailable(I_Queue queue,
                                         long valueToCheckAgainst,
                                         boolean ifFullThrowException,
                                         java.lang.String extraTxt)
                                  throws XmlBlasterException
Throws:
XmlBlasterException

storageUnavailable

public void storageUnavailable(int oldStatus)
Description copied from interface: I_StorageProblemListener
Invoked by the I_StorageProblemNotifier when the storage becomes unavailable (for example on a DB when the jdbc connection is broken).

Specified by:
storageUnavailable in interface I_StorageProblemListener
Parameters:
oldStatus - the status before the storage became unavailable.
See Also:
I_StorageProblemListener.storageUnavailable(int)

storageAvailable

public void storageAvailable(int oldStatus)
Description copied from interface: I_StorageProblemListener
Invoked by the I_StorageProblemNotifier when the storage becomes available again (for example on a DB when the jdbc connection is broken). Note that this method is invoked ONLY after the connection has become unavailable, it is NOT invoked the at startup, i.e. the first time the connection becomes available.

Specified by:
storageAvailable in interface I_StorageProblemListener
See Also:
I_StorageProblemListener.storageAvailable(int)

initialize

public void initialize(StorageId uniqueQueueId,
                       java.lang.Object userData)
                throws XmlBlasterException
Is called after the instance is created.

Specified by:
initialize in interface I_Queue
Parameters:
uniqueQueueId - A unique name, allowing to create a unique name for a persistent store (e.g. file name)
userData - For example a Properties object or a String[] args object passing the configuration data
Throws:
XmlBlasterException
See Also:
I_Queue.initialize(StorageId, Object)

createRamCopy

private QueuePropertyBase createRamCopy(QueuePropertyBase queuePropertyBase)
We set the cache props to the real props for RAM queue running under a cacheQueue


setProperties

public void setProperties(java.lang.Object userData)
                   throws XmlBlasterException
Description copied from interface: I_Queue
Allows to overwrite properties which where passed on initialize() The properties which support hot configuration are depending on the used implementation

Specified by:
setProperties in interface I_Queue
Throws:
XmlBlasterException
See Also:
I_Queue.setProperties(Object)

getPropertyStr

public java.lang.String getPropertyStr()
Description copied from interface: I_AdminQueue
Access the current queue configuration

Specified by:
getPropertyStr in interface I_AdminQueue

getProperties

public java.lang.Object getProperties()
Access the current queue configuration

Specified by:
getProperties in interface I_Queue

setNotifiedAboutAddOrRemove

public void setNotifiedAboutAddOrRemove(boolean notify)
Specified by:
setNotifiedAboutAddOrRemove in interface I_Queue

isNotifiedAboutAddOrRemove

public boolean isNotifiedAboutAddOrRemove()
Description copied from interface: I_AdminQueue
Defaults to false.

Specified by:
isNotifiedAboutAddOrRemove in interface I_AdminQueue
Specified by:
isNotifiedAboutAddOrRemove in interface I_Queue
Returns:
true The I_QueueEntry.addedToQueue() and removedFromQueue() are invoked
false The entries are not informed

addPutListener

public void addPutListener(I_QueuePutListener l)
Description copied from interface: I_Queue
Register a listener which wants to be informed on put() events.

Only one listener is currently supported.

Specified by:
addPutListener in interface I_Queue
See Also:
I_Queue.addPutListener(I_QueuePutListener)

removePutListener

public void removePutListener(I_QueuePutListener l)
Description copied from interface: I_Queue
Remove the listener which wanted to be informed on put() events.

The currently registered listener is removed. If no listener is registered, this call is silently ignored

Specified by:
removePutListener in interface I_Queue
See Also:
I_Queue.removePutListener(I_QueuePutListener)

getPersistentQueue

public I_Queue getPersistentQueue()
returns the persistent queue (null if no one defined)


getTransientQueue

public I_Queue getTransientQueue()
returns the transient queue (null if no one defined)


getEntryReferences

public long[] getEntryReferences()
                          throws XmlBlasterException
Gets the references of the entries in the queue. Note that the data which is referenced here may be changed by other threads.

Specified by:
getEntryReferences in interface I_AdminQueue
Specified by:
getEntryReferences in interface I_Queue
Returns:
Array with reference numbers
Throws:
XmlBlasterException

getEntries

public java.util.List<I_Entry> getEntries(I_EntryFilter entryFilter)
                                   throws XmlBlasterException
Description copied from interface: I_Queue
Gets a copy of the entries (e.g the messages) in the queue. If the queue is modified, this copy will not be affected. This method is useful for client browsing, the entries are not removed

Specified by:
getEntries in interface I_Queue
Parameters:
entryFilter - if not null the you can control which entries to return with the callback entryFilter.intercept(I_Entry).
Returns:
The found entries
Throws:
XmlBlasterException
See Also:
I_Queue.getEntries(I_EntryFilter)

put

public void put(I_QueueEntry queueEntry,
                boolean ignorePutInterceptor)
         throws XmlBlasterException
Description copied from interface: I_Queue
Puts one queue entry on top of the queue. See the other put() for a detailed description.

Specified by:
put in interface I_Queue
ignorePutInterceptor - if set to 'IGNORE_PUT_INTERCEPTOR=true' the put will not inform the QueuePutListener that a put occurred.
Throws:
XmlBlasterException - in case an error occurs. Possible causes of error can be a communication exception of the underlying implementation (jdbc, file system etc).
See Also:
I_Queue.put(I_QueueEntry, boolean)

put

public void put(I_QueueEntry[] queueEntries,
                boolean ignorePutInterceptor)
         throws XmlBlasterException
All entries are stored into the transient queue. All persistent messages are stored also in the persistent queue. The exceeding size in the transient queue is calculated. If it is positive it means we need to swap. The overflowing messages are taken from the ram queue. The volatile between them are stored in the persistent storage (since the persistent ones have been previously stored).

Specified by:
put in interface I_Queue
ignorePutInterceptor - if set to 'IGNORE_PUT_INTERCEPTOR=true' the put will not inform the QueuePutListener that a put occurred.
Throws:
XmlBlasterException - in case an error occurs. Possible causes of error can be a communication exception of the underlying implementation (jdbc, file system etc).
See Also:
I_Queue.put(I_QueueEntry[], boolean)

getQueueName

public java.lang.String getQueueName()
Description copied from interface: I_AdminQueue
Returns the unique ID of this queue as found in the database XB_ENTRIES.queueName column.

Specified by:
getQueueName in interface I_AdminQueue
Returns:
For example "history_heronhello"

getStorageId

public StorageId getStorageId()
Returns the unique ID of this queue

Specified by:
getStorageId in interface I_Storage
Returns:
For example "history_heronhello"

takeWithPriority

public java.util.List<I_Entry> takeWithPriority(int numOfEntries,
                                                long numOfBytes,
                                                int minPriority,
                                                int maxPriority)
                                         throws XmlBlasterException
Description copied from interface: I_AdminQueue
Takes given number of entries out of the queue. The ordering is first priority and secondly timestamp. This method blocks until at least one entry is found

Specified by:
takeWithPriority in interface I_AdminQueue
Specified by:
takeWithPriority in interface I_Queue
Parameters:
numOfEntries - Take numOfEntries entries, if -1 take all entries currently found
numOfBytes - so many entries are returned as not to exceed the amount specified. If the first entry is bigger than this amount, it is returned anyway.
minPriority - The lower priority (inclusive), usually 0 lowest, 9 highest
maxPriority - The higher priority (inclusive), usually 0 lowest, 9 highest
Returns:
list with I_QueueEntry, the least elements with respect to the given ordering, or size()==0
Throws:
XmlBlasterException - in case the underlying implementation gets an exception while retrieving the element.
See Also:
I_Queue.takeWithPriority(int,long,int,int)

hasTransientsSwapped

private final boolean hasTransientsSwapped()

isPersistenceAvailable

private final boolean isPersistenceAvailable()

hasUncachedEntries

private final boolean hasUncachedEntries()

peekLowest

public java.util.List<I_Entry> peekLowest(int numOfEntries,
                                          long numOfBytes,
                                          I_QueueEntry limitEntry,
                                          boolean leaveOne)
                                   throws XmlBlasterException
Aware: peekLowest is not implemented!!

Specified by:
peekLowest in interface I_Queue
Throws:
XmlBlasterException
See Also:
I_Queue.peekLowest(int, long, I_QueueEntry, boolean)

takeLowest

public java.util.List<I_Entry> takeLowest(int numOfEntries,
                                          long numOfBytes,
                                          I_QueueEntry limitEntry,
                                          boolean leaveOne)
                                   throws XmlBlasterException
Aware: takeLowest for more than one entry is not implemented!!

Specified by:
takeLowest in interface I_Queue
Parameters:
numOfEntries - inclusive, zero up to numOfEntries, if -1 up to the whole queue
numOfBytes - inclusive, and minimum one is returned (but not if limitEntry suppress it)
leaveOne - Usually set to false. (true for cache queue to never flush transient queue totally)
Returns:
the list containing all 'I_QueueEntry' entries which fit into the constrains, never null.
Throws:
XmlBlasterException
See Also:
I_Queue.takeLowest(int, long, I_QueueEntry, boolean)

peekStr

public java.lang.String peekStr()
                         throws java.lang.Exception
Description copied from interface: I_AdminQueue
Returns the first element in the queue but does not remove it from that queue (leaves it untouched). This method does not block.

Specified by:
peekStr in interface I_AdminQueue
Returns:
I_QueueEntry the least element with respect to the given ordering or null if the queue is empty.
Throws:
java.lang.Exception - if the underlying implementation gets an exception.

peekEntries

public java.lang.String[] peekEntries(int numOfEntries)
                               throws java.lang.Exception
Description copied from interface: I_AdminQueue
Returns maximum the first num element in the queue but does not remove it from that queue (leaves it untouched). This method does not block.

Specified by:
peekEntries in interface I_AdminQueue
Parameters:
numOfEntries - Access num entries, if -1 access all entries currently found
Returns:
list with I_QueueEntry.toString(), the least elements with respect to the given ordering, or size()==0
Throws:
java.lang.Exception - if the underlying implementation gets an exception.

peek

public I_QueueEntry peek()
                  throws XmlBlasterException
Description copied from interface: I_Queue
Returns the first element in the queue but does not remove it from that queue (leaves it untouched). This method does not block.

Specified by:
peek in interface I_Queue
Returns:
I_QueueEntry the least element with respect to the given ordering or null if the queue is empty.
Throws:
XmlBlasterException - if the underlying implementation gets an exception.
See Also:
I_Queue.peek()

peek

public java.util.List<I_Entry> peek(int numOfEntries,
                                    long numOfBytes)
                             throws XmlBlasterException
Description copied from interface: I_Queue
Returns maximum the first num element in the queue but does not remove it from that queue (leaves it untouched). This method does not block.

Specified by:
peek in interface I_Queue
Parameters:
numOfEntries - Access num entries, if -1 access all entries currently found
numOfBytes - is the maximum size in bytes of the array to return, -1 is unlimited .
Returns:
list with I_QueueEntry, the least elements with respect to the given ordering, or size()==0
Throws:
XmlBlasterException - if the underlying implementation gets an exception.
See Also:
I_Queue.peek(int,long)

peekStartAt

public java.util.List<I_Entry> peekStartAt(int numOfEntries,
                                           long numOfBytes,
                                           I_QueueEntry firstEntryExlusive)
                                    throws XmlBlasterException
Description copied from interface: I_Queue
Returns maximum the first num element in the queue but does not remove it from that queue (leaves it untouched). This method does not block.

Specified by:
peekStartAt in interface I_Queue
Parameters:
numOfEntries - Access num entries, if -1 access all entries currently found
numOfBytes - is the maximum size in bytes of the array to return, -1 is unlimited .
Returns:
list with I_QueueEntry, the least elements with respect to the given ordering, or size()==0
Throws:
XmlBlasterException - if the underlying implementation gets an exception.

peekSamePriority

public java.util.List<I_Entry> peekSamePriority(int numOfEntries,
                                                long numOfBytes)
                                         throws XmlBlasterException
Description copied from interface: I_Queue
Returns maximum the first num element in the queue of highest priority but does not remove it from that queue (leaves it untouched). This method does not block.

Specified by:
peekSamePriority in interface I_Queue
Parameters:
numOfEntries - Access num entries, if -1 access all entries currently found
numOfBytes - so many entries are returned as not to exceed the amount specified. If the first entry is bigger than this amount, it is returned anyway. -1 is unlimited.
Returns:
list with I_QueueEntry, the least elements with respect to the given ordering, or size()==0
Throws:
XmlBlasterException - if the underlying implementation gets an exception.
See Also:
I_Queue.peekSamePriority(int, long)

peekWithPriority

public java.util.List<I_Entry> peekWithPriority(int numOfEntries,
                                                long numOfBytes,
                                                int minPriority,
                                                int maxPriority)
                                         throws XmlBlasterException
Description copied from interface: I_Queue
Returns maximum given number of entries from the queue (none blocking).

Specified by:
peekWithPriority in interface I_Queue
Parameters:
numOfEntries - Access num entries, if -1 take all entries currently found
numOfBytes - so many entries are returned as not to exceed the amount specified. If the first entry is bigger than this amount, it is returned anyway.
minPriority - The lower priority (inclusive), usually 0 lowest, 9 highest, <0 is not allowed
maxPriority - The higher priority (inclusive), usually 0 lowest, 9 highest, <0 is not allowed
Returns:
list with I_QueueEntry, the least elements with respect to the given ordering, or size()==0
Throws:
XmlBlasterException - in case the underlying implementation gets an exception while retrieving the element.
See Also:
I_Queue.peekWithPriority(int, long, int, int)

peekWithLimitEntry

public java.util.List<I_Entry> peekWithLimitEntry(I_QueueEntry limitEntry)
                                           throws XmlBlasterException
Deprecated. 

Description copied from interface: I_Queue
It returns the entries which are higher than the entry specified in the argument list.

Specified by:
peekWithLimitEntry in interface I_Queue
Parameters:
limitEntry - the entry which limits the peek. Only entries of higher order, i.e. entries having a higher priority, or same priority and lower uniqueId are returned. If entryLimit is null or no entries are higher than entryLimit, an empty list is returned. Note: The limitEntry does not need to be in the queue.
Throws:
XmlBlasterException
See Also:
I_Queue.peekWithLimitEntry(I_QueueEntry)

removeWithLimitEntry

public long removeWithLimitEntry(I_QueueEntry limitEntry,
                                 boolean inclusive)
                          throws XmlBlasterException
Description copied from interface: I_Queue
It removes the entries which are higher than the entry specified in the argument list.

Specified by:
removeWithLimitEntry in interface I_Queue
Parameters:
limitEntry - the entry which limits the remove. Only entries of higher order, i.e. entries having a higher priority, or same priority and lower uniqueId are deleted. If entryLimit is null or no entries are higher than entryLimit, an empty list is returned.
inclusive - if 'true', then also the entry specified will be removed (if it exists). If false the remove is exclusive, i.e. the specified entry is left in the queue. Note: The limitEntry does not need to be in the queue.
Throws:
XmlBlasterException
See Also:
I_Queue.removeWithLimitEntry(I_QueueEntry, boolean)

remove

public int remove()
           throws XmlBlasterException
Removes the first element in the queue This method does not block.

Specified by:
remove in interface I_AdminQueue
Specified by:
remove in interface I_Queue
Returns:
Number of messages erased (0 or 1)
Throws:
XmlBlasterException - if the underlying implementation gets an exception.

removeNum

public long removeNum(long numOfEntries)
               throws XmlBlasterException
Removes max num messages. This method does not block.

Specified by:
removeNum in interface I_AdminQueue
Specified by:
removeNum in interface I_Queue
Parameters:
num - Erase num entries or less if less entries are available, -1 erases everything
Returns:
Number of entries erased
Throws:
XmlBlasterException - if the underlying implementation gets an exception.

removeRandom

public int removeRandom(long dataId)
                 throws XmlBlasterException
Removes the given entry.

Parameters:
dataId - the unique id. It must be unique within the storage area of the implementing queue. In other words, if the underlying implementation is on RAM, then the storage area is the JVM, that is the queue must be unique in the same JVM. If the queue is a jdbc, the dataId is unique in the DB used.
Throws:
XmlBlasterException

removeRandom

public long removeRandom(long[] dataIdArray)
                  throws XmlBlasterException
Removes the given entries.

Parameters:
msgQueueEntry - the entry to erase.
Throws:
XmlBlasterException

removeRandom

public int removeRandom(I_Entry entry)
                 throws XmlBlasterException
Description copied from interface: I_Queue
Removes the given entry.

Specified by:
removeRandom in interface I_Queue
Parameters:
entry - The entry to erase.
Returns:
the number of elements erased.
Throws:
XmlBlasterException
See Also:
I_Queue.removeRandom(I_Entry)

removePossibleSwappedEntries

private final boolean[] removePossibleSwappedEntries(boolean[] ret,
                                                     I_Entry[] queueEntries)
The given ret array will be updated with the result of the removing from the persistent queue.


removeRandomNoNotify

private final boolean[] removeRandomNoNotify(I_Entry[] queueEntries)
                                      throws XmlBlasterException
Throws:
XmlBlasterException
See Also:
I_Queue.removeRandom(I_Entry[])

removeRandom

public final boolean[] removeRandom(I_Entry[] queueEntries)
                             throws XmlBlasterException
Description copied from interface: I_Queue
Removes the given entries.

Specified by:
removeRandom in interface I_Queue
Parameters:
queueEntries - the entries to erase.
Returns:
a boolean array of the same size as the queueEntries array. If an entry is true it means it could be removed, if false it means it could not be removed (probably already removed)
Throws:
XmlBlasterException
See Also:
I_Queue.removeRandom(I_Entry[])

loadFromPersistence

private final int loadFromPersistence()
                               throws XmlBlasterException
Loads from the persistence so much data as it fits into the transient queue.

Throws:
XmlBlasterException

removeWithPriority

public long removeWithPriority(long numOfEntries,
                               long numOfBytes,
                               int minPriority,
                               int maxPriority)
                        throws XmlBlasterException
Description copied from interface: I_AdminQueue
Removes max numOfEntries messages (or less depending on the numOfBytes). This method does not block.

Specified by:
removeWithPriority in interface I_AdminQueue
Specified by:
removeWithPriority in interface I_Queue
Parameters:
numOfEntries - Erase num entries or less if less entries are available, -1 erases everything
numOfBytes - so many entries are returned as not to exceed the amout specified. If the first entry is bigger than this amount, it is returned anyway.
minPriority - The lower priority (inclusive), usually 0 lowest, 9 highest
maxPriority - The higher priority (inclusive), usually 0 lowest, 9 highest
Returns:
Number of entries erased
Throws:
XmlBlasterException - in case the underlying implementation gets an exception while retrieving the element.
See Also:
I_Queue.removeWithPriority(long, long, int, int)

removeTransient

public int removeTransient()
                    throws XmlBlasterException
Description copied from interface: I_AdminQueue
Removes all the transient entries (the ones which have the flag 'persistent' set to false.

Specified by:
removeTransient in interface I_AdminQueue
Throws:
XmlBlasterException
See Also:
I_Queue#removeTransient()

getNumOfEntries

public long getNumOfEntries()
It returns the size of the queue. Note that this call will return the size stored in cache, i.e. it will NOT make a call to the underlying DB.

Specified by:
getNumOfEntries in interface I_AdminQueue
Specified by:
getNumOfEntries in interface I_Storage
Returns:
int the number of elements currently in the queue
See Also:
I_Storage.getNumOfEntries()

getNumOfPersistentEntries

public long getNumOfPersistentEntries()
It returns the size of persistent entries in the queue. Note that this call will return the size stored in cache, i.e. it will NOT make a call to the underlying DB.

Specified by:
getNumOfPersistentEntries in interface I_AdminQueue
Specified by:
getNumOfPersistentEntries in interface I_Queue
Returns:
int the number of elements currently in the queue
See Also:
I_Queue.getNumOfPersistentEntries()

getMaxNumOfEntries

public long getMaxNumOfEntries()
Description copied from interface: I_AdminQueue
Returns the maximum number of elements for this queue

Specified by:
getMaxNumOfEntries in interface I_AdminQueue
Specified by:
getMaxNumOfEntries in interface I_Storage
Returns:
The maximum number of elements in the queue
See Also:
I_Storage.getMaxNumOfEntries()

getNumOfBytes

public long getNumOfBytes()
Description copied from interface: I_AdminQueue
Returns the amount of bytes currently in the queue. If the implementation of this interface is not able to return the correct number of entries (for example if the implementation must make a remote call to a DB which is temporarly not available) it will return -1.

Specified by:
getNumOfBytes in interface I_AdminQueue
Specified by:
getNumOfBytes in interface I_Storage
Returns:
The amount of bytes currently in the queue
See Also:
I_Storage.getNumOfBytes()

getNumOfPersistentBytes

public long getNumOfPersistentBytes()
Description copied from interface: I_AdminQueue
Returns the amount of bytes used by the persistent entries in the queue If the implementation of this interface is not able to return the correct number of entries (for example if the implementation must make a remote call to a DB which is temporarly not available) it will return -1.

Specified by:
getNumOfPersistentBytes in interface I_AdminQueue
Specified by:
getNumOfPersistentBytes in interface I_Queue
Returns:
The amount of bytes currently in the queue
See Also:
I_Queue.getNumOfPersistentBytes()

getMaxNumOfBytes

public long getMaxNumOfBytes()
Description copied from interface: I_AdminQueue
Access the configured capacity (maximum bytes) for this queue

Specified by:
getMaxNumOfBytes in interface I_AdminQueue
Specified by:
getMaxNumOfBytes in interface I_Queue
Returns:
The maximum capacity for the queue in bytes
See Also:
I_Queue.getMaxNumOfBytes()

update

public int update(I_QueueEntry queueEntry)
           throws XmlBlasterException
Updates the given message queue entry with a new value. Note that this can be used if an entry with the unique id already exists. ?? Does this really make sense here since we need to store history ?? ?? Should we define a switch which can deactivate storage of history ??

Throws:
XmlBlasterException

clear

public long clear()
Clears everything and removes the queue (i.e. frees the associated table) This method is not synchronized because of the callback in remove which must be outside the synchronized.

Specified by:
clear in interface I_AdminQueue
Specified by:
clear in interface I_Queue
Returns:
The number of entries erased

removeHead

public long removeHead(I_QueueEntry toEntry)
                throws XmlBlasterException
Description copied from interface: I_Queue
removes the head of the queue until (but not included) the entry specified as the argument.

Specified by:
removeHead in interface I_Queue
Parameters:
toEntry - the entry until to remove.
Returns:
long the number of entries deleted.
Throws:
XmlBlasterException
See Also:
I_Queue.removeHead(I_QueueEntry)

shutdown

public void shutdown()
Shutdown the implementation, sync with data store

Specified by:
shutdown in interface I_AdminPlugin
Specified by:
shutdown in interface I_AdminQueue
Specified by:
shutdown in interface I_Plugin
Specified by:
shutdown in interface I_Queue

isShutdown

public boolean isShutdown()
Description copied from interface: I_AdminPlugin
Check status

Specified by:
isShutdown in interface I_AdminPlugin
Specified by:
isShutdown in interface I_AdminQueue
Specified by:
isShutdown in interface I_Storage
Returns:
true if down

usage

public java.lang.String usage()
JMX help

Specified by:
usage in interface I_AdminUsage
Specified by:
usage in interface I_Queue
Returns:
a human readable usage help string

getUsageUrl

public java.lang.String getUsageUrl()
Specified by:
getUsageUrl in interface I_AdminUsage
Returns:
A link for JMX usage

setUsageUrl

public void setUsageUrl(java.lang.String url)
Specified by:
setUsageUrl in interface I_AdminUsage

toXml

public final java.lang.String toXml()
Description copied from interface: I_AdminQueue
Dump state to XML string.

Specified by:
toXml in interface I_AdminQueue
Returns:
An xml encoded dump

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Description copied from interface: I_Queue
Dump state to XML string.

Specified by:
toXml in interface I_Queue
Parameters:
extraOffset - Indent the dump with given ASCII blanks
Returns:
Internal state as an XML ASCII string

init

public void init(Global glob,
                 PluginInfo pluginInfo)
Enforced by I_Plugin

Specified by:
init in interface I_Plugin
See Also:
I_Plugin.init(org.xmlBlaster.util.Global, PluginInfo)

getType

public java.lang.String getType()
Enforced by I_Plugin

Specified by:
getType in interface I_AdminPlugin
Specified by:
getType in interface I_Plugin
Returns:
"CACHE"

getVersion

public java.lang.String getVersion()
Enforced by I_Plugin

Specified by:
getVersion in interface I_AdminPlugin
Specified by:
getVersion in interface I_Plugin
Returns:
"1.0"

getInfo

public PluginInfo getInfo()
Enforced by I_StoragePlugin

Specified by:
getInfo in interface I_StoragePlugin
Returns:
the pluginInfo object.

registerStorageProblemListener

public boolean registerStorageProblemListener(I_StorageProblemListener listener)
Description copied from interface: I_StorageProblemNotifier
registers a new listener to be notified. If the registration was not done (for example if the implementation only allows one listener and there is already one), then a 'false' is returned, otherwise 'true' is returned.

Specified by:
registerStorageProblemListener in interface I_StorageProblemNotifier
See Also:
I_StorageProblemNotifier.registerStorageProblemListener(I_StorageProblemListener)

unRegisterStorageProblemListener

public boolean unRegisterStorageProblemListener(I_StorageProblemListener listener)
Description copied from interface: I_StorageProblemNotifier
unregisters a listener. If there is no such listener 'false' is returned, otherwise 'true' is returned.

Specified by:
unRegisterStorageProblemListener in interface I_StorageProblemNotifier
See Also:
I_StorageProblemNotifier.unRegisterStorageProblemListener(I_StorageProblemListener)

addStorageSizeListener

public void addStorageSizeListener(I_StorageSizeListener listener)
Description copied from interface: I_Storage
Adds a storage size listener to the storage. Every time the number of storage entries changes we will fire a changed() event.

The changed() invocation is guaranteed to NOT be in any Queue specific synchronize

You can use this for example to add a threshold warning system.

Specified by:
addStorageSizeListener in interface I_Storage
Parameters:
listener - the listener to be added, adding the same listener multiple times will only remember one and fire once
See Also:
I_Storage.addStorageSizeListener(I_StorageSizeListener)

removeStorageSizeListener

public void removeStorageSizeListener(I_StorageSizeListener listener)
Description copied from interface: I_Storage
Removes the specified listener from the queue.

Specified by:
removeStorageSizeListener in interface I_Storage
Parameters:
listener - the listener to be removed. Currently only one. If you pass null, all queueSizeListeners are removed.
See Also:
I_Storage.removeStorageSizeListener(I_StorageSizeListener)

hasStorageSizeListener

public boolean hasStorageSizeListener(I_StorageSizeListener listener)
Description copied from interface: I_Storage
Checks wether the specified listener is registered.

Specified by:
hasStorageSizeListener in interface I_Storage
Parameters:
listener - the listener to check against. If you pass null it checks if at least one listener exists.
Returns:
true if the specified listener exists, false otherwise. If you passed null in the argument list it returns true if a listener exists.
See Also:
I_Storage.hasStorageSizeListener(I_StorageSizeListener)

getStorageSizeListeners

public I_StorageSizeListener[] getStorageSizeListeners()
Specified by:
getStorageSizeListeners in interface I_Storage
Returns:
the array of storage size listeners for this storage. It never returns null.
See Also:
I_Storage.getStorageSizeListeners()

embeddedQueueObjectsToXml

public long embeddedQueueObjectsToXml(java.io.OutputStream out,
                                      java.util.Properties props)
                               throws java.lang.Exception
Description copied from interface: I_Queue
NOTE: rename from embeddedObjectsToXml to embeddedQueueObjectsToXml as it used the map lookup and lost priority info Dump all entries of this queue to the given output stream. The messages are XML formatted.

Specified by:
embeddedQueueObjectsToXml in interface I_Queue
Parameters:
out - The output stream to dump the entries
props - Configuration properties, not yet specified, just pass null
Returns:
Number of entries dumped
Throws:
java.lang.Exception

embeddedObjectsToXml

public long embeddedObjectsToXml(java.io.OutputStream out,
                                 java.util.Properties props)
                          throws java.lang.Exception
Currently ONLY PERSISTENT entries are dumped (TODO add transients) Currently PRIORITY is always set to 5 (see ClientEntryFactory#createEntry as ref is null and guessed

Throws:
java.lang.Exception
See Also:
I_Queue#embeddedObjectsToXml(OutputStream, Properties)

dumpEmbeddedObjectsToFile

public java.lang.String dumpEmbeddedObjectsToFile(java.lang.String fileName)
                                           throws java.lang.Exception
Currently ONLY PERSISTENT entries are dumped (TODO add transients) Currently PRIORITY is always set to 5 (see ClientEntryFactory#createEntry as ref is null and guessed

Specified by:
dumpEmbeddedObjectsToFile in interface I_AdminQueue
Parameters:
fileName - The file name to dump, may contain a path.
Returns:
Status string
Throws:
java.lang.Exception
See Also:
I_AdminQueue.dumpEmbeddedObjectsToFile(String)

dumpEmbeddedObjects

public java.lang.String dumpEmbeddedObjects()
Currently ONLY PERSISTENT entries are dumped (TODO add transients) Currently PRIORITY is always set to 5 (see ClientEntryFactory#createEntry as ref is null and guessed

Specified by:
dumpEmbeddedObjects in interface I_AdminQueue
Returns:
messages

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.