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)
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(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()
Returns a local hosts blacklist, while cleaning up expired records from the global blacklist, or a blacklist 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()
Checks if host blacklist management was enabled.
|
protected boolean |
isMasterConnection()
Always returns 'true' as there are no "masters" and "slaves" 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 |
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, setProxy
protected 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 MultiHostConnectionProxy
proxyConn
- 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 MultiHostConnectionProxy
t
- The Exception instance to check.protected boolean isMasterConnection()
isMasterConnection
in class MultiHostConnectionProxy
protected void invalidateConnection(JdbcConnection conn) throws java.sql.SQLException
invalidateConnection
in class MultiHostConnectionProxy
conn
- connectionjava.sql.SQLException
- if an error occurspublic void pickNewConnection() throws java.sql.SQLException
pickNewConnection
in class MultiHostConnectionProxy
java.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 MultiHostConnectionProxy
hostInfo
- The host info instance.java.sql.SQLException
- if an error occursprotected void syncSessionState(JdbcConnection source, JdbcConnection target, boolean readOnly) throws java.sql.SQLException
MultiHostConnectionProxy
syncSessionState
in class MultiHostConnectionProxy
source
- 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 MultiHostConnectionProxy
protected void doAbortInternal()
doAbortInternal
in class MultiHostConnectionProxy
protected void doAbort(java.util.concurrent.Executor executor)
doAbort
in class MultiHostConnectionProxy
executor
- 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 MultiHostConnectionProxy
proxy
- proxy objectmethod
- method to invokeargs
- method parametersjava.lang.Throwable
- if an error occurspublic void doPing() throws java.sql.SQLException
doPing
in interface PingTarget
java.sql.SQLException
- if an error occurspublic 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 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()