public class MastersFailoverListener extends AbstractMastersListener
Modifier and Type | Field and Description |
---|---|
private static Logger |
logger |
private HaMode |
mode |
currentConnectionAttempts, currentProtocol, currentReadOnlyAsked, explicitClosed, globalInfo, lastQueryNanos, lastRetry, proxy, urlParser
Constructor and Description |
---|
MastersFailoverListener(UrlParser urlParser,
GlobalStateInfo globalInfo)
Initialisation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkMasterStatus(SearchFilter searchFilter)
Check master status.
|
void |
foundActiveMaster(Protocol protocol)
method called when a new Master connection is found after a fallback.
|
long |
getServerThreadId() |
void |
handleFailLoop()
Add listener to FailoverLoop if master connection is not active, so a reconnection will be
done.
|
void |
initializeConnection()
Connect to database.
|
boolean |
isMasterConnected() |
void |
preAbort() |
void |
preClose() |
void |
preExecute()
Before executing query, reconnect if connection is closed, and autoReconnect option is set.
|
HandleErrorResult |
primaryFail(java.lang.reflect.Method method,
java.lang.Object[] args,
boolean killCmd) |
void |
reconnect()
Try to reconnect connection.
|
void |
reconnectFailedConnection(SearchFilter searchFilter)
Loop to connect failed hosts.
|
void |
rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult,
boolean mustExecuteOnSlave) |
void |
reset()
Reset state of master connection.
|
void |
switchReadOnlyConnection(java.lang.Boolean mustBeReadOnly)
Force session to read-only according to options.
|
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, isValid, noBackslashEscapes, pingMasterProtocol, preAutoReconnect, prolog, relaunchOperation, removeFromBlacklist, removeListenerFromSchedulers, resetMasterFailoverData, resetOldsBlackListHosts, sessionStateAware, setMasterHostFail, setProxy, setSessionReadOnly, syncConnection, throwFailoverMessage, versionGreaterOrEqual
public MastersFailoverListener(UrlParser urlParser, GlobalStateInfo globalInfo)
urlParser
- url options.globalInfo
- server global variables informationpublic void initializeConnection() throws java.sql.SQLException
initializeConnection
in interface Listener
initializeConnection
in class AbstractMastersListener
java.sql.SQLException
- if connection is on error.public void preExecute() throws java.sql.SQLException
preExecute
in interface Listener
preExecute
in class AbstractMastersListener
java.sql.SQLException
- if connection has been explicitly closed.public void preClose()
preClose
in interface Listener
preClose
in class AbstractMastersListener
public long getServerThreadId()
public void preAbort()
public HandleErrorResult primaryFail(java.lang.reflect.Method method, java.lang.Object[] args, boolean killCmd)
primaryFail
in interface Listener
primaryFail
in class AbstractMastersListener
public void reconnectFailedConnection(SearchFilter searchFilter) throws java.sql.SQLException
reconnectFailedConnection
in interface Listener
reconnectFailedConnection
in class AbstractMastersListener
searchFilter
- search parameters.java.sql.SQLException
- if there is any error during reconnectionpublic void switchReadOnlyConnection(java.lang.Boolean mustBeReadOnly) throws java.sql.SQLException
switchReadOnlyConnection
in interface Listener
switchReadOnlyConnection
in class AbstractMastersListener
mustBeReadOnly
- is read-only flagjava.sql.SQLException
- if a connection error occurpublic void foundActiveMaster(Protocol protocol) throws java.sql.SQLException
protocol
- the new active connectionjava.sql.SQLException
public void reconnect() throws java.sql.SQLException
reconnect
in interface Listener
reconnect
in class AbstractMastersListener
java.sql.SQLException
- if reconnect a new connection but there was an active transaction.public 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 mustExecuteOnSlave)
public void reset() throws java.sql.SQLException
java.sql.SQLException
- if command fail.