public class LoadBalancedConnectionProxy extends MultiHostConnectionProxy implements PingTarget
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,ConnectionImpl> |
liveConnections |
autoReconnect, closedExplicitly, closedReason, connectionUrl, currentConnection, hostsList, isClosed, lastExceptionDealtWith, thisAsConnection| 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.
|
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. |
protected void |
doAbort(java.util.concurrent.Executor executor)
Aborts all live connections, using the provided Executor.
|
protected void |
doAbortInternal()
Aborts all live connections
|
protected 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.
|
long |
getTotalPhysicalConnectionCount() |
long |
getTransactionCount() |
boolean |
inTransaction() |
protected void |
invalidateConnection(JdbcConnection 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()
Deprecated.
|
boolean |
isGlobalBlocklistEnabled()
Checks if host blocklist management was enabled.
|
protected 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.
|
protected 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.
|
protected 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, invalidateCurrentConnection, invoke, proxyIfReturnTypeIsJdbcInterface, setProxyprotected java.util.Map<java.lang.String,ConnectionImpl> liveConnections
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 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)
protected boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
shouldExceptionTriggerConnectionSwitch in class MultiHostConnectionProxyt - The Exception instance to check.protected boolean isSourceConnection()
isSourceConnection in class MultiHostConnectionProxyprotected void 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 occursprotected void 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 occursprotected void doClose()
doClose in class MultiHostConnectionProxyprotected void doAbortInternal()
doAbortInternal in class MultiHostConnectionProxyprotected void doAbort(java.util.concurrent.Executor executor)
doAbort in class MultiHostConnectionProxyexecutor - executorpublic java.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()