Class AsynchronousLoadBalancerPersistence

java.lang.Object
org.jppf.load.balancer.persistence.AsynchronousLoadBalancerPersistence
All Implemented Interfaces:
LoadBalancerPersistence

public class AsynchronousLoadBalancerPersistence extends Object implements LoadBalancerPersistence
An asynchronous wrapper for any other load-balancer persistence implementation. The methods of LoadBalancerPersistence that do not return a result (void return type) are non-blocking and return immediately. All other methods will block until they are executed and their result is available. The execution of the interface's methods are delegated to a thread pool, whose size can be defined in the configuration or defaults to 1.

This asynchronous persistence can be configured in two forms:

 # shorten the configuration value for clarity
 wrapper = org.jppf.load.balancer.persistence.AsynchronousLoadBalancerPersistence
 # asynchronous persistence with default thread pool size
 jppf.load.balancing.persistence = ${wrapper} <actual_persistence> <param1> ... <paramN>
 # asynchronous persistence with a specified thread pool size
 jppf.load.balancer.persistence = ${wrapper} <pool_size> <actual_persistence> <param1> ... <paramN>

Here is an example configuration for an asynchronous database persistence:

 pkg = org.jppf.load.balancer.persistence
 # asynchronous database persistence with pool of 4 threads,
 # a table named 'JPPF_TEST' and datasource named 'loadBalancerDS'
 jppf.load.balancing.persistence = ${pkg}.AsynchronousLoadBalancerPersistence 4 \
   ${pkg}.DatabaseLoadBalancerPersistence JPPF_TEST loadBalancerDS
Since:
6.0
Author:
Laurent Cohen
  • Constructor Details

    • AsynchronousLoadBalancerPersistence

      public AsynchronousLoadBalancerPersistence(String... params) throws LoadBalancerPersistenceException
      Initialize this persistence with the specified parameters.
      Parameters:
      params - if the first parameter is a number, then it represents the number of threads that perform the asynchronous processing, and the remaining parameters represent the wrapped persistence implementation. Otherwise it represents the wrapped persistence and the remaining parameters are those of the wrapped persistence.
      Throws:
      LoadBalancerPersistenceException - if any error occurs.
  • Method Details

    • load

      Description copied from interface: LoadBalancerPersistence
      Load the state of a load balancer from the persistence sstore.
      Specified by:
      load in interface LoadBalancerPersistence
      Parameters:
      info - a LoadBalancerPersistenceInfo object representing the load balancer and its state.
      Returns:
      an object representing the load balancer state, or null if no entry exists in the persistence store for the specified node identifier.
      Throws:
      LoadBalancerPersistenceException - if any erorr occurs during the persistence operation.
    • store

      Description copied from interface: LoadBalancerPersistence
      Store a load balancer to the persistence sstore.
      Specified by:
      store in interface LoadBalancerPersistence
      Parameters:
      info - a LoadBalancerPersistenceInfo object representing the load balancer and its state.
      Throws:
      LoadBalancerPersistenceException - if any erorr occurs during the persistence operation.
    • delete

      Description copied from interface: LoadBalancerPersistence
      Delete the specified load-balancer state(s) from the persistence store.

      The info parameter embeds both the scope and identifiers for the artifacts to delete:

      • if info is null or both info.getChannelID() and info.getAlgorithmID() are null, then all entries in the persistence store are deleted
      • if only info.getAlgorithmID() is null, then the states of all algorithm for the specified channel are deleted
      • if only info.getChannelID() is null, then the states of the specified algorithm are deleted for all the channels
      • if neither info.getChannelID() nor info.getAlgorithmID() are null, then only the state of the specified algorithm for the specified channel is deleted
      Specified by:
      delete in interface LoadBalancerPersistence
      Parameters:
      info - encapsulates information about the artifacts to delete.
      Throws:
      LoadBalancerPersistenceException - if any erorr occurs during the persistence operation.
    • list

      Description copied from interface: LoadBalancerPersistence
      List all entries in the persistence store.

      The info parameter embeds both the scope and identifiers for the artifacts to list:

      • if info is null or both info.getChannelID() and info.getAlgorithmID() are null, then all channelIDs in the persistence store are returned
      • if only info.getAlgorithmID() is null, then all the algorithm IDs for the specified channel are returned
      • if only info.getChannelID() is null, then the the IDs of the channels that have a persisted state for the algorithm are returned
      • if neither info.getChannelID() nor info.getAlgorithmID() are null, then the specified algorithmID is returned (list with a single entry) if the specified channel has an entry for it, otherwise an empty list must be returned
      Specified by:
      list in interface LoadBalancerPersistence
      Parameters:
      info - encapsulates information about the artifacts to delete.
      Returns:
      a list of nodeIDs or algorithmIDs, depending on the input parameter.
      Throws:
      LoadBalancerPersistenceException - if any erorr occurs during the persistence operation.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getUncompletedOperations

      public int getUncompletedOperations()
      Description copied from interface: LoadBalancerPersistence
      Get the number of persistence operations, including load, store, delete and list, that have started but not yet completed.
      Specified by:
      getUncompletedOperations in interface LoadBalancerPersistence
      Returns:
      the number of uncompleted operations.