Class JDBC_PING
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.Discovery
-
- org.jgroups.protocols.FILE_PING
-
- org.jgroups.protocols.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, Bela Ban
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jgroups.protocols.FILE_PING
FILE_PING.InfoWriter
-
Nested classes/interfaces inherited from class org.jgroups.protocols.Discovery
Discovery.DiscoveryCacheDisseminationTask
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
clear_sql
protected java.lang.String
connection_driver
protected java.lang.String
connection_password
protected java.lang.String
connection_url
protected java.lang.String
connection_username
protected java.lang.String
contains_sql
protected javax.sql.DataSource
dataSource
protected java.lang.String
datasource_jndi_name
protected java.lang.String
delete_single_sql
protected java.lang.String
initialize_sql
protected java.lang.String
insert_single_sql
protected java.lang.String
select_all_pingdata_sql
-
Fields inherited from class org.jgroups.protocols.FILE_PING
filter, info_writer, info_writer_max_writes_after_view, info_writer_sleep_time, location, reads, regexp, register_shutdown_hook, remove_all_data_on_view_change, remove_old_coords_on_view_change, root_dir, SUFFIX, update_store_on_view_change, write_data_on_find, writes
-
Fields inherited from class org.jgroups.protocols.Discovery
async_discovery, async_discovery_use_separate_thread_per_request, break_on_coord_rsp, cluster_name, current_coord, discovery_req_futures, discovery_rsp_callback, discovery_rsp_expiry_time, is_coord, is_leaving, is_server, local_addr, max_members_in_discovery_request, max_rank_to_reply, num_discovery_requests, num_discovery_runs, ping_responses, return_entire_cache, send_cache_on_join, sends_can_block, stagger_timeout, timer, transport, transport_supports_multicasting, use_disk_cache, use_ip_addrs, view, WHITESPACE
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description JDBC_PING()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
attemptSchemaInitialization()
protected void
clearTable(java.lang.String clustername)
protected void
closeConnection(java.sql.Connection connection)
protected boolean
contains(java.lang.String cluster_name, Address addr)
protected void
createRootDir()
protected void
delete(java.lang.String clustername, java.lang.String addressToDelete)
protected void
delete(java.sql.Connection connection, java.lang.String clustername, java.lang.String addressToDelete)
protected java.sql.Connection
getConnection()
protected javax.sql.DataSource
getDataSourceFromJNDI(java.lang.String name)
void
init()
Called after instance has been created (null constructor) and before protocol is started.protected void
insert(java.sql.Connection connection, PingData data, java.lang.String clustername, java.lang.String address)
protected void
loadDriver()
static void
main(java.lang.String[] args)
protected static java.sql.PreparedStatement
prepareStatement(java.sql.Connection connection, java.lang.String sql, int resultSetType, int resultSetConcurrency)
protected void
readAll(java.sql.Connection connection, java.util.List<Address> members, java.lang.String clustername, Responses rsps)
protected void
readAll(java.util.List<Address> members, java.lang.String clustername, Responses responses)
protected void
remove(java.lang.String clustername, Address addr)
protected void
removeAll(java.lang.String clustername)
Removes all files for the given cluster namevoid
setDataSource(javax.sql.DataSource dataSource)
protected void
verifyConfigurationParameters()
protected void
write(java.util.List<PingData> list, java.lang.String clustername)
protected void
writeToDB(PingData data, java.lang.String clustername, boolean overwrite)
-
Methods inherited from class org.jgroups.protocols.FILE_PING
addressToFilename, deleteFile, down, findMembers, getLocation, getRemoveAllDataOnViewChange, handleView, isDynamic, isInfoWriterRunning, read, read, resetStats, setLocation, setRemoveAllDataOnViewChange, startInfoWriter, stop, stopInfoWriter, write, writeAll, writeAll, writeInfo
-
Methods inherited from class org.jgroups.protocols.Discovery
addDiscoveryResponseToCaches, addResponse, addResponse, addressAsString, addToCache, breakOnCoordResponse, breakOnCoordResponse, clearRequestFutures, deserialize, discoveryRequestReceived, discoveryRspExpiryTime, disseminateDiscoveryInformation, dumpCache, findInitialMembersAsString, findMembers, getClusterName, getCurrentCoord, getNumberOfDiscoveryRequestsSent, getView, getViewId, handleConnect, handleDisconnect, handleDiscoveryResponse, invokeFindMembers, isCoord, isMergeRunning, marshal, providedUpServices, readPingData, returnEntireCache, returnEntireCache, sendCacheInformation, sendDiscoveryResponse, serializeWithoutView, setClusterName, staggerTimeout, staggerTimeout, start, startCacheDissemination, up, up, useDiskCache, useDiskCache, weedOutCompletedDiscoveryResponses
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, down, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, up
-
-
-
-
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
protected javax.sql.DataSource dataSource
-
-
Method Detail
-
createRootDir
protected void createRootDir()
- Overrides:
createRootDir
in classFILE_PING
-
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
-
init
public void init() throws java.lang.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.
-
write
protected void write(java.util.List<PingData> list, java.lang.String clustername)
-
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)
-
removeAll
protected void removeAll(java.lang.String clustername)
Description copied from class:FILE_PING
Removes all files for the given cluster name
-
readAll
protected void readAll(java.util.List<Address> members, java.lang.String clustername, Responses responses)
-
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()
-
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()
-
main
public static void main(java.lang.String[] args) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
-