public class MastersSlavesListener extends AbstractMastersSlavesListener
| Modifier and Type | Field and Description |
|---|---|
private static DynamicSizedSchedulerInterface |
dynamicSizedScheduler |
private static java.util.concurrent.atomic.AtomicInteger |
listenerCount |
private static Logger |
logger |
protected Protocol |
masterProtocol |
protected Protocol |
secondaryProtocol |
waitNewMasterProtocol, waitNewSecondaryProtocolcurrentConnectionAttempts, currentProtocol, currentReadOnlyAsked, explicitClosed, globalInfo, lastQueryNanos, lastRetry, proxy, urlParser| Constructor and Description |
|---|
MastersSlavesListener(UrlParser urlParser,
GlobalStateInfo globalInfo)
Initialisation.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
blackListAndCloseConnection(Protocol protocol) |
protected void |
checkInitialConnection(java.sql.SQLException queryException) |
boolean |
checkMasterStatus(SearchFilter searchFilter)
Check master status.
|
void |
checkWaitingConnection()
Verify that there is waiting connection that have to replace failing one.
|
java.util.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.
|
java.lang.String |
getCatalog() |
int |
getMajorServerVersion() |
long |
getServerThreadId() |
int |
getTimeout()
Get timeout (master connection possibly down).
|
void |
handleFailLoop() |
void |
initializeConnection()
Initialize connections.
|
java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object[] args) |
boolean |
isClosed() |
boolean |
isMasterConnected() |
boolean |
isMasterConnection() |
boolean |
isValid(int timeout) |
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.
|
boolean |
noBackslashEscapes() |
private boolean |
pingSecondaryProtocol(Protocol protocol)
Ping secondary protocol.
|
void |
preAbort() |
void |
preClose()
Called after a call on Connection.close().
|
void |
preExecute() |
HandleErrorResult |
primaryFail(java.lang.reflect.Method method,
java.lang.Object[] args,
boolean killCmd)
To handle the newly detected failover on the master connection.
|
void |
prolog(long maxRows,
MariaDbConnection connection,
MariaDbStatement statement) |
void |
reconnect()
Reconnect failed connection.
|
void |
reconnectFailedConnection(SearchFilter searchFilter)
Loop to connect.
|
protected void |
removeListenerFromSchedulers() |
void |
rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult,
boolean mustBeOnMaster) |
void |
reset()
Reset state of master and slave connection.
|
HandleErrorResult |
secondaryFail(java.lang.reflect.Method method,
java.lang.Object[] args,
boolean killCmd)
To handle the newly detected failover on the secondary connection.
|
boolean |
sessionStateAware() |
void |
switchReadOnlyConnection(java.lang.Boolean mustBeReadOnly)
Switch to a read-only(secondary) or read and write connection(master).
|
boolean |
versionGreaterOrEqual(int major,
int minor,
int patch) |
getFilterForFailedHost, getSecondaryHostFailNanos, handleFailover, hasHostFail, isMasterHostFailReconnect, isSecondaryHostFail, isSecondaryHostFailReconnect, resetMasterFailoverData, resetSecondaryFailoverData, setSecondaryHostFailabortConnection, 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, throwFailoverMessageprivate static final DynamicSizedSchedulerInterface dynamicSizedScheduler
private static final java.util.concurrent.atomic.AtomicInteger listenerCount
private static final Logger logger
protected Protocol masterProtocol
protected Protocol secondaryProtocol
public MastersSlavesListener(UrlParser urlParser, GlobalStateInfo globalInfo)
urlParser - connection string object.globalInfo - server global variables informationprotected void removeListenerFromSchedulers()
removeListenerFromSchedulers in class AbstractMastersListenerpublic void initializeConnection()
throws java.sql.SQLException
initializeConnection in interface ListenerinitializeConnection in class AbstractMastersListenerjava.sql.SQLException - if a connection error append.public boolean isClosed()
isClosed in interface ListenerisClosed in class AbstractMastersListenerpublic java.lang.Object invoke(java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
invoke in interface Listenerinvoke in class AbstractMastersListenerjava.lang.Throwablepublic boolean versionGreaterOrEqual(int major,
int minor,
int patch)
versionGreaterOrEqual in interface ListenerversionGreaterOrEqual in class AbstractMastersListenerpublic boolean sessionStateAware()
sessionStateAware in interface ListenersessionStateAware in class AbstractMastersListenerpublic java.lang.String getCatalog()
throws java.sql.SQLException
getCatalog in interface ListenergetCatalog in class AbstractMastersListenerjava.sql.SQLExceptionpublic int getMajorServerVersion()
getMajorServerVersion in interface ListenergetMajorServerVersion in class AbstractMastersListenerpublic boolean isMasterConnection()
isMasterConnection in interface ListenerisMasterConnection in class AbstractMastersListenerpublic int getTimeout()
throws java.net.SocketException
getTimeout in interface ListenergetTimeout in class AbstractMastersListenerjava.net.SocketException - if socket exceptionpublic void prolog(long maxRows,
MariaDbConnection connection,
MariaDbStatement statement)
throws java.sql.SQLException
prolog in interface Listenerprolog in class AbstractMastersListenerjava.sql.SQLExceptionpublic boolean noBackslashEscapes()
noBackslashEscapes in interface ListenernoBackslashEscapes in class AbstractMastersListenerpublic long getServerThreadId()
protected void checkInitialConnection(java.sql.SQLException queryException)
throws java.sql.SQLException
java.sql.SQLExceptionpublic void preClose()
preClose in interface ListenerpreClose in class AbstractMastersListenerpublic void preAbort()
public void preExecute()
throws java.sql.SQLException
preExecute in interface ListenerpreExecute in class AbstractMastersListenerjava.sql.SQLExceptionpublic boolean isValid(int timeout)
throws java.sql.SQLException
isValid in interface ListenerisValid in class AbstractMastersListenerjava.sql.SQLExceptionpublic void checkWaitingConnection()
throws java.sql.SQLException
java.sql.SQLException - if error occurpublic void reconnectFailedConnection(SearchFilter searchFilter) throws java.sql.SQLException
reconnectFailedConnection in interface ListenerreconnectFailedConnection in class AbstractMastersListenerjava.sql.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 java.sql.SQLException
foundActiveSecondary in class AbstractMastersSlavesListenernewSecondaryProtocol - the new active connectionjava.sql.SQLException - if switch failedpublic void lockAndSwitchSecondary(Protocol newSecondaryProtocol) throws java.sql.SQLException
newSecondaryProtocol - new secondary connectionjava.sql.SQLException - if an error occur during setting session read-onlypublic void switchReadOnlyConnection(java.lang.Boolean mustBeReadOnly)
throws java.sql.SQLException
switchReadOnlyConnection in interface ListenerswitchReadOnlyConnection in class AbstractMastersListenermustBeReadOnly - the read-only status askedjava.sql.SQLException - if operation hasn't change protocolpublic HandleErrorResult primaryFail(java.lang.reflect.Method method, java.lang.Object[] args, boolean killCmd) throws java.lang.Throwable
primaryFail in interface ListenerprimaryFail in class AbstractMastersListenermethod - the initial called methodargs - the initial argskillCmd - is the fail due to a KILL cmdjava.lang.Throwable - if failover has not been catchprivate void blackListAndCloseConnection(Protocol protocol)
public void reconnect()
throws java.sql.SQLException
reconnect in interface Listenerreconnect in class AbstractMastersListenerjava.sql.SQLException - if reconnection has failedprivate boolean pingSecondaryProtocol(Protocol protocol)
protocol - socket to pingpublic HandleErrorResult secondaryFail(java.lang.reflect.Method method, java.lang.Object[] args, boolean killCmd) throws java.lang.Throwable
secondaryFail in class AbstractMastersSlavesListenermethod - the initial called methodargs - the initial argskillCmd - is fail due to a KILL commandjava.lang.Throwable - if failover has not catch errorpublic void handleFailLoop()
handleFailLoop in class AbstractMastersListenerpublic boolean isMasterConnected()
public boolean checkMasterStatus(SearchFilter searchFilter)
checkMasterStatus in interface ListenercheckMasterStatus in class AbstractMastersListenersearchFilter - search filterpublic void rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult, boolean mustBeOnMaster) throws java.sql.SQLException
java.sql.SQLExceptionpublic java.util.List<HostAddress> connectedHosts()
public void reset()
throws java.sql.SQLException
java.sql.SQLException - if command fail.