Package org.jivesoftware.util.cache
Class DefaultLocalCacheStrategy
- java.lang.Object
-
- org.jivesoftware.util.cache.DefaultLocalCacheStrategy
-
- All Implemented Interfaces:
CacheFactoryStrategy
public class DefaultLocalCacheStrategy extends Object implements CacheFactoryStrategy
CacheFactoryStrategy for use in Openfire. It creates and manages local caches, and it's cluster related method implementations do nothing.- See Also:
Cache,CacheFactory
-
-
Constructor Summary
Constructors Constructor Description DefaultLocalCacheStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CachecreateCache(String name)Creates a new cache for the cache name specified.voiddestroyCache(Cache cache)Destroys the supplied cache.voiddoClusterTask(ClusterTask task)Invokes a task on other cluster members in an asynchronous fashion.voiddoClusterTask(ClusterTask task, byte[] nodeID)Invokes a task on other the specified cluster member in an asynchronous fashion.Collection<Object>doSynchronousClusterTask(ClusterTask task, boolean includeLocalMember)Invokes a task on other cluster members synchronously and returns the result as a Collection (method will not return until the task has been executed on each cluster member).ObjectdoSynchronousClusterTask(ClusterTask task, byte[] nodeID)Invokes a task on a given cluster member synchronously and returns the result of the remote operation.byte[]getClusterMemberID()Returns a byte[] that uniquely identifies this member within the cluster ornullwhen not in a cluster.ClusterNodeInfogetClusterNodeInfo(byte[] nodeID)Returns the node info for the given cluster nodeCollection<ClusterNodeInfo>getClusterNodesInfo()Returns basic information about the current members of the cluster or an empty collection if not running in a cluster.longgetClusterTime()Gets the pseudo-synchronized time from the cluster.LockgetLock(Object key, Cache cache)Returns an existing lock on the specified key or creates a new one if none was found.intgetMaxClusterNodes()Returns the maximum number of cluster members allowed.StringgetPluginName()Get the plugin name corresponding to this clustering implementationbyte[]getSeniorClusterMemberID()Returns a byte[] that uniquely identifies this senior cluster member ornullwhen not in a cluster.booleanisSeniorClusterMember()Returns true if this node is the maste node of the cluster.booleanstartCluster()Returns true if the cluster has been started.voidstopCluster()Stops the cluster.voidupdateCacheStats(Map<String,Cache> caches)Updates the statistics of the specified caches and publishes them into a cache for statistics.
-
-
-
Method Detail
-
startCluster
public boolean startCluster()
Description copied from interface:CacheFactoryStrategyReturns true if the cluster has been started. When running in local mode a true value should be returned.An error should be logged when the cluster fails to be started.
- Specified by:
startClusterin interfaceCacheFactoryStrategy- Returns:
- true if the cluster has been started.
-
stopCluster
public void stopCluster()
Description copied from interface:CacheFactoryStrategyStops the cluster. When not running in a cluster this request will be ignored.- Specified by:
stopClusterin interfaceCacheFactoryStrategy
-
createCache
public Cache createCache(String name)
Description copied from interface:CacheFactoryStrategyCreates a new cache for the cache name specified. The created cache is already configured. Different implementations could store the cache configuration in different ways. It is recommended to store the cache configuration in an external file so it is easier for customers to change the default configuration.- Specified by:
createCachein interfaceCacheFactoryStrategy- Parameters:
name- name of the cache to create.- Returns:
- newly created and configured cache.
-
destroyCache
public void destroyCache(Cache cache)
Description copied from interface:CacheFactoryStrategyDestroys the supplied cache.- Specified by:
destroyCachein interfaceCacheFactoryStrategy- Parameters:
cache- the cache to destroy.
-
isSeniorClusterMember
public boolean isSeniorClusterMember()
Description copied from interface:CacheFactoryStrategyReturns true if this node is the maste node of the cluster. When not running in cluster mode a value of true should be returned.- Specified by:
isSeniorClusterMemberin interfaceCacheFactoryStrategy- Returns:
- true if this node is the maste node of the cluster.
-
getClusterNodesInfo
public Collection<ClusterNodeInfo> getClusterNodesInfo()
Description copied from interface:CacheFactoryStrategyReturns basic information about the current members of the cluster or an empty collection if not running in a cluster.- Specified by:
getClusterNodesInfoin interfaceCacheFactoryStrategy- Returns:
- information about the current members of the cluster or an empty collection if not running in a cluster.
-
getMaxClusterNodes
public int getMaxClusterNodes()
Description copied from interface:CacheFactoryStrategyReturns the maximum number of cluster members allowed. A value of 0 will be returned when clustering is not allowed.- Specified by:
getMaxClusterNodesin interfaceCacheFactoryStrategy- Returns:
- the maximum number of cluster members allowed or 0 if clustering is not allowed.
-
getSeniorClusterMemberID
public byte[] getSeniorClusterMemberID()
Description copied from interface:CacheFactoryStrategyReturns a byte[] that uniquely identifies this senior cluster member ornullwhen not in a cluster.- Specified by:
getSeniorClusterMemberIDin interfaceCacheFactoryStrategy- Returns:
- a byte[] that uniquely identifies this senior cluster member or null when not in a cluster.
-
getClusterMemberID
public byte[] getClusterMemberID()
Description copied from interface:CacheFactoryStrategyReturns a byte[] that uniquely identifies this member within the cluster ornullwhen not in a cluster.- Specified by:
getClusterMemberIDin interfaceCacheFactoryStrategy- Returns:
- a byte[] that uniquely identifies this member within the cluster or null when not in a cluster.
-
getClusterTime
public long getClusterTime()
Description copied from interface:CacheFactoryStrategyGets the pseudo-synchronized time from the cluster. While the cluster members may have varying system times, this method is expected to return a timestamp that is synchronized (or nearly so; best effort) across the cluster.- Specified by:
getClusterTimein interfaceCacheFactoryStrategy- Returns:
- Synchronized time for all cluster members
-
doClusterTask
public void doClusterTask(ClusterTask task)
Description copied from interface:CacheFactoryStrategyInvokes a task on other cluster members in an asynchronous fashion. The task will not be executed on the local cluster member. If clustering is not enabled, this method will do nothing.- Specified by:
doClusterTaskin interfaceCacheFactoryStrategy- Parameters:
task- the task to be invoked on all other cluster members.
-
doClusterTask
public void doClusterTask(ClusterTask task, byte[] nodeID)
Description copied from interface:CacheFactoryStrategyInvokes a task on other the specified cluster member in an asynchronous fashion. If clustering is not enabled, this method will do nothing.- Specified by:
doClusterTaskin interfaceCacheFactoryStrategy- Parameters:
task- the task to be invoked on the specified cluster member.nodeID- the byte array that identifies the target cluster member.
-
doSynchronousClusterTask
public Collection<Object> doSynchronousClusterTask(ClusterTask task, boolean includeLocalMember)
Description copied from interface:CacheFactoryStrategyInvokes a task on other cluster members synchronously and returns the result as a Collection (method will not return until the task has been executed on each cluster member). The task will not be executed on the local cluster member. If clustering is not enabled, this method will return an empty collection.- Specified by:
doSynchronousClusterTaskin interfaceCacheFactoryStrategy- Parameters:
task- the ClusterTask object to be invoked on all other cluster members.includeLocalMember- true to run the task on the local member, false otherwise- Returns:
- collection with the result of the execution.
-
doSynchronousClusterTask
public Object doSynchronousClusterTask(ClusterTask task, byte[] nodeID)
Description copied from interface:CacheFactoryStrategyInvokes a task on a given cluster member synchronously and returns the result of the remote operation. If clustering is not enabled, this method will return null.- Specified by:
doSynchronousClusterTaskin interfaceCacheFactoryStrategy- Parameters:
task- the ClusterTask object to be invoked on a given cluster member.nodeID- the byte array that identifies the target cluster member.- Returns:
- result of remote operation or null if operation failed or operation returned null.
-
updateCacheStats
public void updateCacheStats(Map<String,Cache> caches)
Description copied from interface:CacheFactoryStrategyUpdates the statistics of the specified caches and publishes them into a cache for statistics. The statistics cache is already known to the application but this could change in the future (?). When not in cluster mode then do nothing.The statistics cache must contain a long array of 5 positions for each cache with the following content:
- cache.getCacheSize()
- cache.getMaxCacheSize()
- cache.size()
- cache.getCacheHits()
- cache.getCacheMisses()
- Specified by:
updateCacheStatsin interfaceCacheFactoryStrategy- Parameters:
caches- caches to get their stats and publish them in a statistics cache.
-
getPluginName
public String getPluginName()
Description copied from interface:CacheFactoryStrategyGet the plugin name corresponding to this clustering implementation- Specified by:
getPluginNamein interfaceCacheFactoryStrategy- Returns:
- the plugin name for this clustering implementation
-
getLock
public Lock getLock(Object key, Cache cache)
Description copied from interface:CacheFactoryStrategyReturns an existing lock on the specified key or creates a new one if none was found. This operation is thread safe. The supplied cache may or may not be used depending whether the server is running on cluster mode or not. When not running as part of a cluster then the lock will be unrelated to the cache and will only be visible in this JVM.- Specified by:
getLockin interfaceCacheFactoryStrategy- Parameters:
key- the object that defines the visibility or scope of the lock.cache- the cache used for holding the lock.- Returns:
- an existing lock on the specified key or creates a new one if none was found.
-
getClusterNodeInfo
public ClusterNodeInfo getClusterNodeInfo(byte[] nodeID)
Description copied from interface:CacheFactoryStrategyReturns the node info for the given cluster node- Specified by:
getClusterNodeInfoin interfaceCacheFactoryStrategy- Parameters:
nodeID- The target cluster node- Returns:
- The info for the cluster node, or null if not found
-
-