public class FailoverConnectionProxy extends MultiHostConnectionProxy
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
FailoverConnectionProxy.FailoverJdbcInterfaceProxy
Proxy class to intercept and deal with errors that may occur in any object bound to the current connection.
|
MultiHostConnectionProxy.JdbcInterfaceProxy| Modifier and Type | Field and Description |
|---|---|
private int |
currentHostIndex |
private static int |
DEFAULT_PRIMARY_HOST_INDEX |
private boolean |
enableFallBackToPrimaryHost |
private boolean |
explicitlyAutoCommit |
private java.lang.Boolean |
explicitlyReadOnly |
private boolean |
failoverReadOnly |
private static java.lang.String |
METHOD_COMMIT |
private static java.lang.String |
METHOD_ROLLBACK |
private static java.lang.String |
METHOD_SET_AUTO_COMMIT |
private static java.lang.String |
METHOD_SET_READ_ONLY |
private static int |
NO_CONNECTION_INDEX |
private long |
primaryHostFailTimeMillis |
private int |
primaryHostIndex |
private long |
queriesBeforeRetryPrimaryHost |
private long |
queriesIssuedSinceFailover |
private int |
retriesAllDown |
private int |
secondsBeforeRetryPrimaryHost |
autoReconnect, closedExplicitly, closedReason, connectionUrl, currentConnection, hostsList, isClosed, lastExceptionDealtWith, parentProxyConnection, thisAsConnection, topProxyConnection| Modifier | Constructor and Description |
|---|---|
private |
FailoverConnectionProxy(ConnectionUrl connectionUrl)
Instantiates a new FailoverConnectionProxy for the given list of hosts and connection properties.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) boolean |
connectedToPrimaryHost()
Checks if this proxy is using the primary host in the underlying connection.
|
(package private) boolean |
connectedToSecondaryHost()
Checks if this proxy is using a secondary host in the underlying connection.
|
private void |
connectTo(int hostIndex)
Connects this dynamic failover connection proxy to the host pointed out by the given host index.
|
(package private) ConnectionImpl |
createConnectionForHostIndex(int hostIndex)
Creates a new connection instance for host pointed out by the given host index.
|
static JdbcConnection |
createProxyInstance(ConnectionUrl connectionUrl) |
(package private) void |
doAbort(java.util.concurrent.Executor executor)
Aborts current connection using the given executor.
|
(package private) void |
doAbortInternal()
Aborts current connection.
|
(package private) void |
doClose()
Closes current connection.
|
private void |
failOver()
Initiates a default failover procedure starting at the current connection host index.
|
private void |
failOver(int failedHostIdx)
Initiates a default failover procedure starting at the given host index.
|
(package private) void |
fallBackToPrimaryIfAvailable()
Falls back to primary host or keep current connection if primary not available.
|
(package private) MultiHostConnectionProxy.JdbcInterfaceProxy |
getNewJdbcInterfaceProxy(java.lang.Object toProxy)
Gets locally bound instances of FailoverJdbcInterfaceProxy.
|
(package private) void |
incrementQueriesIssuedSinceFailover()
Increments counter for query executions.
|
java.lang.Object |
invokeMore(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.
|
(package private) boolean |
isConnected()
Checks if there is a underlying connection for this proxy.
|
(package private) boolean |
isPrimaryHostIndex(int hostIndex)
Checks if the given host index points to the primary host.
|
(package private) boolean |
isSourceConnection()
Checks if current connection is to a source host.
|
private int |
nextHost(int currHostIdx,
boolean vouchForPrimaryHost)
Gets the next host on the hosts list.
|
(package private) void |
pickNewConnection()
Picks the "best" connection to use from now on.
|
private boolean |
queriesBeforeRetryPrimaryHostIsMet()
Checks the condition set by the property 'queriesBeforeRetrySource'.
|
(package private) 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 'queriesBeforeRetrySource'
and 'secondsBeforeRetrySource'.
|
private void |
resetAutoFallBackCounters()
Resets auto-fall back counters.
|
private boolean |
secondsBeforeRetryPrimaryHostIsMet()
Checks the condition set by the property 'secondsBeforeRetrySource'.
|
(package private) boolean |
shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
Checks if the given throwable should trigger a connection switch.
|
private void |
switchCurrentConnectionTo(int hostIndex,
JdbcConnection connection)
Replaces the previous underlying connection by the connection given.
|
allowedOnClosedConnection, createConnectionForHost, dealWithInvocationException, getNewWrapperForThisAsConnection, getParentProxy, getProxy, initializeHostsSpecs, invalidateConnection, invalidateCurrentConnection, invoke, isMasterConnection, propagateProxyDown, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionState, syncSessionStateprivate static final java.lang.String METHOD_SET_READ_ONLY
private static final java.lang.String METHOD_SET_AUTO_COMMIT
private static final java.lang.String METHOD_COMMIT
private static final java.lang.String METHOD_ROLLBACK
private static final int NO_CONNECTION_INDEX
private static final int DEFAULT_PRIMARY_HOST_INDEX
private int secondsBeforeRetryPrimaryHost
private long queriesBeforeRetryPrimaryHost
private boolean failoverReadOnly
private int retriesAllDown
private int currentHostIndex
private int primaryHostIndex
private java.lang.Boolean explicitlyReadOnly
private boolean explicitlyAutoCommit
private boolean enableFallBackToPrimaryHost
private long primaryHostFailTimeMillis
private long queriesIssuedSinceFailover
private FailoverConnectionProxy(ConnectionUrl connectionUrl) throws java.sql.SQLException
connectionUrl - ConnectionUrl instance containing the lists of hosts available to switch on.java.sql.SQLException - if an error occurspublic static JdbcConnection createProxyInstance(ConnectionUrl connectionUrl) throws java.sql.SQLException
java.sql.SQLExceptionMultiHostConnectionProxy.JdbcInterfaceProxy getNewJdbcInterfaceProxy(java.lang.Object toProxy)
getNewJdbcInterfaceProxy in class MultiHostConnectionProxytoProxy - The object instance to be proxied.boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
MultiHostConnectionProxyshouldExceptionTriggerConnectionSwitch in class MultiHostConnectionProxyt - The Throwable instance to analyze.boolean isSourceConnection()
isSourceConnection in class MultiHostConnectionProxyvoid pickNewConnection()
throws java.sql.SQLException
MultiHostConnectionProxypickNewConnection in class MultiHostConnectionProxyjava.sql.SQLException - if an error occursConnectionImpl createConnectionForHostIndex(int hostIndex) throws java.sql.SQLException
hostIndex - The host index in the global hosts list.java.sql.SQLException - if an error occursprivate void connectTo(int hostIndex)
throws java.sql.SQLException
hostIndex - The host index in the global hosts list.java.sql.SQLException - if an error occursprivate void switchCurrentConnectionTo(int hostIndex,
JdbcConnection connection)
throws java.sql.SQLException
hostIndex - The host index in the global hosts list that matches the given connection.connection - The connection instance to switch to.java.sql.SQLException - if an error occursprivate void failOver()
throws java.sql.SQLException
java.sql.SQLException - if an error occursprivate void failOver(int failedHostIdx)
throws java.sql.SQLException
failedHostIdx - The host index where to start from. First connection attempt will be the next one.java.sql.SQLException - if an error occursvoid fallBackToPrimaryIfAvailable()
private int nextHost(int currHostIdx,
boolean vouchForPrimaryHost)
currHostIdx - Current host index.vouchForPrimaryHost - Allows to return the primary host index even if the usual required conditions aren't met.void incrementQueriesIssuedSinceFailover()
boolean readyToFallBackToPrimaryHost()
boolean isConnected()
boolean isPrimaryHostIndex(int hostIndex)
hostIndex - The host index in the global hosts list.boolean connectedToPrimaryHost()
boolean connectedToSecondaryHost()
private boolean secondsBeforeRetryPrimaryHostIsMet()
private boolean queriesBeforeRetryPrimaryHostIsMet()
private void resetAutoFallBackCounters()
void doClose()
throws java.sql.SQLException
doClose in class MultiHostConnectionProxyjava.sql.SQLException - if an error occursvoid doAbortInternal()
throws java.sql.SQLException
doAbortInternal in class MultiHostConnectionProxyjava.sql.SQLException - if an error occursvoid doAbort(java.util.concurrent.Executor executor)
throws java.sql.SQLException
doAbort in class MultiHostConnectionProxyexecutor - executorjava.sql.SQLException - if an error occurspublic java.lang.Object invokeMore(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
MultiHostConnectionProxyinvokeMore in class MultiHostConnectionProxyproxy - proxy objectmethod - method to invokeargs - method parametersjava.lang.Throwable - if an error occurs