Interface CacheFactoryStrategy

All Known Implementing Classes:
DefaultLocalCacheStrategy

public interface CacheFactoryStrategy
Implementation of CacheFactory that relies on the specific clustering solution.
Author:
Gaston Dombiak
  • Method Details

    • startCluster

      boolean startCluster()
      Returns 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.

      Returns:
      true if the cluster has been started.
    • stopCluster

      void stopCluster()
      Stops the cluster. When not running in a cluster this request will be ignored.
    • createCache

      Cache createCache(String name)
      Creates 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.
      Parameters:
      name - name of the cache to create.
      Returns:
      newly created and configured cache.
    • destroyCache

      void destroyCache(Cache cache)
      Destroys the supplied cache.
      Parameters:
      cache - the cache to destroy.
    • isSeniorClusterMember

      boolean isSeniorClusterMember()
      Returns true if this node is the master node of the cluster. When not running in cluster mode a value of true should be returned.
      Returns:
      true if this node is the master node of the cluster.
    • getClusterNodesInfo

      Collection<ClusterNodeInfo> getClusterNodesInfo()
      Returns basic information about the current members of the cluster or an empty collection if not running in a cluster.
      Returns:
      information about the current members of the cluster or an empty collection if not running in a cluster.
    • getMaxClusterNodes

      int getMaxClusterNodes()
      Returns the maximum number of cluster members allowed. A value of 0 will be returned when clustering is not allowed.
      Returns:
      the maximum number of cluster members allowed or 0 if clustering is not allowed.
    • getSeniorClusterMemberID

      byte[] getSeniorClusterMemberID()
      Returns a byte[] that uniquely identifies this senior cluster member or null when not in a cluster.
      Returns:
      a byte[] that uniquely identifies this senior cluster member or null when not in a cluster.
    • getClusterMemberID

      byte[] getClusterMemberID()
      Returns a byte[] that uniquely identifies this member within the cluster or null when not in a cluster.
      Returns:
      a byte[] that uniquely identifies this member within the cluster or null when not in a cluster.
    • getClusterTime

      long getClusterTime()
      Gets 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.
      Returns:
      Synchronized time for all cluster members
    • doClusterTask

      void doClusterTask(ClusterTask<?> task)
      Invokes 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.
      Parameters:
      task - the task to be invoked on all other cluster members.
    • doClusterTask

      void doClusterTask(ClusterTask<?> task, byte[] nodeID)
      Invokes a task on other the specified cluster member in an asynchronous fashion. If clustering is not enabled, this method will do nothing.
      Parameters:
      task - the task to be invoked on the specified cluster member.
      nodeID - the byte array that identifies the target cluster member.
      Throws:
      IllegalStateException - if requested node was not found.
    • doSynchronousClusterTask

      <T> Collection<T> doSynchronousClusterTask(ClusterTask<T> 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). The task will not be executed on the local cluster member. If clustering is not enabled, this method will return an empty collection.
      Type Parameters:
      T - the return type of the cluster task
      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

      <T> T doSynchronousClusterTask(ClusterTask<T> task, byte[] nodeID)
      Invokes 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.
      Type Parameters:
      T - the return type of the cluster task
      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.
      Throws:
      IllegalStateException - if requested node was not found.
    • updateCacheStats

      void updateCacheStats(Map<String,Cache> caches)
      Updates 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:

      1. cache.getCacheSize()
      2. cache.getMaxCacheSize()
      3. cache.size()
      4. cache.getCacheHits()
      5. cache.getCacheMisses()
      Parameters:
      caches - caches to get their stats and publish them in a statistics cache.
    • getPluginName

      String getPluginName()
      Get the plugin name corresponding to this clustering implementation
      Returns:
      the plugin name for this clustering implementation
    • getClusterNodeInfo

      ClusterNodeInfo getClusterNodeInfo(byte[] nodeID)
      Returns the node info for the given cluster node
      Parameters:
      nodeID - The target cluster node
      Returns:
      The info for the cluster node, or null if not found