public class MastersSlavesListener extends AbstractMastersSlavesListener
Modifier and Type | Field and Description |
---|---|
protected Protocol |
masterProtocol |
protected Protocol |
secondaryProtocol |
waitNewMasterProtocol, waitNewSecondaryProtocol
currentConnectionAttempts, currentProtocol, currentReadOnlyAsked, explicitClosed, lastQueryNanos, lastRetry, proxy, urlParser
Constructor and Description |
---|
MastersSlavesListener(UrlParser urlParser)
Initialisation.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkInitialConnection(SQLException queryException) |
boolean |
checkMasterStatus(SearchFilter searchFilter)
Check master status.
|
void |
checkWaitingConnection()
Verify that there is waiting connection that have to replace failing one.
|
List<HostAddress> |
connectedHosts()
List current connected HostAddress.
|
void |
foundActiveMaster(Protocol newMasterProtocol)
Method called when a new Master connection is found after a fallback.
|
void |
foundActiveSecondary(Protocol newSecondaryProtocol)
Method called when a new secondary connection is found after a fallback.
|
void |
handleFailLoop() |
void |
initializeConnection()
Initialize connections.
|
boolean |
isMasterConnected() |
void |
lockAndSwitchMaster(Protocol newMasterProtocol)
Use the parameter newMasterProtocol as new current master connection.
|
void |
lockAndSwitchSecondary(Protocol newSecondaryProtocol)
Use the parameter newSecondaryProtocol as new current secondary connection.
|
void |
preClose()
Called after a call on Connection.close().
|
void |
preExecute() |
HandleErrorResult |
primaryFail(Method method,
Object[] args,
boolean killCmd)
To handle the newly detected failover on the master connection.
|
void |
reconnect()
Reconnect failed connection.
|
void |
reconnectFailedConnection(SearchFilter searchFilter)
Loop to connect.
|
protected void |
removeListenerFromSchedulers() |
void |
rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult,
boolean mustBeOnMaster) |
HandleErrorResult |
secondaryFail(Method method,
Object[] args,
boolean killCmd)
To handle the newly detected failover on the secondary connection.
|
void |
switchReadOnlyConnection(Boolean mustBeReadOnly)
Switch to a read-only(secondary) or read and write connection(master).
|
getFilterForFailedHost, getSecondaryHostFailNanos, handleFailover, hasHostFail, isMasterHostFailReconnect, isSecondaryHostFail, isSecondaryHostFailReconnect, resetMasterFailoverData, resetSecondaryFailoverData, setSecondaryHostFail
addToBlacklist, canRetryFailLoop, clearBlacklist, closeConnection, getBlacklistKeys, getCurrentProtocol, getLastQueryNanos, getMasterHostFailNanos, getProxy, getRetriesAllDown, getUrlParser, invoke, invoke, isAutoReconnect, isClosed, isExplicitClosed, isMasterHostFail, isQueryRelaunchable, isReadOnly, pingMasterProtocol, preAutoReconnect, relaunchOperation, removeFromBlacklist, resetOldsBlackListHosts, setMasterHostFail, setProxy, setSessionReadOnly, syncConnection, throwFailoverMessage
protected Protocol masterProtocol
protected Protocol secondaryProtocol
public MastersSlavesListener(UrlParser urlParser)
urlParser
- connection string object.protected void removeListenerFromSchedulers()
removeListenerFromSchedulers
in class AbstractMastersListener
public void initializeConnection() throws SQLException
initializeConnection
in interface Listener
initializeConnection
in class AbstractMastersListener
SQLException
- if a connection error append.protected void checkInitialConnection(SQLException queryException) throws SQLException
SQLException
public void preClose()
preClose
in interface Listener
preClose
in class AbstractMastersListener
public void preExecute() throws SQLException
preExecute
in interface Listener
preExecute
in class AbstractMastersListener
SQLException
public void checkWaitingConnection() throws SQLException
SQLException
- if error occurpublic void reconnectFailedConnection(SearchFilter searchFilter) throws SQLException
reconnectFailedConnection
in interface Listener
reconnectFailedConnection
in class AbstractMastersListener
SQLException
- if there is any error during reconnectionpublic void foundActiveMaster(Protocol newMasterProtocol)
newMasterProtocol
- the new active connectionpublic void lockAndSwitchMaster(Protocol newMasterProtocol) throws ReconnectDuringTransactionException
Lock must be set
newMasterProtocol
- new master connectionReconnectDuringTransactionException
- if there was an active transaction.public void foundActiveSecondary(Protocol newSecondaryProtocol) throws SQLException
foundActiveSecondary
in class AbstractMastersSlavesListener
newSecondaryProtocol
- the new active connectionSQLException
- if switch failedpublic void lockAndSwitchSecondary(Protocol newSecondaryProtocol) throws SQLException
newSecondaryProtocol
- new secondary connectionSQLException
- if an error occur during setting session read-onlypublic void switchReadOnlyConnection(Boolean mustBeReadOnly) throws SQLException
switchReadOnlyConnection
in interface Listener
switchReadOnlyConnection
in class AbstractMastersListener
mustBeReadOnly
- the read-only status askedSQLException
- if operation hasn't change protocolpublic HandleErrorResult primaryFail(Method method, Object[] args, boolean killCmd) throws Throwable
primaryFail
in interface Listener
primaryFail
in class AbstractMastersListener
method
- the initial called methodargs
- the initial argskillCmd
- is the fail due to a KILL cmdThrowable
- if failover has not been catchpublic void reconnect() throws SQLException
reconnect
in interface Listener
reconnect
in class AbstractMastersListener
SQLException
- if reconnection has failedpublic HandleErrorResult secondaryFail(Method method, Object[] args, boolean killCmd) throws Throwable
secondaryFail
in class AbstractMastersSlavesListener
method
- the initial called methodargs
- the initial argskillCmd
- is fail due to a KILL commandThrowable
- if failover has not catch errorpublic void handleFailLoop()
handleFailLoop
in class AbstractMastersListener
public boolean isMasterConnected()
public boolean checkMasterStatus(SearchFilter searchFilter)
checkMasterStatus
in interface Listener
checkMasterStatus
in class AbstractMastersListener
searchFilter
- search filterpublic void rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult, boolean mustBeOnMaster) throws SQLException
SQLException
public List<HostAddress> connectedHosts()
Copyright © 2017. All rights reserved.