public class LoadBalancingConnectionProxy extends java.lang.Object implements java.lang.reflect.InvocationHandler, PingTarget
Modifier and Type | Class and Description |
---|---|
protected class |
LoadBalancingConnectionProxy.ConnectionErrorFiringInvocationHandler |
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoReconnect |
static java.lang.String |
BLACKLIST_TIMEOUT_PROPERTY_KEY |
protected boolean |
closedExplicitly |
protected java.lang.String |
closedReason |
protected MySQLConnection |
currentConn |
protected java.util.List<java.lang.String> |
hostList |
protected boolean |
isClosed |
protected java.util.Map<java.lang.String,ConnectionImpl> |
liveConnections |
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) |
void |
addToGlobalBlacklist(java.lang.String host) |
void |
addToGlobalBlacklist(java.lang.String host,
long 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.
|
protected LoadBalancingConnectionProxy.ConnectionErrorFiringInvocationHandler |
createConnectionProxy(java.lang.Object toProxy) |
(package private) void |
dealWithInvocationException(java.lang.reflect.InvocationTargetException e) |
void |
doPing() |
long |
getActivePhysicalConnectionCount() |
long |
getConnectionGroupProxyID() |
java.lang.String |
getCurrentActiveHost() |
long |
getCurrentTransactionDuration() |
java.util.Map<java.lang.String,java.lang.Long> |
getGlobalBlacklist() |
long |
getLastUsed() |
long |
getTotalPhysicalConnectionCount() |
long |
getTransactionCount() |
boolean |
inTransaction() |
(package private) void |
invalidateConnection(MySQLConnection conn)
Closes specified connection and removes it from required mappings.
|
(package private) void |
invalidateCurrentConnection()
Closes current connection and removes it from required mappings.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args) |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args,
boolean swapAtTransactionBoundary)
Proxies method invocation on the java.sql.Connection interface, trapping
"close", "isClosed" and "commit/rollback" (to switch connections for load
balancing).
|
boolean |
isGlobalBlacklistEnabled() |
protected void |
pickNewConnection()
Picks the "best" connection to use for the next transaction based on the
BalanceStrategy in use.
|
(package private) java.lang.Object |
proxyIfInterfaceIsJdbc(java.lang.Object toProxy,
java.lang.Class<?> clazz)
Recursively checks for interfaces on the given object to determine if it
implements a java.sql interface, and if so, proxies the instance so that
we can catch and fire SQL errors.
|
void |
removeHost(java.lang.String host) |
void |
removeHostWhenNotInUse(java.lang.String host) |
boolean |
shouldExceptionTriggerFailover(java.sql.SQLException ex) |
protected void |
syncSessionState(Connection initial,
Connection target) |
protected java.lang.String closedReason
protected boolean closedExplicitly
protected boolean autoReconnect
public static final java.lang.String BLACKLIST_TIMEOUT_PROPERTY_KEY
protected MySQLConnection currentConn
protected java.util.List<java.lang.String> hostList
protected java.util.Map<java.lang.String,ConnectionImpl> liveConnections
protected boolean isClosed
LoadBalancingConnectionProxy(java.util.List<java.lang.String> hosts, java.util.Properties props) throws java.sql.SQLException
hosts
- props
- java.sql.SQLException
public ConnectionImpl createConnectionForHost(java.lang.String hostPortSpec) throws java.sql.SQLException
hostPortSpec
- java.sql.SQLException
void dealWithInvocationException(java.lang.reflect.InvocationTargetException e) throws java.sql.SQLException, java.lang.Throwable, java.lang.reflect.InvocationTargetException
e
- java.sql.SQLException
java.lang.Throwable
java.lang.reflect.InvocationTargetException
void invalidateCurrentConnection() throws java.sql.SQLException
java.sql.SQLException
void invalidateConnection(MySQLConnection conn) throws java.sql.SQLException
conn
- java.sql.SQLException
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invoke
in interface java.lang.reflect.InvocationHandler
java.lang.Throwable
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, boolean swapAtTransactionBoundary) throws java.lang.Throwable
proxy
- method
- args
- swapAtTransactionBoundary
- java.lang.Throwable
protected void pickNewConnection() throws java.sql.SQLException
java.sql.SQLException
java.lang.Object proxyIfInterfaceIsJdbc(java.lang.Object toProxy, java.lang.Class<?> clazz)
toProxy
- clazz
- protected LoadBalancingConnectionProxy.ConnectionErrorFiringInvocationHandler createConnectionProxy(java.lang.Object toProxy)
public void doPing() throws java.sql.SQLException
doPing
in interface PingTarget
java.sql.SQLException
public void addToGlobalBlacklist(java.lang.String host, long timeout)
public void addToGlobalBlacklist(java.lang.String host)
public boolean isGlobalBlacklistEnabled()
public java.util.Map<java.lang.String,java.lang.Long> getGlobalBlacklist()
public boolean shouldExceptionTriggerFailover(java.sql.SQLException ex)
public void removeHostWhenNotInUse(java.lang.String host) throws java.sql.SQLException
java.sql.SQLException
public void removeHost(java.lang.String host) throws java.sql.SQLException
java.sql.SQLException
public boolean addHost(java.lang.String host)
public long getLastUsed()
public boolean inTransaction()
public long getTransactionCount()
public long getActivePhysicalConnectionCount()
public long getTotalPhysicalConnectionCount()
public long getConnectionGroupProxyID()
public java.lang.String getCurrentActiveHost()
public long getCurrentTransactionDuration()
protected void syncSessionState(Connection initial, Connection target) throws java.sql.SQLException
java.sql.SQLException