|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mysql.jdbc.LoadBalancingConnectionProxy
public class LoadBalancingConnectionProxy
An implementation of java.sql.Connection that load balances requests across a series of MySQL JDBC connections, where the balancing takes place at transaction commit. Therefore, for this to work (at all), you must use transactions, even if only reading data. This implementation will invalidate connections that it detects have had communication errors when processing a request. Problematic hosts will be added to a global blacklist for loadBalanceBlacklistTimeout ms, after which they will be removed from the blacklist and made eligible once again to be selected for new connections. This implementation is thread-safe, but it's questionable whether sharing a connection instance amongst threads is a good idea, given that transactions are scoped to connections in JDBC.
Nested Class Summary | |
---|---|
protected class |
LoadBalancingConnectionProxy.ConnectionErrorFiringInvocationHandler
|
Field Summary | |
---|---|
static java.lang.String |
BLACKLIST_TIMEOUT_PROPERTY_KEY
|
Constructor Summary | |
---|---|
LoadBalancingConnectionProxy(java.util.List 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. |
Method Summary | |
---|---|
void |
addToGlobalBlacklist(java.lang.String host)
|
Connection |
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 |
dealWithInvocationException(java.lang.reflect.InvocationTargetException e)
|
void |
doPing()
|
java.util.Map |
getGlobalBlacklist()
|
(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)
Proxies method invocation on the java.sql.Connection interface, trapping "close", "isClosed" and "commit/rollback" (to switch connections for load balancing). |
boolean |
isGlobalBlacklistEnabled()
|
(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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String BLACKLIST_TIMEOUT_PROPERTY_KEY
Constructor Detail |
---|
LoadBalancingConnectionProxy(java.util.List hosts, java.util.Properties props) throws java.sql.SQLException
hosts
- props
-
java.sql.SQLException
Method Detail |
---|
public Connection 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
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
java.lang.Object proxyIfInterfaceIsJdbc(java.lang.Object toProxy, java.lang.Class clazz)
toProxy
- clazz
-
public void doPing() throws java.sql.SQLException
doPing
in interface PingTarget
java.sql.SQLException
public void addToGlobalBlacklist(java.lang.String host)
public boolean isGlobalBlacklistEnabled()
public java.util.Map getGlobalBlacklist()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |