Class MastersFailoverListener
- java.lang.Object
-
- org.mariadb.jdbc.internal.failover.AbstractMastersListener
-
- org.mariadb.jdbc.internal.failover.impl.MastersFailoverListener
-
- All Implemented Interfaces:
Listener
public class MastersFailoverListener extends AbstractMastersListener
-
-
Field Summary
-
Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener
currentConnectionAttempts, currentProtocol, currentReadOnlyAsked, explicitClosed, globalInfo, lastQueryNanos, lastRetry, proxy, urlParser
-
-
Constructor Summary
Constructors Constructor Description MastersFailoverListener(UrlParser urlParser, GlobalStateInfo globalInfo)Initialisation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckMasterStatus(SearchFilter searchFilter)Check master status.voidfoundActiveMaster(Protocol protocol)method called when a new Master connection is found after a fallback.longgetServerThreadId()voidhandleFailLoop()Add listener to FailoverLoop if master connection is not active, so a reconnection will be done.voidinitializeConnection()Connect to database.booleanisMasterConnected()voidpreAbort()voidpreClose()voidpreExecute()Before executing query, reconnect if connection is closed, and autoReconnect option is set.HandleErrorResultprimaryFail(Method method, Object[] args, boolean killCmd, boolean alreadyClosed)voidreconnect()Try to reconnect connection.voidreconnectFailedConnection(SearchFilter searchFilter)Loop to connect failed hosts.voidrePrepareOnSlave(ServerPrepareResult oldServerPrepareResult, boolean mustExecuteOnSlave)voidreset()Reset state of master connection.voidswitchReadOnlyConnection(Boolean mustBeReadOnly)Force session to read-only according to options.-
Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener
abortConnection, addToBlacklist, canRetryFailLoop, clearBlacklist, closeConnection, getBlacklistKeys, getCatalog, getCurrentProtocol, getFilterForFailedHost, getLastQueryNanos, getMajorServerVersion, getMasterHostFailNanos, getProxy, getRetriesAllDown, getTimeout, getUrlParser, handleFailover, hasHostFail, inTransaction, invoke, invoke, isAutoReconnect, isClosed, isExplicitClosed, isMasterConnection, isMasterHostFail, isQueryRelaunchable, isReadOnly, isServerMariaDb, isValid, noBackslashEscapes, pingMasterProtocol, preAutoReconnect, prolog, relaunchOperation, removeFromBlacklist, removeListenerFromSchedulers, resetMasterFailoverData, resetOldsBlackListHosts, sessionStateAware, setMasterHostFail, setProxy, setSessionReadOnly, syncConnection, throwFailoverMessage, versionGreaterOrEqual
-
-
-
-
Constructor Detail
-
MastersFailoverListener
public MastersFailoverListener(UrlParser urlParser, GlobalStateInfo globalInfo)
Initialisation.- Parameters:
urlParser- url options.globalInfo- server global variables information
-
-
Method Detail
-
initializeConnection
public void initializeConnection() throws SQLExceptionConnect to database.- Specified by:
initializeConnectionin interfaceListener- Overrides:
initializeConnectionin classAbstractMastersListener- Throws:
SQLException- if connection is on error.
-
preExecute
public void preExecute() throws SQLExceptionBefore executing query, reconnect if connection is closed, and autoReconnect option is set.- Specified by:
preExecutein interfaceListener- Specified by:
preExecutein classAbstractMastersListener- Throws:
SQLException- if connection has been explicitly closed.
-
preClose
public void preClose()
- Specified by:
preClosein interfaceListener- Specified by:
preClosein classAbstractMastersListener
-
getServerThreadId
public long getServerThreadId()
-
preAbort
public void preAbort()
-
primaryFail
public HandleErrorResult primaryFail(Method method, Object[] args, boolean killCmd, boolean alreadyClosed)
- Specified by:
primaryFailin interfaceListener- Specified by:
primaryFailin classAbstractMastersListener
-
reconnectFailedConnection
public void reconnectFailedConnection(SearchFilter searchFilter) throws SQLException
Loop to connect failed hosts.- Specified by:
reconnectFailedConnectionin interfaceListener- Specified by:
reconnectFailedConnectionin classAbstractMastersListener- Parameters:
searchFilter- search parameters.- Throws:
SQLException- if there is any error during reconnection
-
switchReadOnlyConnection
public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws SQLException
Force session to read-only according to options.- Specified by:
switchReadOnlyConnectionin interfaceListener- Specified by:
switchReadOnlyConnectionin classAbstractMastersListener- Parameters:
mustBeReadOnly- is read-only flag- Throws:
SQLException- if a connection error occur
-
foundActiveMaster
public void foundActiveMaster(Protocol protocol) throws SQLException
method called when a new Master connection is found after a fallback.- Parameters:
protocol- the new active connection- Throws:
SQLException
-
reconnect
public void reconnect() throws SQLExceptionTry to reconnect connection.- Specified by:
reconnectin interfaceListener- Specified by:
reconnectin classAbstractMastersListener- Throws:
SQLException- if reconnect a new connection but there was an active transaction.
-
handleFailLoop
public void handleFailLoop()
Add listener to FailoverLoop if master connection is not active, so a reconnection will be done. (the reconnection will be done by failover or if append before by the next query/method that will use the failed connection) Remove listener from FailoverLoop is master connection is active.- Specified by:
handleFailLoopin classAbstractMastersListener
-
isMasterConnected
public boolean isMasterConnected()
-
checkMasterStatus
public boolean checkMasterStatus(SearchFilter searchFilter)
Check master status.- Specified by:
checkMasterStatusin interfaceListener- Specified by:
checkMasterStatusin classAbstractMastersListener- Parameters:
searchFilter- search filter- Returns:
- has some status changed
-
rePrepareOnSlave
public void rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult, boolean mustExecuteOnSlave)
-
reset
public void reset() throws SQLExceptionReset state of master connection.- Throws:
SQLException- if command fail.
-
-