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:
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.
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:
configIdis used to distinguish the datasource properties when multiple datasources are defined- the datasource
nameis 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_propertydesginates 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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jppf.persistence.AbstractDatabasePersistence
AbstractDatabasePersistence.ConnectionWrapper -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default persistence datasource name.static final StringThe default persistence table name.Fields inherited from class org.jppf.persistence.AbstractDatabasePersistence
dataSource, dataSourceName, ddlProp, defaultDatasource, defaultTable, EMPTY_STRINGS, sqlStatements, TABLE_PROP, tableName -
Constructor Summary
ConstructorsConstructorDescriptionIntialize this persistence with the default table name.DatabaseLoadBalancerPersistence(String... params) Intialize this persistence with a table name specified in the first string parameter. -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete the specified load-balancer state(s) from the persistence store.intGet the number of persistence operations, including load, store, delete and list, that have started but not yet completed.protected voidinsertElement(Connection connection, LoadBalancerPersistenceInfo info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.List all entries in the persistence store.Load the state of a load balancer from the persistence sstore.protected booleanlockForUpdate(Connection connection, LoadBalancerPersistenceInfo info) Lock the specified row for update, if it existsvoidStore a load balancer to the persistence sstore.protected voidupdateElement(Connection connection, LoadBalancerPersistenceInfo info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.Methods inherited from class org.jppf.persistence.AbstractDatabasePersistence
getConnection, getSQL, storeElement, toString
-
Field Details
-
DEFAULT_TABLE
The default persistence table name.- See Also:
-
DEFAULT_DATASOURCE
The default persistence datasource name.- See Also:
-
-
Constructor Details
-
DatabaseLoadBalancerPersistence
Intialize this persistence with the default table name.- Throws:
Exception- if any error occurs.
-
DatabaseLoadBalancerPersistence
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
-
load
Description copied from interface:LoadBalancerPersistenceLoad the state of a load balancer from the persistence sstore.- Specified by:
loadin interfaceLoadBalancerPersistence- Parameters:
info- aLoadBalancerPersistenceInfoobject representing the load balancer and its state.- Returns:
- an object representing the load balancer state, or
nullif 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:LoadBalancerPersistenceStore a load balancer to the persistence sstore.- Specified by:
storein interfaceLoadBalancerPersistence- Parameters:
info- aLoadBalancerPersistenceInfoobject representing the load balancer and its state.- Throws:
LoadBalancerPersistenceException- if any erorr occurs during the persistence operation.
-
delete
Description copied from interface:LoadBalancerPersistenceDelete the specified load-balancer state(s) from the persistence store.The
infoparameter embeds both the scope and identifiers for the artifacts to delete:- if
infoisnullor bothinfo.getChannelID()andinfo.getAlgorithmID()arenull, then all entries in the persistence store are deleted - if only
info.getAlgorithmID()isnull, then the states of all algorithm for the specified channel are deleted - if only
info.getChannelID()isnull, then the states of the specified algorithm are deleted for all the channels - if neither
info.getChannelID()norinfo.getAlgorithmID()arenull, then only the state of the specified algorithm for the specified channel is deleted
- Specified by:
deletein interfaceLoadBalancerPersistence- Parameters:
info- encapsulates information about the artifacts to delete.- Throws:
LoadBalancerPersistenceException- if any erorr occurs during the persistence operation.
- if
-
list
Description copied from interface:LoadBalancerPersistenceList all entries in the persistence store.The
infoparameter embeds both the scope and identifiers for the artifacts to list:- if
infoisnullor bothinfo.getChannelID()andinfo.getAlgorithmID()arenull, then all channelIDs in the persistence store are returned - if only
info.getAlgorithmID()isnull, then all the algorithm IDs for the specified channel are returned - if only
info.getChannelID()isnull, then the the IDs of the channels that have a persisted state for the algorithm are returned - if neither
info.getChannelID()norinfo.getAlgorithmID()arenull, 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:
listin interfaceLoadBalancerPersistence- 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.
- if
-
lockForUpdate
protected boolean lockForUpdate(Connection connection, LoadBalancerPersistenceInfo info) throws Exception Description copied from class:AbstractDatabasePersistenceLock the specified row for update, if it exists- Specified by:
lockForUpdatein classAbstractDatabasePersistence<LoadBalancerPersistenceInfo>- Parameters:
connection- the JDBC connection with which to create an dexecute the query.info- the job element corresponding to the SQL row to lock.- Returns:
trueif the row already exists (and therefore a lock is acquired),falseotherwise.- Throws:
Exception- if any error occurs.
-
insertElement
protected void insertElement(Connection connection, LoadBalancerPersistenceInfo info, byte[] bytes) throws Exception Description copied from class:AbstractDatabasePersistenceCreate a prepared statement which will insert or update an object in the database.- Specified by:
insertElementin classAbstractDatabasePersistence<LoadBalancerPersistenceInfo>- Parameters:
connection- the JDBC connection with which to create an dexecute the statement.info- the information on the object to persist.bytes- the serialized object to persist.- Throws:
Exception- if any error occurs.
-
updateElement
protected void updateElement(Connection connection, LoadBalancerPersistenceInfo info, byte[] bytes) throws Exception Description copied from class:AbstractDatabasePersistenceCreate a prepared statement which will insert or update an object in the database.- Specified by:
updateElementin classAbstractDatabasePersistence<LoadBalancerPersistenceInfo>- Parameters:
connection- the JDBC connection with which to create an dexecute the statement.info- the information on the object to persist.bytes- the serialized object to persist.- Throws:
Exception- if any error occurs.
-
getUncompletedOperations
public int getUncompletedOperations()Description copied from interface:LoadBalancerPersistenceGet the number of persistence operations, including load, store, delete and list, that have started but not yet completed.- Specified by:
getUncompletedOperationsin interfaceLoadBalancerPersistence- Returns:
- the number of uncompleted operations.
-