public class LoadBalancingConnectionProxy 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, localProps, thisAsConnection| Constructor and Description |
|---|
LoadBalancingConnectionProxy(java.util.List<java.lang.String> hosts,
java.util.Properties props)
Creates a proxy for java.sql.Connection that routes requests between the given list of host:port and uses the given properties when creating connections.
|
| 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.
|
(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) void |
pickNewConnection()
Picks the "best" connection to use for the next transaction based on the BalanceStrategy in use.
|
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.
|
(package private) boolean |
shouldExceptionTriggerFailover(java.lang.Throwable t)
Deprecated.
|
dealWithInvocationException, getNewJdbcInterfaceProxy, initializeHostsSpecs, invalidateCurrentConnection, invoke, proxyIfIsJdbcInterface, syncSessionState, syncSessionStateprotected java.util.Map<java.lang.String,ConnectionImpl> liveConnections
public static final java.lang.String BLACKLIST_TIMEOUT_PROPERTY_KEY
LoadBalancingConnectionProxy(java.util.List<java.lang.String> hosts,
java.util.Properties props)
throws java.sql.SQLException
hosts - The list of the hosts to load balance.props - Connection properties from where to get initial settings and to be used in new connections.java.sql.SQLExceptionMySQLConnection getNewWrapperForThisAsConnection() throws java.sql.SQLException
getNewWrapperForThisAsConnection in class MultiHostConnectionProxyjava.sql.SQLException@Deprecated boolean shouldExceptionTriggerFailover(java.lang.Throwable t)
boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
shouldExceptionTriggerConnectionSwitch in class MultiHostConnectionProxyex - The Exception instance to check.void invalidateConnection(MySQLConnection conn) throws java.sql.SQLException
invalidateConnection in class MultiHostConnectionProxyconn - java.sql.SQLExceptionvoid pickNewConnection()
throws java.sql.SQLException
pickNewConnection in class MultiHostConnectionProxyjava.sql.SQLExceptionpublic ConnectionImpl createConnectionForHost(java.lang.String hostPortSpec) throws java.sql.SQLException
createConnectionForHost in class MultiHostConnectionProxyhostPortSpec - The host:port specification.java.sql.SQLExceptionvoid doClose()
doClose in class MultiHostConnectionProxyvoid doAbortInternal()
doAbortInternal in class MultiHostConnectionProxyvoid doAbort(java.util.concurrent.Executor executor)
doAbort in class MultiHostConnectionProxypublic java.lang.Object invokeMore(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
invokeMore in class MultiHostConnectionProxyjava.lang.Throwablepublic void doPing()
throws java.sql.SQLException
doPing in interface PingTargetjava.sql.SQLExceptionpublic 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.SQLExceptionpublic void removeHost(java.lang.String host)
throws java.sql.SQLException
host - The host to be removed.java.sql.SQLExceptionpublic 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()