Class JDBC_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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jgroups.protocols.FILE_PING
FILE_PING.WriterTaskNested classes/interfaces inherited from class org.jgroups.protocols.Discovery
Discovery.Responses -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected StringFields inherited from class org.jgroups.protocols.FILE_PING
filter, interval, location, root_dir, SUFFIXFields inherited from class org.jgroups.protocols.Discovery
group_addr, local_addr, members, ping_responses, rank, timer, view -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidcloseConnection(Connection connection) protected voidprotected voidprotected voiddelete(Connection connection, String clustername, String addressToDelete) protected voidprotected PingDatadeserialize(byte[] data) protected Connectionprotected DataSourcegetDataSourceFromJNDI(String name) voidinit()Called after instance has been created (null constructor) and before protocol is started.protected voidinsert(Connection connection, PingData data, String clustername, String address) protected voidReads all information from the given directory under clusternamereadAll(Connection connection, String clustername) protected voidprotected byte[]serializeWithoutView(PingData data) Creates a byte[] representation of the PingData, but DISCARDING the view it contains.voidstop()This method is called on aChannel.disconnect().protected voidprotected voidwriteToFile(PingData data, String clustername) Methods inherited from class org.jgroups.protocols.FILE_PING
addressAsString, down, handleView, readFile, sendGetMembersRequest, startMethods inherited from class org.jgroups.protocols.Discovery
discoveryRequestReceived, findAllMembers, findAllViews, findAllViewsAsString, findInitialMembers, findInitialMembers, findInitialMembersAsString, getNumberOfDiscoveryRequestsSent, getNumInitialMembers, getNumPingRequests, getTimeout, getView, handleConnect, handleDisconnect, makeView, providedUpServices, resetStats, setNumInitialMembers, setNumPingRequests, setTimeout, upMethods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getId, getLevel, getName, getProperties, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getValue, isErgonomics, printStats, providedDownServices, requiredDownServices, requiredUpServices, setDownProtocol, setErgonomics, setId, setLevel, setProperties, setPropertiesInternal, setProperty, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, statsEnabled, upThreadEnabled
-
Field Details
-
connection_url
-
connection_username
-
connection_password
-
connection_driver
-
initialize_sql
-
insert_single_sql
-
delete_single_sql
-
select_all_pingdata_sql
-
datasource_jndi_name
-
-
Constructor Details
-
JDBC_PING
public JDBC_PING()
-
-
Method Details
-
init
Description copied from class:ProtocolCalled 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. -
stop
public void stop()Description copied from class:ProtocolThis method is called on aChannel.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 -
attemptSchemaInitialization
protected void attemptSchemaInitialization() -
loadDriver
protected void loadDriver() -
getConnection
-
createRootDir
protected void createRootDir()- Overrides:
createRootDirin classFILE_PING
-
remove
-
readAll
Description copied from class:FILE_PINGReads all information from the given directory under clustername -
readAll
- Throws:
SQLException
-
writeToFile
- Overrides:
writeToFilein classFILE_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
- Throws:
SQLException
-
deleteSelf
- Throws:
SQLException
-
serializeWithoutView
Creates a byte[] representation of the PingData, but DISCARDING the view it contains.- Parameters:
data- the PingData instance to serialize.- Returns:
-
deserialize
-
closeConnection
-
getDataSourceFromJNDI
-
verifyconfigurationParameters
protected void verifyconfigurationParameters()
-