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 Detail

      • connection_url

        protected java.lang.String connection_url
      • connection_username

        protected java.lang.String connection_username
      • connection_password

        protected java.lang.String connection_password
      • connection_driver

        protected java.lang.String connection_driver
      • initialize_sql

        protected java.lang.String initialize_sql
      • insert_single_sql

        protected java.lang.String insert_single_sql
      • delete_single_sql

        protected java.lang.String delete_single_sql
      • clear_sql

        protected java.lang.String clear_sql
      • select_all_pingdata_sql

        protected java.lang.String select_all_pingdata_sql
      • contains_sql

        protected java.lang.String contains_sql
      • datasource_jndi_name

        protected java.lang.String datasource_jndi_name
      • datasource_injecter_class

        protected java.lang.String datasource_injecter_class
      • dataSource

        protected javax.sql.DataSource dataSource
    • Constructor Detail

      • JDBC_PING

        public JDBC_PING()
    • Method Detail

      • setDataSource

        public JDBC_PING setDataSource​(javax.sql.DataSource ds)
      • getDataSource

        public javax.sql.DataSource getDataSource()
      • getConnectionUrl

        public java.lang.String getConnectionUrl()
      • setConnectionUrl

        public JDBC_PING setConnectionUrl​(java.lang.String c)
      • getConnectionUsername

        public java.lang.String getConnectionUsername()
      • setConnectionUsername

        public JDBC_PING setConnectionUsername​(java.lang.String c)
      • getConnectionPassword

        public java.lang.String getConnectionPassword()
      • setConnectionPassword

        public JDBC_PING setConnectionPassword​(java.lang.String c)
      • getConnectionDriver

        public java.lang.String getConnectionDriver()
      • setConnectionDriver

        public JDBC_PING setConnectionDriver​(java.lang.String c)
      • getInitializeSql

        public java.lang.String getInitializeSql()
      • setInitializeSql

        public JDBC_PING setInitializeSql​(java.lang.String i)
      • getInsertSingleSql

        public java.lang.String getInsertSingleSql()
      • setInsertSingleSql

        public JDBC_PING setInsertSingleSql​(java.lang.String i)
      • getDeleteSingleSql

        public java.lang.String getDeleteSingleSql()
      • setDeleteSingleSql

        public JDBC_PING setDeleteSingleSql​(java.lang.String d)
      • getClearSql

        public java.lang.String getClearSql()
      • setClearSql

        public JDBC_PING setClearSql​(java.lang.String c)
      • getSelectAllPingdataSql

        public java.lang.String getSelectAllPingdataSql()
      • setSelectAllPingdataSql

        public JDBC_PING setSelectAllPingdataSql​(java.lang.String s)
      • getContainsSql

        public java.lang.String getContainsSql()
      • setContainsSql

        public JDBC_PING setContainsSql​(java.lang.String c)
      • getDatasourceJndiName

        public java.lang.String getDatasourceJndiName()
      • setDatasourceJndiName

        public JDBC_PING setDatasourceJndiName​(java.lang.String d)
      • getDatasourceInjecterClass

        public java.lang.String getDatasourceInjecterClass()
      • setDatasourceInjecterClass

        public JDBC_PING setDatasourceInjecterClass​(java.lang.String d)
      • init

        public void init()
                  throws java.lang.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:
        java.lang.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​(java.util.List<PingData> list,
                             java.lang.String clustername)
        Overrides:
        write in class FILE_PING
      • writeToDB

        protected void writeToDB​(PingData data,
                                 java.lang.String clustername,
                                 boolean overwrite)
      • contains

        protected boolean contains​(java.lang.String cluster_name,
                                   Address addr)
      • remove

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

        protected void removeAll​(java.lang.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​(java.util.List<Address> members,
                               java.lang.String clustername,
                               Responses responses)
        Overrides:
        readAll in class FILE_PING
      • prepareStatement

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

        protected void readAll​(java.sql.Connection connection,
                               java.util.List<Address> members,
                               java.lang.String clustername,
                               Responses rsps)
                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • attemptSchemaInitialization

        protected void attemptSchemaInitialization()
      • loadDriver

        protected void loadDriver()
      • injectDataSource

        protected javax.sql.DataSource injectDataSource​(java.lang.String ds_class)
                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getConnection

        protected java.sql.Connection getConnection()
      • insert

        protected void insert​(java.sql.Connection connection,
                              PingData data,
                              java.lang.String clustername,
                              java.lang.String address)
                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • delete

        protected void delete​(java.sql.Connection connection,
                              java.lang.String clustername,
                              java.lang.String addressToDelete)
                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • delete

        protected void delete​(java.lang.String clustername,
                              java.lang.String addressToDelete)
                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • clearTable

        protected void clearTable​(java.lang.String clustername)
      • closeConnection

        protected void closeConnection​(java.sql.Connection connection)
      • getDataSourceFromJNDI

        protected javax.sql.DataSource getDataSourceFromJNDI​(java.lang.String name)
      • verifyConfigurationParameters

        protected void verifyConfigurationParameters()
      • assertNonNull

        protected static void assertNonNull​(java.lang.String... strings)
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException