public class LoadBalancedConnectionProxy extends MultiHostConnectionProxy implements PingTarget
MultiHostConnectionProxy.JdbcInterfaceProxy
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BLACKLIST_TIMEOUT_PROPERTY_KEY |
protected java.util.Map<java.lang.String,ConnectionImpl> |
liveConnections |
autoReconnect, closedExplicitly, closedReason, currentConnection, hostList, isClosed, lastExceptionDealtWith, localProps, proxyConnection, thisAsConnection
Modifier and Type | Method and Description |
---|---|
boolean |
addHost(java.lang.String host)
Adds a host to the hosts list.
|
void |
addToGlobalBlacklist(java.lang.String host)
Adds a host to the blacklist.
|
void |
addToGlobalBlacklist(java.lang.String host,
long timeout)
Adds a host to the blacklist with the given timeout.
|
ConnectionImpl |
createConnectionForHost(java.lang.String hostPortSpec)
Creates a new physical connection for the given host:port and updates required internal mappings and statistics for that connection.
|
static LoadBalancedConnection |
createProxyInstance(java.util.List<java.lang.String> hosts,
java.util.Properties props) |
(package private) void |
doAbort(java.util.concurrent.Executor executor)
Aborts all live connections, using the provided Executor.
|
(package private) void |
doAbortInternal()
Aborts all live connections
|
(package private) void |
doClose()
Closes all live connections.
|
void |
doPing()
Pings live connections.
|
long |
getActivePhysicalConnectionCount() |
long |
getConnectionGroupProxyID() |
java.lang.String |
getCurrentActiveHost() |
long |
getCurrentTransactionDuration() |
java.util.Map<java.lang.String,java.lang.Long> |
getGlobalBlacklist()
Returns a local hosts blacklist, or a blacklist with a single host to be removed, while cleaning up expired records from the global blacklist.
|
(package private) MySQLConnection |
getNewWrapperForThisAsConnection()
Wraps this object with a new load balanced Connection instance.
|
long |
getTotalPhysicalConnectionCount() |
long |
getTransactionCount() |
boolean |
inTransaction() |
(package private) void |
invalidateConnection(MySQLConnection conn)
Closes specified connection and removes it from required mappings.
|
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, trapping "close", "isClosed" and "commit/rollback" to switch connections for load
balancing.
|
boolean |
isGlobalBlacklistEnabled()
Checks if host blacklist management was enabled.
|
(package private) boolean |
isMasterConnection()
Always returns 'true' as there are no "masters" and "slaves" in this type of connection.
|
(package private) void |
pickNewConnection()
Picks the "best" connection to use for the next transaction based on the BalanceStrategy in use.
|
protected void |
propagateProxyDown(MySQLConnection proxyConn)
Propagates the connection proxy down through all live connections.
|
void |
removeHost(java.lang.String host)
Removes a host from the host list.
|
void |
removeHostWhenNotInUse(java.lang.String host)
Removes a host from the host list, allowing it some time to be released gracefully if needed.
|
(package private) boolean |
shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
Consults the registered LoadBalanceExceptionChecker if the given exception should trigger a connection fail-over.
|
allowedOnClosedConnection, dealWithInvocationException, getNewJdbcInterfaceProxy, getProxy, initializeHostsSpecs, invalidateCurrentConnection, invoke, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionState, syncSessionState
protected java.util.Map<java.lang.String,ConnectionImpl> liveConnections
public static final java.lang.String BLACKLIST_TIMEOUT_PROPERTY_KEY
public static LoadBalancedConnection createProxyInstance(java.util.List<java.lang.String> hosts, java.util.Properties props) throws java.sql.SQLException
java.sql.SQLException
MySQLConnection getNewWrapperForThisAsConnection() throws java.sql.SQLException
getNewWrapperForThisAsConnection
in class MultiHostConnectionProxy
java.sql.SQLException
protected void propagateProxyDown(MySQLConnection proxyConn)
propagateProxyDown
in class MultiHostConnectionProxy
proxyConn
- The top level connection in the multi-host connections chain.boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
shouldExceptionTriggerConnectionSwitch
in class MultiHostConnectionProxy
ex
- The Exception instance to check.boolean isMasterConnection()
isMasterConnection
in class MultiHostConnectionProxy
void invalidateConnection(MySQLConnection conn) throws java.sql.SQLException
invalidateConnection
in class MultiHostConnectionProxy
conn
- java.sql.SQLException
void pickNewConnection() throws java.sql.SQLException
pickNewConnection
in class MultiHostConnectionProxy
java.sql.SQLException
public ConnectionImpl createConnectionForHost(java.lang.String hostPortSpec) throws java.sql.SQLException
createConnectionForHost
in class MultiHostConnectionProxy
hostPortSpec
- The host:port specification.java.sql.SQLException
void doClose()
doClose
in class MultiHostConnectionProxy
void doAbortInternal()
doAbortInternal
in class MultiHostConnectionProxy
void doAbort(java.util.concurrent.Executor executor)
doAbort
in class MultiHostConnectionProxy
public java.lang.Object invokeMore(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invokeMore
in class MultiHostConnectionProxy
java.lang.Throwable
public void doPing() throws java.sql.SQLException
doPing
in interface PingTarget
java.sql.SQLException
public void addToGlobalBlacklist(java.lang.String host, long timeout)
host
- The host to be blacklisted.timeout
- The blacklist timeout for this entry.public void addToGlobalBlacklist(java.lang.String host)
host
- The host to be blacklisted.public boolean isGlobalBlacklistEnabled()
public java.util.Map<java.lang.String,java.lang.Long> getGlobalBlacklist()
public void removeHostWhenNotInUse(java.lang.String host) throws java.sql.SQLException
host
- The host to be removed.java.sql.SQLException
public void removeHost(java.lang.String host) throws java.sql.SQLException
host
- The host to be removed.java.sql.SQLException
public boolean addHost(java.lang.String host)
host
- The host to be added.public boolean inTransaction()
public long getTransactionCount()
public long getActivePhysicalConnectionCount()
public long getTotalPhysicalConnectionCount()
public long getConnectionGroupProxyID()
public java.lang.String getCurrentActiveHost()
public long getCurrentTransactionDuration()