Class JDBC_PING

All Implemented Interfaces:
Lifecycle

public class JDBC_PING extends FILE_PING
Discovery protocol using a JDBC connection to a shared database. Connection options can be defined as configuration properties, or the JNDI name of a DataSource can be provided (avoid providing both).

Both the schema and the used SQL statements can be customized; make sure the order of parameters of such customized SQL statements is maintained and that compatible types are used for the columns. The recommended schema uses a single table, with two String columns being used primary key (local address, cluster name) and a third column to store the serialized form of the objects needed by JGroups.

A default table will be created at first connection, errors during this operation are not considered critical. Set the initialize_sql to an empty value to prevent this initial table creation, or change it to create a customized table.

Since:
2.12
Author:
Sanne Grinovero, Bela Ban
  • Field Details

    • connection_url

      protected String connection_url
    • connection_username

      protected String connection_username
    • connection_password

      protected String connection_password
    • connection_driver

      protected String connection_driver
    • initialize_sql

      protected String initialize_sql
    • insert_single_sql

      protected String insert_single_sql
    • delete_single_sql

      protected String delete_single_sql
    • clear_sql

      protected String clear_sql
    • select_all_pingdata_sql

      protected String select_all_pingdata_sql
    • contains_sql

      protected String contains_sql
    • datasource_jndi_name

      protected String datasource_jndi_name
    • datasource_injecter_class

      protected String datasource_injecter_class
    • dataSource

      protected DataSource dataSource
  • Constructor Details

    • JDBC_PING

      public JDBC_PING()
  • Method Details

    • createRootDir

      protected void createRootDir()
      Overrides:
      createRootDir in class FILE_PING
    • setDataSource

      public JDBC_PING setDataSource(DataSource ds)
    • getDataSource

      public DataSource getDataSource()
    • getConnectionUrl

      public String getConnectionUrl()
    • setConnectionUrl

      public JDBC_PING setConnectionUrl(String c)
    • getConnectionUsername

      public String getConnectionUsername()
    • setConnectionUsername

      public JDBC_PING setConnectionUsername(String c)
    • getConnectionPassword

      public String getConnectionPassword()
    • setConnectionPassword

      public JDBC_PING setConnectionPassword(String c)
    • getConnectionDriver

      public String getConnectionDriver()
    • setConnectionDriver

      public JDBC_PING setConnectionDriver(String c)
    • getInitializeSql

      public String getInitializeSql()
    • setInitializeSql

      public JDBC_PING setInitializeSql(String i)
    • getInsertSingleSql

      public String getInsertSingleSql()
    • setInsertSingleSql

      public JDBC_PING setInsertSingleSql(String i)
    • getDeleteSingleSql

      public String getDeleteSingleSql()
    • setDeleteSingleSql

      public JDBC_PING setDeleteSingleSql(String d)
    • getClearSql

      public String getClearSql()
    • setClearSql

      public JDBC_PING setClearSql(String c)
    • getSelectAllPingdataSql

      public String getSelectAllPingdataSql()
    • setSelectAllPingdataSql

      public JDBC_PING setSelectAllPingdataSql(String s)
    • getContainsSql

      public String getContainsSql()
    • setContainsSql

      public JDBC_PING setContainsSql(String c)
    • getDatasourceJndiName

      public String getDatasourceJndiName()
    • setDatasourceJndiName

      public JDBC_PING setDatasourceJndiName(String d)
    • getDatasourceInjecterClass

      public String getDatasourceInjecterClass()
    • setDatasourceInjecterClass

      public JDBC_PING setDatasourceInjecterClass(String d)
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
      Specified by:
      init in interface Lifecycle
      Overrides:
      init in class FILE_PING
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
    • write

      protected void write(List<PingData> list, String clustername)
      Overrides:
      write in class FILE_PING
    • writeToDB

      protected void writeToDB(PingData data, String clustername, boolean overwrite)
    • contains

      protected boolean contains(String cluster_name, Address addr)
    • remove

      protected void remove(String clustername, Address addr)
      Overrides:
      remove in class FILE_PING
    • removeAll

      protected void removeAll(String clustername)
      Description copied from class: FILE_PING
      Removes all files for the given cluster name
      Overrides:
      removeAll in class FILE_PING
    • readAll

      protected void readAll(List<Address> members, String clustername, Responses responses)
      Overrides:
      readAll in class FILE_PING
    • prepareStatement

      protected static final PreparedStatement prepareStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException
      Throws:
      SQLException
    • readAll

      protected void readAll(Connection connection, List<Address> members, String clustername, Responses rsps) throws SQLException
      Throws:
      SQLException
    • attemptSchemaInitialization

      protected void attemptSchemaInitialization()
    • loadDriver

      protected void loadDriver()
    • injectDataSource

      protected DataSource injectDataSource(String ds_class) throws Exception
      Throws:
      Exception
    • getConnection

      protected Connection getConnection()
    • insert

      protected void insert(Connection connection, PingData data, String clustername, String address) throws SQLException
      Throws:
      SQLException
    • delete

      protected void delete(Connection connection, String clustername, String addressToDelete) throws SQLException
      Throws:
      SQLException
    • delete

      protected void delete(String clustername, String addressToDelete) throws SQLException
      Throws:
      SQLException
    • clearTable

      protected void clearTable(String clustername)
    • closeConnection

      protected void closeConnection(Connection connection)
    • getDataSourceFromJNDI

      protected DataSource getDataSourceFromJNDI(String name)
    • validateDatasourceJndiName

      protected static void validateDatasourceJndiName(String name)
    • verifyConfigurationParameters

      protected void verifyConfigurationParameters()
    • assertNonNull

      protected static void assertNonNull(String... strings)
    • main

      public static void main(String[] args) throws ClassNotFoundException
      Throws:
      ClassNotFoundException