public class LoadBalancedConnectionProxy extends MultiHostConnectionProxy implements PingTarget
| Modifier and Type | Class and Description |
|---|---|
private static class |
LoadBalancedConnectionProxy.NullLoadBalancedConnectionProxy
A LoadBalancedConnection proxy that provides null-functionality.
|
MultiHostConnectionProxy.JdbcInterfaceProxy| Modifier and Type | Field and Description |
|---|---|
private BalanceStrategy |
balancer |
private ConnectionGroup |
connectionGroup |
private long |
connectionGroupProxyID |
private java.util.Map<ConnectionImpl,java.lang.String> |
connectionsToHostsMap |
private LoadBalanceExceptionChecker |
exceptionChecker |
private static java.util.Map<java.lang.String,java.lang.Long> |
globalBlocklist |
private int |
globalBlocklistTimeout |
private int |
hostRemovalGracePeriod |
private java.util.Map<java.lang.String,java.lang.Integer> |
hostsToListIndexMap |
private java.util.Set<java.lang.String> |
hostsToRemove |
private static java.lang.Class<?>[] |
INTERFACES_TO_PROXY |
private boolean |
inTransaction |
protected java.util.Map<java.lang.String,ConnectionImpl> |
liveConnections |
private static LoadBalancedConnection |
nullLBConnectionInstance |
private long[] |
responseTimes |
private int |
retriesAllDown |
private long |
totalPhysicalConnections |
private long |
transactionCount |
private long |
transactionStartTime |
autoReconnect, closedExplicitly, closedReason, connectionUrl, currentConnection, hostsList, isClosed, lastExceptionDealtWith, parentProxyConnection, thisAsConnection, topProxyConnection| Constructor and Description |
|---|
LoadBalancedConnectionProxy(ConnectionUrl connectionUrl)
Creates a proxy for java.sql.Connection that routes requests between the hosts in the connection URL.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addHost(java.lang.String hostPortPair)
Adds a host to the hosts list.
|
void |
addToGlobalBlacklist(java.lang.String host)
Deprecated.
|
void |
addToGlobalBlacklist(java.lang.String host,
long timeout)
Deprecated.
|
void |
addToGlobalBlocklist(java.lang.String host)
Adds a host to the blocklist.
|
void |
addToGlobalBlocklist(java.lang.String host,
long timeout)
Adds a host to the blocklist with the given timeout.
|
private void |
closeAllConnections()
Closes all live connections.
|
ConnectionImpl |
createConnectionForHost(HostInfo hostInfo)
Creates a new physical connection for the given
HostInfo and updates required internal mappings and statistics for that connection. |
ConnectionImpl |
createConnectionForHost(java.lang.String hostPortPair)
Creates a new physical connection for the given host:port info.
|
static LoadBalancedConnection |
createProxyInstance(ConnectionUrl connectionUrl)
Static factory to create
LoadBalancedConnection instances. |
(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()
Deprecated.
|
java.util.Map<java.lang.String,java.lang.Long> |
getGlobalBlocklist()
Returns a local hosts blocklist, while cleaning up expired records from the global blocklist, or a blocklist with the hosts to be removed.
|
(package private) JdbcConnection |
getNewWrapperForThisAsConnection()
Wraps this object with a new load balanced Connection instance.
|
(package private) static LoadBalancedConnection |
getNullLoadBalancedConnectionInstance() |
long |
getTotalPhysicalConnectionCount() |
long |
getTransactionCount() |
boolean |
inTransaction() |
(package private) void |
invalidateConnection(JdbcConnection conn)
Closes specified connection and removes it from required mappings.
|
(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, trapping "close", "isClosed" and "commit/rollback" to switch connections for load
balancing.
|
boolean |
isGlobalBlacklistEnabled()
Deprecated.
|
boolean |
isGlobalBlocklistEnabled()
Checks if host blocklist management was enabled.
|
(package private) boolean |
isSourceConnection()
Always returns 'true' as there are no "sources" and "replicas" in this type of connection.
|
void |
pickNewConnection()
Picks the "best" connection to use for the next transaction based on the BalanceStrategy in use.
|
protected void |
propagateProxyDown(JdbcConnection proxyConn)
Propagates the connection proxy down through all live connections.
|
void |
removeFromGlobalBlacklist(java.lang.String host)
Deprecated.
|
void |
removeFromGlobalBlocklist(java.lang.String host)
Removes a host from the blocklist.
|
void |
removeHost(java.lang.String hostPortPair)
Removes a host from the host list.
|
void |
removeHostWhenNotInUse(java.lang.String hostPortPair)
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.
|
boolean |
shouldExceptionTriggerFailover(java.lang.Throwable t)
Deprecated.
|
(package private) void |
syncSessionState(JdbcConnection source,
JdbcConnection target,
boolean readOnly)
Synchronizes session state between two connections, allowing to override the read-only status.
|
allowedOnClosedConnection, dealWithInvocationException, getNewJdbcInterfaceProxy, getParentProxy, getProxy, initializeHostsSpecs, invalidateCurrentConnection, invoke, isMasterConnection, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionStateprivate ConnectionGroup connectionGroup
private long connectionGroupProxyID
protected java.util.Map<java.lang.String,ConnectionImpl> liveConnections
private java.util.Map<java.lang.String,java.lang.Integer> hostsToListIndexMap
private java.util.Map<ConnectionImpl,java.lang.String> connectionsToHostsMap
private long totalPhysicalConnections
private long[] responseTimes
private int retriesAllDown
private BalanceStrategy balancer
private int globalBlocklistTimeout
private static java.util.Map<java.lang.String,java.lang.Long> globalBlocklist
private int hostRemovalGracePeriod
private java.util.Set<java.lang.String> hostsToRemove
private boolean inTransaction
private long transactionStartTime
private long transactionCount
private LoadBalanceExceptionChecker exceptionChecker
private static java.lang.Class<?>[] INTERFACES_TO_PROXY
private static LoadBalancedConnection nullLBConnectionInstance
public LoadBalancedConnectionProxy(ConnectionUrl connectionUrl) throws java.sql.SQLException
connectionUrl - The connection URL containing the hosts to load balance.java.sql.SQLException - if an error occurspublic static LoadBalancedConnection createProxyInstance(ConnectionUrl connectionUrl) throws java.sql.SQLException
LoadBalancedConnection instances.connectionUrl - The connection URL containing the hosts in a load-balance setup.LoadBalancedConnection proxy.java.sql.SQLException - if an error occursJdbcConnection getNewWrapperForThisAsConnection() throws java.sql.SQLException
getNewWrapperForThisAsConnection in class MultiHostConnectionProxyjava.sql.SQLException - if an error occursprotected void propagateProxyDown(JdbcConnection proxyConn)
propagateProxyDown in class MultiHostConnectionProxyproxyConn - The top level connection in the multi-host connections chain.@Deprecated public boolean shouldExceptionTriggerFailover(java.lang.Throwable t)
boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
shouldExceptionTriggerConnectionSwitch in class MultiHostConnectionProxyt - The Exception instance to check.boolean isSourceConnection()
isSourceConnection in class MultiHostConnectionProxyvoid invalidateConnection(JdbcConnection conn) throws java.sql.SQLException
invalidateConnection in class MultiHostConnectionProxyconn - connectionjava.sql.SQLException - if an error occurspublic void pickNewConnection()
throws java.sql.SQLException
pickNewConnection in class MultiHostConnectionProxyjava.sql.SQLException - if an error occurspublic ConnectionImpl createConnectionForHost(HostInfo hostInfo) throws java.sql.SQLException
HostInfo and updates required internal mappings and statistics for that connection.createConnectionForHost in class MultiHostConnectionProxyhostInfo - The host info instance.java.sql.SQLException - if an error occursvoid syncSessionState(JdbcConnection source, JdbcConnection target, boolean readOnly) throws java.sql.SQLException
MultiHostConnectionProxysyncSessionState in class MultiHostConnectionProxysource - The connection where to get state from.target - The connection where to set state.readOnly - The new read-only status.java.sql.SQLException - if an error occurspublic ConnectionImpl createConnectionForHost(java.lang.String hostPortPair) throws java.sql.SQLException
hostPortPair - The host:port pair identifying the host to connect to.java.sql.SQLException - if an error occursprivate void closeAllConnections()
void doClose()
doClose in class MultiHostConnectionProxyvoid doAbortInternal()
doAbortInternal in class MultiHostConnectionProxyvoid doAbort(java.util.concurrent.Executor executor)
doAbort in class MultiHostConnectionProxyexecutor - executorjava.lang.Object invokeMore(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
invokeMore in class MultiHostConnectionProxyproxy - proxy objectmethod - method to invokeargs - method parametersjava.lang.Throwable - if an error occurspublic void doPing()
throws java.sql.SQLException
doPing in interface PingTargetjava.sql.SQLException - if an error occurspublic void addToGlobalBlocklist(java.lang.String host,
long timeout)
host - The host to be blocklisted.timeout - The blocklist timeout for this entry.public void removeFromGlobalBlocklist(java.lang.String host)
host - The host to be removed from the blocklist.@Deprecated public void removeFromGlobalBlacklist(java.lang.String host)
removeFromGlobalBlocklist(String) instead.host - host@Deprecated
public void addToGlobalBlacklist(java.lang.String host,
long timeout)
addToGlobalBlocklist(String, long) instead.host - The host to be blocklisted.timeout - The blocklist timeout for this entry.public void addToGlobalBlocklist(java.lang.String host)
host - The host to be blocklisted.@Deprecated public void addToGlobalBlacklist(java.lang.String host)
addToGlobalBlocklist(String) instead.host - The host to be blocklisted.public boolean isGlobalBlocklistEnabled()
@Deprecated public boolean isGlobalBlacklistEnabled()
isGlobalBlocklistEnabled() instead.public java.util.Map<java.lang.String,java.lang.Long> getGlobalBlocklist()
@Deprecated public java.util.Map<java.lang.String,java.lang.Long> getGlobalBlacklist()
getGlobalBlocklist() instead.public void removeHostWhenNotInUse(java.lang.String hostPortPair)
throws java.sql.SQLException
hostPortPair - The host to be removed.java.sql.SQLException - if an error occurspublic void removeHost(java.lang.String hostPortPair)
throws java.sql.SQLException
hostPortPair - The host to be removed.java.sql.SQLException - if an error occurspublic boolean addHost(java.lang.String hostPortPair)
hostPortPair - 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()
static LoadBalancedConnection getNullLoadBalancedConnectionInstance()