类 ReplicationConnectionProxy
- java.lang.Object
-
- com.mysql.cj.jdbc.ha.MultiHostConnectionProxy
-
- com.mysql.cj.jdbc.ha.ReplicationConnectionProxy
-
- 所有已实现的接口:
PingTarget,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.
-
-
字段概要
字段 修饰符和类型 字段 说明 protected booleanallowMasterDownConnectionsprotected booleanallowSlaveDownConnectionsprotected booleanenableJMXprotected LoadBalancedConnectionmasterConnectionprotected booleanreadFromMasterWhenNoSlavesprotected booleanreadFromMasterWhenNoSlavesOriginalprotected booleanreadOnlyprotected LoadBalancedConnectionslavesConnection-
从类继承的字段 com.mysql.cj.jdbc.ha.MultiHostConnectionProxy
connectionUrl, lastExceptionDealtWith
-
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddSlaveHost(String hostPortPair)static ReplicationConnectioncreateProxyInstance(ConnectionUrl connectionUrl)Static factory to createReplicationConnectioninstances.voiddoPing()Pings both l/b connections.longgetConnectionGroupId()JdbcConnectiongetCurrentConnection()JdbcConnectiongetMasterConnection()JdbcConnectiongetSlavesConnection()booleanisHostMaster(String hostPortPair)booleanisHostSlave(String hostPortPair)booleanisMasterConnection()Checks if current connection is the masters l/b connection.booleanisReadOnly()booleanisSlavesConnection()Checks if current connection is the slaves l/b connection.voidpromoteSlaveToMaster(String hostPortPair)protected voidpropagateProxyDown(JdbcConnection proxyConn)Propagates the connection proxy down through all live connections.voidremoveMasterHost(String hostPortPair)voidremoveMasterHost(String hostPortPair, boolean waitUntilNotInUse)voidremoveMasterHost(String hostPortPair, boolean waitUntilNotInUse, boolean isNowSlave)voidremoveSlave(String hostPortPair)voidremoveSlave(String hostPortPair, boolean closeGently)voidsetReadOnly(boolean readOnly)-
从类继承的方法 com.mysql.cj.jdbc.ha.MultiHostConnectionProxy
allowedOnClosedConnection, getParentProxy, getProxy, invoke, setProxy
-
-
-
-
字段详细资料
-
enableJMX
protected boolean enableJMX
-
allowMasterDownConnections
protected boolean allowMasterDownConnections
-
allowSlaveDownConnections
protected boolean allowSlaveDownConnections
-
readFromMasterWhenNoSlaves
protected boolean readFromMasterWhenNoSlaves
-
readFromMasterWhenNoSlavesOriginal
protected boolean readFromMasterWhenNoSlavesOriginal
-
readOnly
protected boolean readOnly
-
masterConnection
protected LoadBalancedConnection masterConnection
-
slavesConnection
protected LoadBalancedConnection slavesConnection
-
-
方法详细资料
-
createProxyInstance
public static ReplicationConnection createProxyInstance(ConnectionUrl connectionUrl) throws SQLException
Static factory to createReplicationConnectioninstances.- 参数:
connectionUrl- The connection URL containing the hosts in a replication setup.- 返回:
- A
ReplicationConnectionproxy. - 抛出:
SQLException- if an error occurs
-
propagateProxyDown
protected void propagateProxyDown(JdbcConnection proxyConn)
Propagates the connection proxy down through all live connections.- 覆盖:
propagateProxyDown在类中MultiHostConnectionProxy- 参数:
proxyConn- The top level connection in the multi-host connections chain.
-
isMasterConnection
public boolean isMasterConnection()
Checks if current connection is the masters l/b connection.
-
isSlavesConnection
public boolean isSlavesConnection()
Checks if current connection is the slaves l/b connection.- 返回:
- true if current connection is the slaves l/b connection
-
doPing
public void doPing() throws SQLExceptionPings both l/b connections. Switch to another connection in case of failure.- 指定者:
doPing在接口中PingTarget- 抛出:
SQLException
-
getCurrentConnection
public JdbcConnection getCurrentConnection()
-
getConnectionGroupId
public long getConnectionGroupId()
-
getMasterConnection
public JdbcConnection getMasterConnection()
-
promoteSlaveToMaster
public void promoteSlaveToMaster(String hostPortPair) throws SQLException
- 抛出:
SQLException
-
removeMasterHost
public void removeMasterHost(String hostPortPair) throws SQLException
- 抛出:
SQLException
-
removeMasterHost
public void removeMasterHost(String hostPortPair, boolean waitUntilNotInUse) throws SQLException
- 抛出:
SQLException
-
removeMasterHost
public void removeMasterHost(String hostPortPair, boolean waitUntilNotInUse, boolean isNowSlave) throws SQLException
- 抛出:
SQLException
-
isHostMaster
public boolean isHostMaster(String hostPortPair)
-
getSlavesConnection
public JdbcConnection getSlavesConnection()
-
addSlaveHost
public void addSlaveHost(String hostPortPair) throws SQLException
- 抛出:
SQLException
-
removeSlave
public void removeSlave(String hostPortPair) throws SQLException
- 抛出:
SQLException
-
removeSlave
public void removeSlave(String hostPortPair, boolean closeGently) throws SQLException
- 抛出:
SQLException
-
isHostSlave
public boolean isHostSlave(String hostPortPair)
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLException- 抛出:
SQLException
-
isReadOnly
public boolean isReadOnly() throws SQLException- 抛出:
SQLException
-
-