ReplicationConnectionProxy
Date: 2018-05-01

com.mysql.jdbc

## Class ReplicationConnectionProxy

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

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

      public class ReplicationConnectionProxy
      extends MultiHostConnectionProxy
      implements PingTarget

  Connection that opens two connections, one two a replication master, and another to one or more slaves, and decides to use master when the connection is not read-only, and use slave(s) when the connection is read-only.

- - ### Nested Class Summary

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

      `MultiHostConnectionProxy.JdbcInterfaceProxy`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `allowMasterDownConnections`
    `protected boolean` | `allowSlaveDownConnections`
    `(package private) ReplicationConnectionGroup` | `connectionGroup`
    `protected boolean` | `enableJMX`
    `protected LoadBalancedConnection` | `masterConnection`
    `protected boolean` | `readFromMasterWhenNoSlaves`
    `protected boolean` | `readFromMasterWhenNoSlavesOriginal`
    `protected boolean` | `readOnly`
    `protected LoadBalancedConnection` | `slavesConnection`

    - ### 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
    --- | ---
    `void` | `addSlaveHost(java.lang.String host)`
    `static ReplicationConnection` | `createProxyInstance(java.util.List<java.lang.String> masterHostList, java.util.Properties masterProperties, java.util.List<java.lang.String> slaveHostList, java.util.Properties slaveProperties)`
    `(package private) void` | `doAbort(java.util.concurrent.Executor executor)` Executes a abort() invocation;
    `(package private) void` | `doAbortInternal()` Executes a abortInternal() invocation;
    `(package private) void` | `doClose()` Executes a close() invocation;
    `void` | `doPing()` Pings both l/b connections.
    `long` | `getConnectionGroupId()`
    `Connection` | `getCurrentConnection()`
    `Connection` | `getMasterConnection()`
    `(package private) MySQLConnection` | `getNewWrapperForThisAsConnection()` Wraps this object with a new replication Connection instance.
    `Connection` | `getSlavesConnection()`
    `(package private) java.lang.Object` | `invokeMore(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)` Proxies method invocation on the java.sql.Connection interface.
    `boolean` | `isHostMaster(java.lang.String host)`
    `boolean` | `isHostSlave(java.lang.String host)`
    `boolean` | `isMasterConnection()` Checks if current connection is the masters l/b connection.
    `boolean` | `isReadOnly()`
    `boolean` | `isSlavesConnection()` Checks if current connection is the slaves l/b connection.
    `(package private) void` | `pickNewConnection()` Picks the "best" connection to use from now on.
    `void` | `promoteSlaveToMaster(java.lang.String host)`
    `protected void` | `propagateProxyDown(MySQLConnection proxyConn)` Propagates the connection proxy down through all live connections.
    `void` | `removeMasterHost(java.lang.String host)`
    `void` | `removeMasterHost(java.lang.String host, boolean waitUntilNotInUse)`
    `void` | `removeMasterHost(java.lang.String host, boolean waitUntilNotInUse, boolean isNowSlave)`
    `void` | `removeSlave(java.lang.String host)`
    `void` | `removeSlave(java.lang.String host, boolean closeGently)`
    `void` | `setReadOnly(boolean readOnly)`
    `(package private) boolean` | `shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)` Has no use in replication connections.

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

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

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

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

- - ### Field Detail

    - #### enableJMX

          protected boolean enableJMX

    - #### allowMasterDownConnections

          protected boolean allowMasterDownConnections

    - #### allowSlaveDownConnections

          protected boolean allowSlaveDownConnections

    - #### readFromMasterWhenNoSlaves

          protected boolean readFromMasterWhenNoSlaves

    - #### readFromMasterWhenNoSlavesOriginal

          protected boolean readFromMasterWhenNoSlavesOriginal

    - #### readOnly

          protected boolean readOnly

    - #### connectionGroup

          ReplicationConnectionGroup connectionGroup

    - #### masterConnection

          protected LoadBalancedConnection masterConnection

    - #### slavesConnection

          protected LoadBalancedConnection slavesConnection

  - ### Method Detail

    - #### createProxyInstance

          public static ReplicationConnection createProxyInstance(java.util.List<java.lang.String> masterHostList,
                                                  java.util.Properties masterProperties,
                                                  java.util.List<java.lang.String> slaveHostList,
                                                  java.util.Properties slaveProperties)
                                                           throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### getNewWrapperForThisAsConnection

          MySQLConnection getNewWrapperForThisAsConnection()
                                                     throws java.sql.SQLException

      Wraps this object with a new replication Connection instance.
      Overrides:
        `getNewWrapperForThisAsConnection` in class `MultiHostConnectionProxy`
      Returns:
        The connection object instance that wraps 'this'.
      Throws:
        `java.sql.SQLException`

    - #### propagateProxyDown

          protected void propagateProxyDown(MySQLConnection proxyConn)

      Propagates the connection proxy down through all live connections.
      Overrides:
        `propagateProxyDown` in class `MultiHostConnectionProxy`
      Parameters:
        `proxyConn` - The top level connection in the multi-host connections chain.

    - #### shouldExceptionTriggerConnectionSwitch

          boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)

      Has no use in replication connections. Always return `false`.
      Specified by:
        `shouldExceptionTriggerConnectionSwitch` in class `MultiHostConnectionProxy`
      Parameters:
        `ex` - The Exception instance to check.

    - #### isMasterConnection

          public boolean isMasterConnection()

      Checks if current connection is the masters l/b connection.
      Specified by:
        `isMasterConnection` in class `MultiHostConnectionProxy`

    - #### isSlavesConnection

          public boolean isSlavesConnection()

      Checks if current connection is the slaves l/b connection.

    - #### 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`

    - #### doClose

          void doClose()
                 throws java.sql.SQLException

      Description copied from class: `MultiHostConnectionProxy`
      Executes a close() invocation;
      Specified by:
        `doClose` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### doAbortInternal

          void doAbortInternal()
                         throws java.sql.SQLException

      Description copied from class: `MultiHostConnectionProxy`
      Executes a abortInternal() invocation;
      Specified by:
        `doAbortInternal` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### doAbort

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

      Description copied from class: `MultiHostConnectionProxy`
      Executes a abort() invocation;
      Specified by:
        `doAbort` in class `MultiHostConnectionProxy`
      Throws:
        `java.sql.SQLException`

    - #### invokeMore

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

      Proxies method invocation on the java.sql.Connection interface. This is the continuation of MultiHostConnectionProxy#invoke(Object, Method, Object[]).
      Specified by:
        `invokeMore` in class `MultiHostConnectionProxy`
      Throws:
        `java.lang.Throwable`

    - #### doPing

          public void doPing()
                      throws java.sql.SQLException

      Pings both l/b connections. Switch to another connection in case of failure.
      Specified by:
        `doPing` in interface `PingTarget`
      Throws:
        `java.sql.SQLException`

    - #### getCurrentConnection

          public Connection getCurrentConnection()

    - #### getConnectionGroupId

          public long getConnectionGroupId()

    - #### getMasterConnection

          public Connection getMasterConnection()

    - #### promoteSlaveToMaster

          public void promoteSlaveToMaster(java.lang.String host)
                                    throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### removeMasterHost

          public void removeMasterHost(java.lang.String host)
                                throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### removeMasterHost

          public void removeMasterHost(java.lang.String host,
                              boolean waitUntilNotInUse)
                                throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### removeMasterHost

          public void removeMasterHost(java.lang.String host,
                              boolean waitUntilNotInUse,
                              boolean isNowSlave)
                                throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### isHostMaster

          public boolean isHostMaster(java.lang.String host)

    - #### getSlavesConnection

          public Connection getSlavesConnection()

    - #### addSlaveHost

          public void addSlaveHost(java.lang.String host)
                            throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### removeSlave

          public void removeSlave(java.lang.String host)
                           throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### removeSlave

          public void removeSlave(java.lang.String host,
                         boolean closeGently)
                           throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### isHostSlave

          public boolean isHostSlave(java.lang.String host)

    - #### setReadOnly

          public void setReadOnly(boolean readOnly)
                           throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### isReadOnly

          public boolean isReadOnly()
                             throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`