Class FailoverConnectionProxy

java.lang.Object
com.mysql.jdbc.MultiHostConnectionProxy
com.mysql.jdbc.FailoverConnectionProxy
All Implemented Interfaces:
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.
  • Method Details

    • createProxyInstance

      public static Connection createProxyInstance(List<String> hosts, Properties props) throws SQLException
      Throws:
      SQLException
    • getNewJdbcInterfaceProxy

      MultiHostConnectionProxy.JdbcInterfaceProxy getNewJdbcInterfaceProxy(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(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 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:
      SQLException
    • createConnectionForHostIndex

      ConnectionImpl createConnectionForHostIndex(int hostIndex) throws 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:
      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 SQLException
      Closes current connection.
      Specified by:
      doClose in class MultiHostConnectionProxy
      Throws:
      SQLException
    • doAbortInternal

      void doAbortInternal() throws SQLException
      Aborts current connection.
      Specified by:
      doAbortInternal in class MultiHostConnectionProxy
      Throws:
      SQLException
    • doAbort

      void doAbort(Executor executor) throws SQLException
      Aborts current connection using the given executor.
      Specified by:
      doAbort in class MultiHostConnectionProxy
      Throws:
      SQLException
    • invokeMore

      public Object invokeMore(Object proxy, Method method, Object[] args) throws 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:
      Throwable