Class JDBC_PING


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
  • 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
    • select_all_pingdata_sql

      protected String select_all_pingdata_sql
    • datasource_jndi_name

      protected String datasource_jndi_name
  • Constructor Details

    • JDBC_PING

      public JDBC_PING()
  • Method Details

    • init

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

      public void stop()
      Description copied from class: Protocol
      This method is called on a Channel.disconnect(). Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
      Overrides:
      stop in class FILE_PING
    • attemptSchemaInitialization

      protected void attemptSchemaInitialization()
    • loadDriver

      protected void loadDriver()
    • getConnection

      protected Connection getConnection()
    • createRootDir

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

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

      protected List<PingData> readAll(String clustername)
      Description copied from class: FILE_PING
      Reads all information from the given directory under clustername
      Overrides:
      readAll in class FILE_PING
      Returns:
    • readAll

      protected List<PingData> readAll(Connection connection, String clustername) throws SQLException
      Throws:
      SQLException
    • writeToFile

      protected void writeToFile(PingData data, String clustername)
      Overrides:
      writeToFile in class FILE_PING
    • 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
    • deleteSelf

      protected void deleteSelf() throws SQLException
      Throws:
      SQLException
    • serializeWithoutView

      protected byte[] serializeWithoutView(PingData data)
      Creates a byte[] representation of the PingData, but DISCARDING the view it contains.
      Parameters:
      data - the PingData instance to serialize.
      Returns:
    • deserialize

      protected PingData deserialize(byte[] data)
    • closeConnection

      protected void closeConnection(Connection connection)
    • getDataSourceFromJNDI

      protected DataSource getDataSourceFromJNDI(String name)
    • verifyconfigurationParameters

      protected void verifyconfigurationParameters()