com.ibm.websphere.cache
Interface DistributedMap

All Superinterfaces:
java.util.Map

public interface DistributedMap
extends java.util.Map

This class provides applications with an extended java.util.Map interface to access the WebSphere Dynamic Cache, allowing inspection and manipulation of the cache. The cache does not have any authorization checking done before allowing access to its contents, so care should be taken on the type of data that is placed in the cache. The default WebSphere Dynamic Cache instance is created when the cache is enabled in the administration console and is bound into the global JNDI namespace with the name "services/cache/distributedmap". Additional cache instances can be created using a properties file distributedmap.properties with the following format:

cache.instance.0=/services/cache/instance_one cache.instance.0.cacheSize=1000 cache.instance.0.enableDiskOffload=true cache.instance.0.diskOffloadLocation=${WAS_INSTALL_ROOT}/instance_name cache.instance.1=/services/cache/instance_two cache.instance.1.cache_size=1500 cache.instance.1.disk_offload=true cache.instance.1.disk_offload_location=${CACHE_INSTANCE2_DIR} The distributedmap.properties file must be located in either you application server or application's classpath. In future versions of WebSphere, the cache instances will be configured via the administration console. The first entry in the properties file (cache.instance.0) specifies the JNDI name for the cache instance in the global namespace. You could then lookup the cache instance using the following code: InitialContext ic = new InitialContext(); DistributedMap dm =(DistributedMap)ic.lookup("services/cache/instance_one"); Alternatively, you can define a resource-ref for in cache in your module's deployement descriptor and then lookup the cache using the java:comp namespace. <resource-ref> <res-ref-name>dmap/LayoutCache</res-ref-name> <res-type>com.ibm.websphere.cache.DistributedMap</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> An example of looking up the resource-ref: InitialContext ic = new InitialContext(); DistributedMap dm =(DistributedMap)ic.lookup("java:comp/env/dmap/LayoutCache");


Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Method Summary
 boolean addChangeListener(ChangeListener listener)
          addChangeListener - adds a change listener for this DistributedMap.
 boolean addInvalidationListener(InvalidationListener listener)
          addInvalidationListener - adds an invalidation listener for this DistributeMap.
 boolean enableListener(boolean enable)
          enableListener - enable or disable the invalidation and change listener support.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 int getSharingPolicy()
          getSharingPolicy - gets the sharing policy for DistributedMap.
 void invalidate(java.lang.Object key)
          invalidate - invalidates the given key.
 void invalidate(java.lang.Object key, boolean wait)
          invalidate - invalidates the given key.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map (optional operation).
 java.lang.Object put(java.lang.Object key, java.lang.Object value, int priority, int timeToLive, int sharingPolicy, java.lang.Object[] dependencyIds)
          Associates the specified value with the specified key in this map (optional operation).
 boolean removeChangeListener(ChangeListener listener)
          removeChangeListener - removes a change listener for this DistributedMap.
 boolean removeInvalidationListener(InvalidationListener listener)
          removeInvalidationListener - removes an invalidation listener for this DistributedMap.
 void setSharingPolicy(int sharingPolicy)
          setSharingPolicy - sets the sharing policy for DistributedMap.
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Method Detail

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Specified by:
get in interface java.util.Map
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
Throws:
java.lang.ClassCastException - if the key is not of an inappropriate type for this map. (Currently supports only String)
java.lang.NullPointerException - key is null and this map does not not permit null keys.
See Also:
Map.containsKey(Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced. This method will use optional metadata looked up from the cache configuration file. If no meta data is found, the entrie is cached with an infinite timeout and the cache's default priority. Metadata found in the cache configuration is looked up via class name and includes priority, timeout, and dependency ids.

Specified by:
put in interface java.util.Map
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
java.lang.UnsupportedOperationException - if the put operation is not supported by this map.
java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
java.lang.NullPointerException - this map does not permit null keys or values, and the specified key or value is null.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value,
                            int priority,
                            int timeToLive,
                            int sharingPolicy,
                            java.lang.Object[] dependencyIds)
Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced.

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
priority - the priority value for the cache entry. entries with higher priority will remain in the cache longer than those with a lower priority in the case of cache overflow.
timeToLive - the time in seconds that the cache entry should remain in the cache
sharingPolicy - how the cache entry should be shared in a cluster. values are EntryInfo.NOT_SHARED, EntryInfo.SHARED_PUSH, EntryInfo.SHARED_PULL, and EntryInfo.SHARED_PUSH_PULL
dependencyIds - an optional set of dependency ids to associate with the cache entry
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
java.lang.UnsupportedOperationException - if the put operation is not supported by this map.
java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
java.lang.NullPointerException - this map does not permit null keys or values, and the specified key or value is null.

setSharingPolicy

public void setSharingPolicy(int sharingPolicy)
setSharingPolicy - sets the sharing policy for DistributedMap.

Parameters:
sharingPolicy - policy to set. Default is EntryInfo.NOT_SHARED
See Also:
getSharingPolicy()

getSharingPolicy

public int getSharingPolicy()
getSharingPolicy - gets the sharing policy for DistributedMap.

Returns:
returns the current sharing policy of DistributedMap.
See Also:
setSharingPolicy(int)

invalidate

public void invalidate(java.lang.Object key)
invalidate - invalidates the given key. If the key is for a specific cache entry, then only that object is invalidated. If the key is for a dependency id, then all objects that share that dependency id will be invalidated.

Parameters:
key - the key which will be invalidated
See Also:
Map.remove(Object key)

invalidate

public void invalidate(java.lang.Object key,
                       boolean wait)
invalidate - invalidates the given key. If the key is for a specific cache entry, then only that object is invalidated. If the key is for a dependency id, then all objects that share that dependency id will be invalidated.

Parameters:
key - the key which will be invalidated
wait - if true, then the method will not complete until the invalidation has occured. if false, then the invalidation will occur in batch mode
See Also:
Map.remove(Object key)

enableListener

public boolean enableListener(boolean enable)
enableListener - enable or disable the invalidation and change listener support. You must call enableListener(true) before calling addInvalidationListner() or addChangeListener().

Parameters:
enable - - true to enable support for invalidation and change listeners or false to disable support for invalidation and change listeners
Returns:
boolean "true" means listener support was successfully enabled or disabled. "false" means this DistributedMap is configurated to use the listener's J2EE context for event notification and the callback registration failed. In this case, the caller's thread context will be used for event notification.

addInvalidationListener

public boolean addInvalidationListener(InvalidationListener listener)
addInvalidationListener - adds an invalidation listener for this DistributeMap.

Parameters:
listener - the invalidation listener object
Returns:
boolean "true" means the invalidation listener was successfully added. "false" means either the passed listener object is null or listener support is not enable.
See Also:
removeInvalidationListener(com.ibm.websphere.cache.InvalidationListener)

removeInvalidationListener

public boolean removeInvalidationListener(InvalidationListener listener)
removeInvalidationListener - removes an invalidation listener for this DistributedMap.

Parameters:
listener - the invalidation listener object
Returns:
boolean "true" means the invalidation listener was successfully removed. "false" means either passed listener object is null or listener support is not enable.
See Also:
addInvalidationListener(com.ibm.websphere.cache.InvalidationListener)

addChangeListener

public boolean addChangeListener(ChangeListener listener)
addChangeListener - adds a change listener for this DistributedMap.

Parameters:
listener - the change listener object
Returns:
boolean "true" means the change listener was successfully added. "false" means either the passed listener object is null or listener support is not enable.
See Also:
removeChangeListener(com.ibm.websphere.cache.ChangeListener)

removeChangeListener

public boolean removeChangeListener(ChangeListener listener)
removeChangeListener - removes a change listener for this DistributedMap.

Parameters:
listener - the change listener object
Returns:
boolean "true" means the change listener was successfully removed. "false" means either passed listener object is null or listener support is not enable.
See Also:
addChangeListener(com.ibm.websphere.cache.ChangeListener)