Class FailoverConnectionProxy
java.lang.Object
com.mysql.jdbc.MultiHostConnectionProxy
com.mysql.jdbc.FailoverConnectionProxy
- All Implemented Interfaces:
InvocationHandler
A proxy for a dynamic com.mysql.jdbc.Connection implementation that provides failover features for list of hosts. Connection switching occurs on
communications related exceptions and/or user defined settings, namely when one of the conditions set in 'secondsBeforeRetryMaster' or
'queriesBeforeRetryMaster' is met.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classProxy class to intercept and deal with errors that may occur in any object bound to the current connection.Nested classes/interfaces inherited from class MultiHostConnectionProxy
MultiHostConnectionProxy.JdbcInterfaceProxy -
Field Summary
Fields inherited from class MultiHostConnectionProxy
autoReconnect, closedExplicitly, closedReason, currentConnection, hostList, isClosed, lastExceptionDealtWith, localProps, proxyConnection, thisAsConnection -
Method Summary
Modifier and TypeMethodDescription(package private) booleanChecks if this proxy is using the primary host in the underlying connection.(package private) booleanChecks if this proxy is using a secondary host in the underlying connection.(package private) ConnectionImplcreateConnectionForHostIndex(int hostIndex) Creates a new connection instance for host pointed out by the given host index.static ConnectioncreateProxyInstance(List<String> hosts, Properties props) (package private) voidAborts current connection using the given executor.(package private) voidAborts current connection.(package private) voiddoClose()Closes current connection.(package private) voidFalls back to primary host or keep current connection if primary not available.(package private) MultiHostConnectionProxy.JdbcInterfaceProxygetNewJdbcInterfaceProxy(Object toProxy) Instantiates a new JdbcInterfaceProxy for the given object.(package private) voidIncrements counter for query executions.invokeMore(Object proxy, Method method, Object[] args) Continuation of the method invocation process, to be implemented within each subclass.(package private) booleanChecks if there is a underlying connection for this proxy.(package private) booleanChecks if current connection is to a master host.(package private) booleanisPrimaryHostIndex(int hostIndex) Checks if the given host index points to the primary host.(package private) voidPicks the "best" connection to use from now on.(package private) booleanChecks if at least one of the required conditions to fall back to primary host is met, which is determined by the properties 'queriesBeforeRetryMaster' and 'secondsBeforeRetryMaster'.(package private) booleanChecks if the given throwable should trigger a connection switch.Methods inherited from class MultiHostConnectionProxy
allowedOnClosedConnection, createConnectionForHost, dealWithInvocationException, getNewWrapperForThisAsConnection, getProxy, initializeHostsSpecs, invalidateConnection, invalidateCurrentConnection, invoke, propagateProxyDown, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionState, syncSessionState
-
Method Details
-
createProxyInstance
public static Connection createProxyInstance(List<String> hosts, Properties props) throws SQLException - Throws:
SQLException
-
getNewJdbcInterfaceProxy
Description copied from class:MultiHostConnectionProxyInstantiates a new JdbcInterfaceProxy for the given object. Subclasses can override this to return instances of JdbcInterfaceProxy subclasses.- Overrides:
getNewJdbcInterfaceProxyin classMultiHostConnectionProxy- Parameters:
toProxy- The object instance to be proxied.- Returns:
- The new InvocationHandler instance.
-
shouldExceptionTriggerConnectionSwitch
Description copied from class:MultiHostConnectionProxyChecks if the given throwable should trigger a connection switch.- Specified by:
shouldExceptionTriggerConnectionSwitchin classMultiHostConnectionProxy- Parameters:
t- The Throwable instance to analyze.
-
isMasterConnection
boolean isMasterConnection()Checks if current connection is to a master host.- Specified by:
isMasterConnectionin classMultiHostConnectionProxy
-
pickNewConnection
Description copied from class:MultiHostConnectionProxyPicks the "best" connection to use from now on. Each subclass needs to implement its connection switch strategy on it.- Specified by:
pickNewConnectionin classMultiHostConnectionProxy- Throws:
SQLException
-
createConnectionForHostIndex
Creates a new connection instance for host pointed out by the given host index.- Parameters:
hostIndex- The host index in the global hosts list.- Returns:
- The new connection instance.
- Throws:
SQLException
-
fallBackToPrimaryIfAvailable
void fallBackToPrimaryIfAvailable()Falls back to primary host or keep current connection if primary not available. -
incrementQueriesIssuedSinceFailover
void incrementQueriesIssuedSinceFailover()Increments counter for query executions. -
readyToFallBackToPrimaryHost
boolean readyToFallBackToPrimaryHost()Checks if at least one of the required conditions to fall back to primary host is met, which is determined by the properties 'queriesBeforeRetryMaster' and 'secondsBeforeRetryMaster'. -
isConnected
boolean isConnected()Checks if there is a underlying connection for this proxy. -
isPrimaryHostIndex
boolean isPrimaryHostIndex(int hostIndex) Checks if the given host index points to the primary host.- Parameters:
hostIndex- The host index in the global hosts list.
-
connectedToPrimaryHost
boolean connectedToPrimaryHost()Checks if this proxy is using the primary host in the underlying connection. -
connectedToSecondaryHost
boolean connectedToSecondaryHost()Checks if this proxy is using a secondary host in the underlying connection. -
doClose
Closes current connection.- Specified by:
doClosein classMultiHostConnectionProxy- Throws:
SQLException
-
doAbortInternal
Aborts current connection.- Specified by:
doAbortInternalin classMultiHostConnectionProxy- Throws:
SQLException
-
doAbort
Aborts current connection using the given executor.- Specified by:
doAbortin classMultiHostConnectionProxy- Throws:
SQLException
-
invokeMore
Description copied from class:MultiHostConnectionProxyContinuation of the method invocation process, to be implemented within each subclass.- Specified by:
invokeMorein classMultiHostConnectionProxy- Throws:
Throwable
-