- All Implemented Interfaces:
Listener
- Direct Known Subclasses:
AuroraListener
this class handle the operation when multiple hosts.
-
-
Constructor Summary
Constructors
-
Method Summary
private void
protected void
boolean
void
Verify that there is waiting connection that have to replace failing one.
List current connected HostAddress.
void
Method called when a new Master connection is found after a fallback.
void
Method called when a new secondary connection is found after a fallback.
int
long
Get current connection server id.
int
Get timeout (master connection possibly down).
void
void
boolean
Indicate if connection has an active transaction.
boolean
boolean
boolean
boolean
boolean
private static void
void
Use the parameter newMasterProtocol as new current master connection.
void
Use the parameter newSecondaryProtocol as new current secondary connection.
boolean
private boolean
void
void
Called after a call on Connection.close().
void
To handle the newly detected failover on the master connection.
void
void
Reconnect failed connection.
void
protected void
void
void
Reset state of master and replica connection.
To handle the newly detected failover on the secondary connection.
boolean
void
Switch to a read-only(secondary) or read and write connection(master).
boolean
Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener
abortConnection, addToBlacklist, canRetryFailLoop, clearBlacklist, closeConnection, getBlacklistKeys, getCurrentProtocol, getLastQueryNanos, getMasterHostFailNanos, getProxy, getRetriesAllDown, getUrlParser, invoke, isAutoReconnect, isExplicitClosed, isMasterHostFail, isQueryRelaunchable, isReadOnly, pingMasterProtocol, preAutoReconnect, relaunchOperation, removeFromBlacklist, resetOldsBlackListHosts, setMasterHostFail, setProxy, setSessionReadOnly, syncConnection, throwFailoverMessage
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
-
logger
private static final Logger logger
-
-
-
-
-
Constructor Details
-
MastersReplicasListener
Initialisation.
- Parameters:
urlParser
- connection string object.
globalInfo
- server global variables information
-
Method Details
-
loadScheduler
private static void loadScheduler()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
getServerThreadId
public long getServerThreadId()
Get current connection server id.
- Returns:
- server id.
-
-
-
preAbort
public void preAbort()
-
-
-
checkWaitingConnection
Verify that there is waiting connection that have to replace failing one. If there is replace
failed connection with new one.
- Throws:
SQLException
- if error occur
-
-
foundActiveMaster
public void foundActiveMaster(Protocol newMasterProtocol)
Method called when a new Master connection is found after a fallback.
- Parameters:
newMasterProtocol
- the new active connection
-
lockAndSwitchMaster
Use the parameter newMasterProtocol as new current master connection.
Lock must be set
- Parameters:
newMasterProtocol
- new master connection
- Throws:
ReconnectDuringTransactionException
- if there was an active transaction.
-
-
lockAndSwitchSecondary
Use the parameter newSecondaryProtocol as new current secondary connection.
- Parameters:
newSecondaryProtocol
- new secondary connection
- Throws:
SQLException
- if an error occur during setting session read-only
-
-
primaryFail
To handle the newly detected failover on the master connection.
- Specified by:
primaryFail
in interface Listener
- Specified by:
primaryFail
in class AbstractMastersListener
- Parameters:
method
- the initial called method
args
- the initial args
killCmd
- is the fail due to a KILL cmd
- Returns:
- an object to indicate if the previous Exception must be thrown, or the object resulting
if a failover worked
-
blackListAndCloseConnection
private void blackListAndCloseConnection(Protocol protocol)
-
-
pingSecondaryProtocol
private boolean pingSecondaryProtocol(Protocol protocol)
Ping secondary protocol. ! lock must be set !
- Parameters:
protocol
- socket to ping
- Returns:
- true if ping is valid.
-
secondaryFail
To handle the newly detected failover on the secondary connection.
- Specified by:
secondaryFail
in class AbstractMastersReplicasListener
- Parameters:
method
- the initial called method
args
- the initial args
killCmd
- is fail due to a KILL command
- Returns:
- an object to indicate if the previous Exception must be thrown, or the object resulting
if a failover worked
- Throws:
SQLException
- if relaunch operation fails
-
-
isMasterConnected
public boolean isMasterConnected()
-
-
-
-
connectedHosts
List current connected HostAddress.
- Returns:
- hostAddress List.
-
reset
Reset state of master and replica connection.
- Throws:
SQLException
- if command fail.