FailoverConnectionProxy
Date: 2018-05-01

com.mysql.jdbc

## Class FailoverConnectionProxy

- java.lang.Object
- - com.mysql.jdbc.MultiHostConnectionProxy
  - - com.mysql.jdbc.FailoverConnectionProxy

- All Implemented Interfaces:
    java.lang.reflect.InvocationHandler

      public class FailoverConnectionProxy
      extends MultiHostConnectionProxy

  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 Classes
    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.

    - ### Nested classes/interfaces inherited from class com.mysql.jdbc.MultiHostConnectionProxy

      `MultiHostConnectionProxy.JdbcInterfaceProxy`

  - ### Field Summary

    - ### Fields inherited from class com.mysql.jdbc.MultiHostConnectionProxy

      `autoReconnect, closedExplicitly, closedReason, currentConnection, hostList, isClosed, lastExceptionDealtWith, localProps, proxyConnection, thisAsConnection`

  - ### Method Summary

    Methods
    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.
    `(package private) ConnectionImpl` | `createConnectionForHostIndex(int hostIndex)` Creates a new connection instance for host pointed out by the given host index.
    `static Connection` | `createProxyInstance(java.util.List<java.lang.String> hosts, java.util.Properties props)`
    `(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.
    `(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)` Instantiates a new JdbcInterfaceProxy for the given object.
    `(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` | `isMasterConnection()` Checks if current connection is to a master host.
    `(package private) boolean` | `isPrimaryHostIndex(int hostIndex)` Checks if the given host index points to the primary host.
    `(package private) void` | `pickNewConnection()` Picks the "best" connection to use from now on.
    `(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 'queriesBeforeRetryMaster' and 'secondsBeforeRetryMaster'.
    `(package private) boolean` | `shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)` Checks if the given throwable should trigger a connection switch.

    - ### Methods inherited from class com.mysql.jdbc.MultiHostConnectionProxy

      `allowedOnClosedConnection, createConnectionForHost, dealWithInvocationException, getNewWrapperForThisAsConnection, getProxy, initializeHostsSpecs, invalidateConnection, invalidateCurrentConnection, invoke, propagateProxyDown, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionState, syncSessionState`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### createProxyInstance

          public static Connection createProxyInstance(java.util.List<java.lang.String> hosts,
                                       java.util.Properties props)
                                                throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### getNewJdbcInterfaceProxy

          MultiHostConnectionProxy.JdbcInterfaceProxy getNewJdbcInterfaceProxy(java.lang.Object toProxy)

      Description copied from class: `MultiHostConnectionProxy`
      Instantiates a new JdbcInterfaceProxy for the given object. Subclasses can override this to return instances of JdbcInterfaceProxy subclasses.
      Overrides:
        `getNewJdbcInterfaceProxy` in class `MultiHostConnectionProxy`
      Parameters:
        `toProxy` - The object instance to be proxied.
      Returns:
        The new InvocationHandler instance.

    - #### shouldExceptionTriggerConnectionSwitch

          boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)

      Description copied from class: `MultiHostConnectionProxy`
      Checks if the given throwable should trigger a connection switch.
      Specified by:
        `shouldExceptionTriggerConnectionSwitch` in class `MultiHostConnectionProxy`
      Parameters:
        `t` - The Throwable instance to analyze.

    - #### isMasterConnection

          boolean isMasterConnection()

      Checks if current connection is to a master host.
      Specified by:
        `isMasterConnection` in class `MultiHostConnectionProxy`

    - #### pickNewConnection

          void pickNewConnection()
                           throws java.sql.SQLException

      Description copied from class: `MultiHostConnectionProxy`
      Picks the "best" connection to use from now on. Each subclass needs to implement its connection switch strategy on it.
      Specified by:
        `pickNewConnection` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### createConnectionForHostIndex

          ConnectionImpl createConnectionForHostIndex(int hostIndex)
                                                throws java.sql.SQLException

      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:
        `java.sql.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

          void doClose()
                 throws java.sql.SQLException

      Closes current connection.
      Specified by:
        `doClose` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### doAbortInternal

          void doAbortInternal()
                         throws java.sql.SQLException

      Aborts current connection.
      Specified by:
        `doAbortInternal` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### doAbort

          void doAbort(java.util.concurrent.Executor executor)
                 throws java.sql.SQLException

      Aborts current connection using the given executor.
      Specified by:
        `doAbort` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### invokeMore

          public java.lang.Object invokeMore(java.lang.Object proxy,
                                    java.lang.reflect.Method method,
                                    java.lang.Object[] args)
                                      throws java.lang.Throwable

      Description copied from class: `MultiHostConnectionProxy`
      Continuation of the method invocation process, to be implemented within each subclass.
      Specified by:
        `invokeMore` in class `MultiHostConnectionProxy`
      Throws:
        `java.lang.Throwable`