xmlBlaster 2.1.0 API

org.xmlBlaster.engine.msgstore.ram
Class MapPlugin

java.lang.Object
  extended by org.xmlBlaster.engine.msgstore.ram.MapPlugin
All Implemented Interfaces:
I_Map, I_Plugin, I_Storage, I_StoragePlugin, I_StorageProblemNotifier

public final class MapPlugin
extends java.lang.Object
implements I_Map, I_StoragePlugin

Mapping messages in RAM only. Please refer to I_Map for Javadoc comments.

Author:
xmlBlaster@marcelruff.info
See Also:
I_MapTest

Nested Class Summary
(package private)  class MapPlugin.LruComparator
          Sorts the entries in the the last recent added order (no real LRU).
 
Field Summary
private  Global glob
           
private  boolean isShutdown
           
private static java.util.logging.Logger log
           
private  java.util.Set lruSet
           
private  StorageId mapId
           
private  java.lang.String ME
           
private  long numOfPersistentEntries
           
private  long persistentSizeInBytes
           
private  PluginInfo pluginInfo
           
private  QueuePropertyBase property
           
private  long sizeInBytes
           
private  java.util.Map storage
           
private  StorageSizeListenerHelper storageSizeListenerHelper
           
 
Constructor Summary
MapPlugin()
           
 
Method Summary
 void addStorageSizeListener(I_StorageSizeListener listener)
          Adds a storage size listener to the storage.
 I_MapEntry change(I_MapEntry entry, I_ChangeCallback callback)
           
 I_MapEntry change(long uniqueId, I_ChangeCallback callback)
          This method is threadsafe because it makes a lookup for the updated entry within the synchronization point.
 long clear()
          Delete all entries
 void destroy()
          destroys all the resources associated to this queue.
 long embeddedObjectsToXml(java.io.OutputStream out, java.util.Properties props)
          Dump all entries of this map to the given output stream.
 I_MapEntry get(long uniqueId)
          Lookup entry without removing.
 I_MapEntry[] getAll(I_EntryFilter entryFilter)
          Retrieve all entries in the storage, please take care on memory consumption.
 PluginInfo getInfo()
          Enforced by I_StoragePlugin
 long getMaxNumOfBytes()
          returns the 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 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 getNumOfEntries()
          Returns the number of elements in this 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()
          i
 java.lang.Object getProperties()
          Access the current queue configuration
 StorageId getStorageId()
          Returns the unique ID of this queue.
 I_StorageSizeListener[] getStorageSizeListeners()
           
 java.lang.String getType()
          Enforced by I_Plugin
 java.lang.String getVersion()
          Enforced by I_Plugin
 boolean hasStorageSizeListener(I_StorageSizeListener listener)
          Checks wether the specified listener is registered.
 void init(Global glob, PluginInfo pluginInfo)
          Enforced by I_Plugin
 void initialize(StorageId uniqueMapId, java.lang.Object userData)
          Is called after the instance is created.
 boolean isShutdown()
          Performs what has to be done when the Map Plugin shuts down.
 boolean isTransient()
           
static void main(java.lang.String[] args)
          java org.xmlBlaster.engine.msgstore.ram.MapPlugin
 int put(I_MapEntry entry)
          Adds one entry and automatically increments the reference counter.
 boolean registerStorageProblemListener(I_StorageProblemListener listener)
          registers a new listener to be notified.
 int remove(I_MapEntry mapEntry)
           
 int remove(long uniqueId)
           
 I_MapEntry removeOldest()
          Remove the oldest entry.
 void removeStorageSizeListener(I_StorageSizeListener listener)
          Removes the specified listener from the queue.
 int removeTransient()
           
 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 shutdown()
          Shutdown the implementation, sync with data store, free resources
private  void touch(I_MapEntry entry)
           
 java.lang.String toXml()
           
 java.lang.String toXml(java.lang.String extraOffset)
           
 boolean unRegisterStorageProblemListener(I_StorageProblemListener listener)
          unregisters a listener.
 void updateCounters(I_MapEntry entry)
           
 java.lang.String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

mapId

private StorageId mapId

storage

private java.util.Map storage

lruSet

private java.util.Set lruSet

property

private QueuePropertyBase property

glob

private Global glob

log

private static java.util.logging.Logger log

isShutdown

private boolean isShutdown

sizeInBytes

private long sizeInBytes

persistentSizeInBytes

private long persistentSizeInBytes

numOfPersistentEntries

private long numOfPersistentEntries

pluginInfo

private PluginInfo pluginInfo

storageSizeListenerHelper

private StorageSizeListenerHelper storageSizeListenerHelper
Constructor Detail

MapPlugin

public MapPlugin()
Method Detail

initialize

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

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

setProperties

public void setProperties(java.lang.Object userData)
                   throws XmlBlasterException
Description copied from interface: I_Map
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_Map
Throws:
XmlBlasterException

getProperties

public java.lang.Object getProperties()
Description copied from interface: I_Map
Access the current queue configuration

Specified by:
getProperties in interface I_Map

getStorageId

public final StorageId getStorageId()
Description copied from interface: I_Storage
Returns the unique ID of this queue.

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

isTransient

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

get

public I_MapEntry get(long uniqueId)
               throws XmlBlasterException
Description copied from interface: I_Map
Lookup entry without removing.

Specified by:
get in interface I_Map
Returns:
null if not found
Throws:
XmlBlasterException
See Also:
I_Map.get(long)

touch

private void touch(I_MapEntry entry)

getAll

public I_MapEntry[] getAll(I_EntryFilter entryFilter)
                    throws XmlBlasterException
Description copied from interface: I_Map
Retrieve all entries in the storage, please take care on memory consumption.

Specified by:
getAll in interface I_Map
Parameters:
entryFilter - null to get everything. If specified you can filter by this callback the wanted entries.
Returns:
A current snapshot of all entries
Throws:
XmlBlasterException
See Also:
I_Map#getAll()

put

public int put(I_MapEntry entry)
        throws XmlBlasterException
Description copied from interface: I_Map
Adds one entry and automatically increments the reference counter. Note: If an entry existed already (0 is returned), it is NOT updated in storage

Specified by:
put in interface I_Map
Returns:
Number of new entries added: 0 if entry existed, 1 if new entry added
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_Map.put(I_MapEntry)

remove

public int remove(I_MapEntry mapEntry)
           throws XmlBlasterException
Specified by:
remove in interface I_Map
Returns:
the number of elements erased.
Throws:
XmlBlasterException
See Also:
I_Map.remove(I_MapEntry)

remove

public int remove(long uniqueId)
           throws XmlBlasterException
Specified by:
remove in interface I_Map
Returns:
the number of elements erased.
Throws:
XmlBlasterException
See Also:
I_Map.remove(long)

removeTransient

public int removeTransient()
                    throws XmlBlasterException
Throws:
XmlBlasterException
See Also:
I_Map#removeTransient()

removeOldest

public I_MapEntry removeOldest()
                        throws XmlBlasterException
Description copied from interface: I_Map
Remove the oldest entry. 'Oldest' is defined in the context of the implementation to support an efficient cache, typically it is the LRU (last recent used) entry.

Specified by:
removeOldest in interface I_Map
Returns:
the removed entry
Throws:
XmlBlasterException
See Also:
I_Map.removeOldest()

clear

public long clear()
Description copied from interface: I_Map
Delete all entries

Specified by:
clear in interface I_Map
Returns:
Number of entries removed

getNumOfEntries

public long getNumOfEntries()
Description copied from interface: I_Storage
Returns the number of elements in this 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 temporary not available) it will return -1.

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

getMaxNumOfEntries

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

Specified by:
getMaxNumOfEntries in interface I_Storage
Returns:
The maximum number of elements in the queue

getNumOfPersistentEntries

public long getNumOfPersistentEntries()
i

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

getNumOfBytes

public long getNumOfBytes()
Description copied from interface: I_Storage
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_Storage
Returns:
The number of elements currently in the queue
See Also:
I_Storage.getNumOfBytes()

getNumOfPersistentBytes

public long getNumOfPersistentBytes()
Description copied from interface: I_Map
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_Map
Returns:
int the number of elements currently in the queue
See Also:
I_Map.getNumOfPersistentBytes()

getMaxNumOfBytes

public final long getMaxNumOfBytes()
Description copied from interface: I_Map
returns the capacity (maximum bytes) for this queue

Specified by:
getMaxNumOfBytes in interface I_Map
Returns:
int the maximum number of elements in the queue
See Also:
I_Map.getMaxNumOfBytes()

shutdown

public final void shutdown()
Description copied from interface: I_Map
Shutdown the implementation, sync with data store, free resources

Specified by:
shutdown in interface I_Map
Specified by:
shutdown in interface I_Plugin

isShutdown

public final boolean isShutdown()
Description copied from interface: I_Storage
Performs what has to be done when the Map Plugin shuts down.

Specified by:
isShutdown in interface I_Storage

destroy

public void destroy()
             throws XmlBlasterException
Description copied from interface: I_Map
destroys all the resources associated to this queue. This means that all temporary and persistent resources are removed.

Specified by:
destroy in interface I_Map
Throws:
XmlBlasterException

usage

public java.lang.String usage()
Specified by:
usage in interface I_Map
Returns:
a human readable usage help string

toXml

public final java.lang.String toXml()

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Specified by:
toXml in interface I_Map
Parameters:
extraOffset - Indent the dump with given ASCII blanks
Returns:
An xml encoded dump

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_Plugin
Returns:
"RAM"

getVersion

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

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)

change

public I_MapEntry change(I_MapEntry entry,
                         I_ChangeCallback callback)
                  throws XmlBlasterException
Specified by:
change in interface I_Map
Parameters:
entry - the entry to change. This is the old entry, i.e. the entry on which the modification has to take place by callback. Or it is the new entry and you can pass null for callback. IMPORTANT: This method is not threadsafe since it does not make a lookup to get the actual entry. The specified entry could be a dirty read, in which case the current entry would be overwritten with this dirty value. If you want to work threadsafe you should invoke change(long, callback). That method makes a lookup within the same synchronization point.
callback - the object on which the callback method 'changeEntry' is invoked. The modification of the object is done in that method. If you pass null, then the changeEntry is not invoked and the processing continues with entry.
Returns:
I_MapEntry the modified entry.
Throws:
XmlBlasterException - if something goes wrong when making the change (for example if the entry is not in the map) or if the callback throws an exception.
See Also:
I_Map.change(I_MapEntry, I_ChangeCallback)

updateCounters

public void updateCounters(I_MapEntry entry)
                    throws XmlBlasterException
Specified by:
updateCounters in interface I_Map
Parameters:
entry - the entry to change. This is the old entry, i.e. the entry on which the modification has to take place by callback. Or it is the new entry and you can pass null for callback. IMPORTANT: This method is not threadsafe since it does not make a lookup to get the actual entry. The specified entry could be a dirty read, in which case the current entry would be overwritten with this dirty value. If you want to work threadsafe you should invoke change(long, callback). That method makes a lookup within the same synchronization point.
Throws:
XmlBlasterException - if something goes wrong when making the change (for example if the entry is not in the map) or if the callback throws an exception.
See Also:
I_Map.change(I_MapEntry, I_ChangeCallback)

change

public I_MapEntry change(long uniqueId,
                         I_ChangeCallback callback)
                  throws XmlBlasterException
Description copied from interface: I_Map
This method is threadsafe because it makes a lookup for the updated entry within the synchronization point.

Specified by:
change in interface I_Map
Parameters:
uniqueId - the uniqueId of the entry to change. This is the old entry, i.e. the entry on which the modification has to take place.
callback - the object on which the callback method 'changeEntry' is invoked. The modification of the object is done in that method. If you pass null, then the changeEntry is not invoked and the processing continues with entry.
Returns:
I_Entry the modified entry.
Throws:
XmlBlasterException - if something goes wrong when making the change (for example if the entry is not in the map) or if the callback throws an exception.
See Also:
I_Map.change(long, I_ChangeCallback)

embeddedObjectsToXml

public long embeddedObjectsToXml(java.io.OutputStream out,
                                 java.util.Properties props)
Description copied from interface: I_Map
Dump all entries of this map to the given output stream. The messages are XML formatted.

Specified by:
embeddedObjectsToXml in interface I_Map
Parameters:
out - The output stream to dump the entries
props - Configuration properties, not yet specified, just pass null
Returns:
Number of entries dumped
See Also:
I_Map.embeddedObjectsToXml(OutputStream, Properties)

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()

main

public static void main(java.lang.String[] args)
java org.xmlBlaster.engine.msgstore.ram.MapPlugin


xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.