Class DatabaseLoadBalancerPersistence

java.lang.Object
org.jppf.persistence.AbstractDatabasePersistence<LoadBalancerPersistenceInfo>
org.jppf.load.balancer.persistence.DatabaseLoadBalancerPersistence
All Implemented Interfaces:
LoadBalancerPersistence

public class DatabaseLoadBalancerPersistence extends AbstractDatabasePersistence<LoadBalancerPersistenceInfo> implements LoadBalancerPersistence
A job persistence implementation which stores jobs in a single database table. The table has the following structure:
 CREATE TABLE <table_name> (
   NODEID varchar(250) NOT NULL,
   ALGORITHMID varchar(250) NOT NULL,
   STATE blob NOT NULL,
   PRIMARY KEY (NODEID, ALGORITHMID)
 );

Where:

  • the NODEID column represents a hash of a string concatenated from various properties of the node. This id is unique for each node and resilient over node restarts, contrary to the node uuid, which is recreated each time a node starts
  • the ALGORITHMID column is a hash of the load-balancer's algorithm name.
  • the STATE column represents the serialized state of the load-balancer, such as provided by PersistentState.getState()

The table name is specified in the JPPF configuration like this:

 lb.pkg = org.jppf.load.balancer.persistence
 jppf.load.balancing.persistence = ${lb.pkg}.DatabaseLoadBalancerPersistence <table_name>

If unspecified, it defaults to the default table name 'load_balancer'. If the table does not exist, JPPF will attempt to create it. If this fails for any reason, for instance if the user does not have sufficient privileges, then persistence will be disabled.

This database persistence implementation uses a HikariCP connection pool and datasource. The datasource is specified by name in the configuration:
jppf.load.balancing.persistence = org.jppf.load.balancer.persistence.DatabaseLoadBalancerPersistence <table_name> <datasource_name>
If unspecified, it defaults to 'loadBalancerDS'. The datasource properties must be defined in the JPPF configuration like so:

 jppf.datasource.<configId>.name = <datasource_name>
 jppf.datasource.<configId>.<hikaricp_property> = <value>

Where:

  • configId is used to distinguish the datasource properties when multiple datasources are defined
  • the datasource name is mandatory and is used to store and retrieve the datasource in a custom registry. It is also the datasource name used in the configuration of this job persistence implementation
  • hikaricp_property desginates any valid HikariCP configuration property. Properties not supported by HikariCP are simply ignored

Here is a full example configuration:

 # persistence definition
 lb.pkg = org.jppf.load.balancer.persistence
 jppf.load.balancing.persistence = ${lb.pkg}.DatabaseLoadBalancerPersistence MY_TABLE loadBalancerDS

 # datasource definition
 jppf.datasource.lb.name = loadBalancerDS
 jppf.datasource.lb.driverClassName = com.mysql.jdbc.Driver
 jppf.datasource.lb.jdbcUrl = jdbc:mysql://localhost:3306/testjppf
 jppf.datasource.lb.username = testjppf
 jppf.datasource.lb.password = testjppf
 jppf.datasource.lb.minimumIdle = 5
 jppf.datasource.lb.maximumPoolSize = 10
 jppf.datasource.lb.connectionTimeout = 30000
 jppf.datasource.lb.idleTimeout = 600000
Since:
6.0
Author:
Laurent Cohen
  • Field Details

  • Constructor Details

    • DatabaseLoadBalancerPersistence

      public DatabaseLoadBalancerPersistence() throws Exception
      Intialize this persistence with the default table name.
      Throws:
      Exception - if any error occurs.
    • DatabaseLoadBalancerPersistence

      public DatabaseLoadBalancerPersistence(String... params) throws Exception
      Intialize this persistence with a table name specified in the first string parameter.
      Parameters:
      params - if parameters are provided, they have this meaning:
      • params[0] is the table name, which defaults to 'JOB_PERSISTENCE'
      • params[1] is the name of a datasource defined in the configuration, and defaults to 'job_persistence'
      Throws:
      Exception - if any error occurs.
  • Method Details