public abstract class AbstractMastersListener extends java.lang.Object implements Listener
| Modifier and Type | Field and Description |
|---|---|
private static java.util.concurrent.ConcurrentMap<HostAddress,java.lang.Long> |
blacklist
List the recent failedConnection.
|
private static ConnectionValidator |
connectionValidationLoop |
protected java.util.concurrent.atomic.AtomicInteger |
currentConnectionAttempts |
protected Protocol |
currentProtocol |
protected boolean |
currentReadOnlyAsked |
protected java.util.concurrent.atomic.AtomicBoolean |
explicitClosed |
protected GlobalStateInfo |
globalInfo |
protected long |
lastQueryNanos |
protected long |
lastRetry |
private static Logger |
logger |
private java.util.concurrent.atomic.AtomicBoolean |
masterHostFail |
private long |
masterHostFailNanos |
protected FailoverProxy |
proxy |
UrlParser |
urlParser |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractMastersListener(UrlParser urlParser,
GlobalStateInfo globalInfo) |
| Modifier and Type | Method and Description |
|---|---|
void |
abortConnection(Protocol protocol)
Utility to force close existing connection.
|
void |
addToBlacklist(HostAddress hostAddress)
After a failover, put the hostAddress in a static list so the other connection will not take
this host in account for a time.
|
boolean |
canRetryFailLoop() |
abstract boolean |
checkMasterStatus(SearchFilter searchFilter) |
static void |
clearBlacklist()
Clear blacklist data.
|
void |
closeConnection(Protocol protocol)
Utility to close existing connection.
|
java.util.Set<HostAddress> |
getBlacklistKeys() |
java.lang.String |
getCatalog() |
Protocol |
getCurrentProtocol() |
SearchFilter |
getFilterForFailedHost() |
long |
getLastQueryNanos() |
int |
getMajorServerVersion() |
long |
getMasterHostFailNanos() |
FailoverProxy |
getProxy() |
int |
getRetriesAllDown() |
int |
getTimeout() |
UrlParser |
getUrlParser() |
abstract void |
handleFailLoop() |
HandleErrorResult |
handleFailover(java.sql.SQLException qe,
java.lang.reflect.Method method,
java.lang.Object[] args,
Protocol protocol,
boolean isClosed)
Call when a failover is detected on master connection.
|
boolean |
hasHostFail() |
void |
initializeConnection()
Initialize Listener.
|
boolean |
inTransaction() |
java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object[] args) |
java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object[] args,
Protocol specificProtocol) |
boolean |
isAutoReconnect() |
boolean |
isClosed() |
boolean |
isExplicitClosed() |
boolean |
isMasterConnection() |
boolean |
isMasterHostFail() |
boolean |
isQueryRelaunchable(java.lang.reflect.Method method,
java.lang.Object[] args)
Check if query can be re-executed.
|
boolean |
isReadOnly() |
boolean |
isServerMariaDb() |
boolean |
isValid(int timeout) |
boolean |
noBackslashEscapes() |
protected boolean |
pingMasterProtocol(Protocol protocol) |
protected void |
preAutoReconnect() |
abstract void |
preClose() |
abstract void |
preExecute() |
abstract HandleErrorResult |
primaryFail(java.lang.reflect.Method method,
java.lang.Object[] args,
boolean killCmd,
boolean isClosed) |
void |
prolog(long maxRows,
MariaDbConnection connection,
MariaDbStatement statement) |
abstract void |
reconnect() |
abstract void |
reconnectFailedConnection(SearchFilter filter) |
HandleErrorResult |
relaunchOperation(java.lang.reflect.Method method,
java.lang.Object[] args)
After a failover that has bean done, relaunch the operation that was in progress.
|
void |
removeFromBlacklist(HostAddress hostAddress)
After a successfull connection, permit to remove a hostAddress from blacklist.
|
protected void |
removeListenerFromSchedulers() |
protected void |
resetMasterFailoverData() |
void |
resetOldsBlackListHosts()
Permit to remove Host to blacklist after loadBalanceBlacklistTimeout seconds.
|
boolean |
sessionStateAware() |
boolean |
setMasterHostFail()
Set master fail variables.
|
void |
setProxy(FailoverProxy proxy) |
protected void |
setSessionReadOnly(boolean readOnly,
Protocol protocol) |
abstract void |
switchReadOnlyConnection(java.lang.Boolean readonly) |
void |
syncConnection(Protocol from,
Protocol to)
When switching between 2 connections, report existing connection parameter to the new used
connection.
|
void |
throwFailoverMessage(HostAddress failHostAddress,
boolean wasMaster,
java.sql.SQLException queryException,
boolean reconnected)
Throw a human readable message after a failoverException.
|
boolean |
versionGreaterOrEqual(int major,
int minor,
int patch) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfoundActiveMaster, getServerThreadId, isMasterConnected, preAbort, rePrepareOnReplica, resetprivate static final java.util.concurrent.ConcurrentMap<HostAddress,java.lang.Long> blacklist
private static final ConnectionValidator connectionValidationLoop
private static final Logger logger
public final UrlParser urlParser
protected final java.util.concurrent.atomic.AtomicInteger currentConnectionAttempts
protected final java.util.concurrent.atomic.AtomicBoolean explicitClosed
protected final GlobalStateInfo globalInfo
private final java.util.concurrent.atomic.AtomicBoolean masterHostFail
protected volatile boolean currentReadOnlyAsked
protected Protocol currentProtocol
protected FailoverProxy proxy
protected long lastRetry
protected long lastQueryNanos
private volatile long masterHostFailNanos
protected AbstractMastersListener(UrlParser urlParser, GlobalStateInfo globalInfo)
public static void clearBlacklist()
public void initializeConnection()
throws java.sql.SQLException
initializeConnection in interface Listenerjava.sql.SQLException - if any exception occur.protected void removeListenerFromSchedulers()
protected void preAutoReconnect()
throws java.sql.SQLException
java.sql.SQLExceptionpublic FailoverProxy getProxy()
public void setProxy(FailoverProxy proxy)
public java.util.Set<HostAddress> getBlacklistKeys()
getBlacklistKeys in interface Listenerpublic HandleErrorResult handleFailover(java.sql.SQLException qe, java.lang.reflect.Method method, java.lang.Object[] args, Protocol protocol, boolean isClosed) throws java.sql.SQLException
handleFailover in interface Listenermethod - called methodargs - methods parametersprotocol - current protocoljava.sql.SQLException - when method and parameters does not exist.public void addToBlacklist(HostAddress hostAddress)
addToBlacklist in interface ListenerhostAddress - the HostAddress to add to blacklistpublic void removeFromBlacklist(HostAddress hostAddress)
removeFromBlacklist in interface ListenerhostAddress - the host address tho be remove of blacklistpublic void resetOldsBlackListHosts()
protected void resetMasterFailoverData()
protected void setSessionReadOnly(boolean readOnly,
Protocol protocol)
throws java.sql.SQLException
java.sql.SQLExceptionpublic abstract void handleFailLoop()
public Protocol getCurrentProtocol()
getCurrentProtocol in interface Listenerpublic long getMasterHostFailNanos()
public boolean setMasterHostFail()
setMasterHostFail in interface Listenerpublic boolean isMasterHostFail()
isMasterHostFail in interface Listenerpublic boolean hasHostFail()
hasHostFail in interface Listenerpublic SearchFilter getFilterForFailedHost()
getFilterForFailedHost in interface Listenerpublic HandleErrorResult relaunchOperation(java.lang.reflect.Method method, java.lang.Object[] args) throws java.sql.SQLException
method - the method accessedargs - the parametersjava.sql.SQLException - if there is any error relaunching initial methodpublic boolean isQueryRelaunchable(java.lang.reflect.Method method,
java.lang.Object[] args)
method - invoke methodargs - invoke argumentspublic java.lang.Object invoke(java.lang.reflect.Method method,
java.lang.Object[] args,
Protocol specificProtocol)
throws java.lang.Throwable
public java.lang.Object invoke(java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
public void syncConnection(Protocol from, Protocol to) throws java.sql.SQLException
syncConnection in interface Listenerfrom - used connectionto - will-be-current connectionjava.sql.SQLException - if catalog cannot be setpublic boolean versionGreaterOrEqual(int major,
int minor,
int patch)
versionGreaterOrEqual in interface Listenerpublic boolean isServerMariaDb()
isServerMariaDb in interface Listenerpublic boolean sessionStateAware()
sessionStateAware in interface Listenerpublic boolean noBackslashEscapes()
noBackslashEscapes in interface Listenerpublic int getMajorServerVersion()
getMajorServerVersion in interface Listenerpublic boolean isValid(int timeout)
throws java.sql.SQLException
public boolean isReadOnly()
isReadOnly in interface Listenerpublic boolean inTransaction()
inTransaction in interface Listenerpublic boolean isMasterConnection()
isMasterConnection in interface Listenerpublic boolean isExplicitClosed()
isExplicitClosed in interface Listenerpublic int getRetriesAllDown()
getRetriesAllDown in interface Listenerpublic boolean isAutoReconnect()
isAutoReconnect in interface Listenerpublic UrlParser getUrlParser()
getUrlParser in interface Listenerpublic abstract void preExecute()
throws java.sql.SQLException
preExecute in interface Listenerjava.sql.SQLExceptionpublic abstract void reconnectFailedConnection(SearchFilter filter) throws java.sql.SQLException
reconnectFailedConnection in interface Listenerjava.sql.SQLExceptionpublic abstract void switchReadOnlyConnection(java.lang.Boolean readonly)
throws java.sql.SQLException
switchReadOnlyConnection in interface Listenerjava.sql.SQLExceptionpublic abstract HandleErrorResult primaryFail(java.lang.reflect.Method method, java.lang.Object[] args, boolean killCmd, boolean isClosed) throws java.sql.SQLException
primaryFail in interface Listenerjava.sql.SQLExceptionpublic void throwFailoverMessage(HostAddress failHostAddress, boolean wasMaster, java.sql.SQLException queryException, boolean reconnected) throws java.sql.SQLException
throwFailoverMessage in interface ListenerfailHostAddress - failedHostAddresswasMaster - was failed connection masterqueryException - internal errorreconnected - connection statusjava.sql.SQLException - error with failover informationpublic boolean canRetryFailLoop()
canRetryFailLoop in interface Listenerpublic void prolog(long maxRows,
MariaDbConnection connection,
MariaDbStatement statement)
throws java.sql.SQLException
public java.lang.String getCatalog()
throws java.sql.SQLException
getCatalog in interface Listenerjava.sql.SQLExceptionpublic int getTimeout()
throws java.net.SocketException
getTimeout in interface Listenerjava.net.SocketExceptionpublic abstract void reconnect()
throws java.sql.SQLException
public abstract boolean checkMasterStatus(SearchFilter searchFilter)
checkMasterStatus in interface Listenerpublic long getLastQueryNanos()
getLastQueryNanos in interface Listenerprotected boolean pingMasterProtocol(Protocol protocol)
public void closeConnection(Protocol protocol)
protocol - connection to close.public void abortConnection(Protocol protocol)
protocol - connection to close.