Package com.mysql.cj.jdbc.ha
Class FailoverConnectionProxy
java.lang.Object
com.mysql.cj.jdbc.ha.MultiHostConnectionProxy
com.mysql.cj.jdbc.ha.FailoverConnectionProxy
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
public class FailoverConnectionProxy extends MultiHostConnectionProxy
A proxy for a dynamic com.mysql.cj.jdbc.JdbcConnection 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 'secondsBeforeRetrySource' or
'queriesBeforeRetrySource' is met.
-
Field Summary
Fields inherited from class com.mysql.cj.jdbc.ha.MultiHostConnectionProxy
autoReconnect, closedExplicitly, closedReason, connectionUrl, currentConnection, hostsList, isClosed, lastExceptionDealtWith, thisAsConnection -
Method Summary
Modifier and Type Method Description static JdbcConnectioncreateProxyInstance(ConnectionUrl connectionUrl)protected voiddoAbort(java.util.concurrent.Executor executor)Aborts current connection using the given executor.protected voiddoAbortInternal()Aborts current connection.protected voiddoClose()Closes current connection.protected com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.JdbcInterfaceProxygetNewJdbcInterfaceProxy(java.lang.Object toProxy)Gets locally bound instances of FailoverJdbcInterfaceProxy.java.lang.ObjectinvokeMore(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)Continuation of the method invocation process, to be implemented within each subclass.protected booleanisSourceConnection()Checks if current connection is to a source host.protected voidpickNewConnection()Picks the "best" connection to use from now on.protected booleanshouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)Checks if the given throwable should trigger a connection switch.Methods inherited from class com.mysql.cj.jdbc.ha.MultiHostConnectionProxy
allowedOnClosedConnection, createConnectionForHost, dealWithInvocationException, getParentProxy, getProxy, invalidateConnection, invalidateCurrentConnection, invoke, propagateProxyDown, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionState
-
Method Details
-
createProxyInstance
public static JdbcConnection createProxyInstance(ConnectionUrl connectionUrl) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getNewJdbcInterfaceProxy
protected com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.JdbcInterfaceProxy getNewJdbcInterfaceProxy(java.lang.Object toProxy)Gets locally bound instances of FailoverJdbcInterfaceProxy.- Overrides:
getNewJdbcInterfaceProxyin classMultiHostConnectionProxy- Parameters:
toProxy- The object instance to be proxied.- Returns:
- The new InvocationHandler instance.
-
shouldExceptionTriggerConnectionSwitch
protected boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)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.- Returns:
- true if the given throwable should trigger a connection switch
-
isSourceConnection
protected boolean isSourceConnection()Checks if current connection is to a source host.- Specified by:
isSourceConnectionin classMultiHostConnectionProxy- Returns:
- true if current connection is to a source host
-
pickNewConnection
protected void pickNewConnection() throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- if an error occurs
-
doClose
protected void doClose() throws java.sql.SQLExceptionCloses current connection.- Specified by:
doClosein classMultiHostConnectionProxy- Throws:
java.sql.SQLException- if an error occurs
-
doAbortInternal
protected void doAbortInternal() throws java.sql.SQLExceptionAborts current connection.- Specified by:
doAbortInternalin classMultiHostConnectionProxy- Throws:
java.sql.SQLException- if an error occurs
-
doAbort
protected void doAbort(java.util.concurrent.Executor executor) throws java.sql.SQLExceptionAborts current connection using the given executor.- Specified by:
doAbortin classMultiHostConnectionProxy- Parameters:
executor- executor- Throws:
java.sql.SQLException- if an error occurs
-
invokeMore
public java.lang.Object invokeMore(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.ThrowableDescription copied from class:MultiHostConnectionProxyContinuation of the method invocation process, to be implemented within each subclass.- Specified by:
invokeMorein classMultiHostConnectionProxy- Parameters:
proxy- proxy objectmethod- method to invokeargs- method parameters- Returns:
- method result
- Throws:
java.lang.Throwable- if an error occurs
-