public abstract class MultiHostConnectionProxy
extends java.lang.Object
implements java.lang.reflect.InvocationHandler
Modifier and Type | Class and Description |
---|---|
(package private) class |
MultiHostConnectionProxy.JdbcInterfaceProxy
Proxy class to intercept and deal with errors that may occur in any object bound to the current connection.
|
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
autoReconnect |
(package private) boolean |
closedExplicitly |
(package private) java.lang.String |
closedReason |
(package private) MySQLConnection |
currentConnection |
(package private) java.util.List<java.lang.String> |
hostList |
(package private) boolean |
isClosed |
protected java.lang.Throwable |
lastExceptionDealtWith |
(package private) java.util.Properties |
localProps |
(package private) MySQLConnection |
proxyConnection |
(package private) MySQLConnection |
thisAsConnection |
Constructor and Description |
---|
MultiHostConnectionProxy()
Initializes a connection wrapper for this MultiHostConnectionProxy instance.
|
MultiHostConnectionProxy(java.util.List<java.lang.String> hosts,
java.util.Properties props)
Constructs a MultiHostConnectionProxy instance for the given list of hosts and connection properties.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowedOnClosedConnection(java.lang.reflect.Method method)
Checks if the given method is allowed on closed connections.
|
(package private) ConnectionImpl |
createConnectionForHost(java.lang.String hostPortSpec)
Creates a new physical connection for the given host:port.
|
(package private) void |
dealWithInvocationException(java.lang.reflect.InvocationTargetException e)
Deals with InvocationException from proxied objects.
|
(package private) abstract void |
doAbort(java.util.concurrent.Executor executor)
Executes a abort() invocation;
|
(package private) abstract void |
doAbortInternal()
Executes a abortInternal() invocation;
|
(package private) abstract void |
doClose()
Executes a close() invocation;
|
(package private) java.lang.reflect.InvocationHandler |
getNewJdbcInterfaceProxy(java.lang.Object toProxy)
Instantiates a new JdbcInterfaceProxy for the given object.
|
(package private) MySQLConnection |
getNewWrapperForThisAsConnection()
Wraps this object with a new multi-host Connection instance.
|
protected MySQLConnection |
getProxy()
Get this connection's proxy.
|
(package private) int |
initializeHostsSpecs(java.util.List<java.lang.String> hosts,
java.util.Properties props)
Initializes the hosts lists and makes a "clean" local copy of the given connection properties so that it can be later used to create standard
connections.
|
(package private) void |
invalidateConnection(MySQLConnection conn)
Invalidates the specified connection by closing it.
|
(package private) void |
invalidateCurrentConnection()
Invalidates the current connection.
|
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 multi-host specific methods and generic methods.
|
(package private) abstract java.lang.Object |
invokeMore(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Continuation of the method invocation process, to be implemented within each subclass.
|
(package private) abstract boolean |
isMasterConnection()
Checks if current connection is to a master host.
|
(package private) abstract void |
pickNewConnection()
Picks the "best" connection to use from now on.
|
protected void |
propagateProxyDown(MySQLConnection proxyConn)
Propagates the connection proxy down through the multi-host connections chain.
|
(package private) java.lang.Object |
proxyIfReturnTypeIsJdbcInterface(java.lang.Class<?> returnType,
java.lang.Object toProxy)
If the given return type is or implements a JDBC interface, proxies the given object so that we can catch SQL errors and fire a connection switch.
|
protected void |
setProxy(MySQLConnection proxyConn)
Sets this connection's proxy.
|
(package private) abstract boolean |
shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
Checks if the given throwable should trigger a connection switch.
|
(package private) static void |
syncSessionState(Connection source,
Connection target)
Synchronizes session state between two connections.
|
(package private) static void |
syncSessionState(Connection source,
Connection target,
boolean readOnly)
Synchronizes session state between two connections, allowing to override the read-only status.
|
java.util.List<java.lang.String> hostList
java.util.Properties localProps
boolean autoReconnect
MySQLConnection thisAsConnection
MySQLConnection proxyConnection
MySQLConnection currentConnection
boolean isClosed
boolean closedExplicitly
java.lang.String closedReason
protected java.lang.Throwable lastExceptionDealtWith
MultiHostConnectionProxy() throws java.sql.SQLException
props
- The properties to be used in new internal connections.java.sql.SQLException
MultiHostConnectionProxy(java.util.List<java.lang.String> hosts, java.util.Properties props) throws java.sql.SQLException
hosts
- The lists of hosts available to switch on.props
- The properties to be used in new internal connections.java.sql.SQLException
int initializeHostsSpecs(java.util.List<java.lang.String> hosts, java.util.Properties props)
hosts
- The list of hosts for this multi-host connection.props
- Connection properties from where to get initial settings and to be used in new connections.MySQLConnection getNewWrapperForThisAsConnection() throws java.sql.SQLException
java.sql.SQLException
protected MySQLConnection getProxy()
protected final void setProxy(MySQLConnection proxyConn)
proxyConn
- The top level connection in the multi-host connections chain.protected void propagateProxyDown(MySQLConnection proxyConn)
proxyConn
- The top level connection in the multi-host connections chain.java.lang.Object proxyIfReturnTypeIsJdbcInterface(java.lang.Class<?> returnType, java.lang.Object toProxy)
returnType
- The type the object instance to proxy is supposed to be.toProxy
- The object instance to proxy.java.lang.reflect.InvocationHandler getNewJdbcInterfaceProxy(java.lang.Object toProxy)
toProxy
- The object instance to be proxied.void dealWithInvocationException(java.lang.reflect.InvocationTargetException e) throws java.sql.SQLException, java.lang.Throwable, java.lang.reflect.InvocationTargetException
e
- The Exception instance to check.java.sql.SQLException
java.lang.Throwable
java.lang.reflect.InvocationTargetException
abstract boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
t
- The Throwable instance to analyze.abstract boolean isMasterConnection()
void invalidateCurrentConnection() throws java.sql.SQLException
java.sql.SQLException
void invalidateConnection(MySQLConnection conn) throws java.sql.SQLException
conn
- The connection instance to invalidate.java.sql.SQLException
abstract void pickNewConnection() throws java.sql.SQLException
java.sql.SQLException
ConnectionImpl createConnectionForHost(java.lang.String hostPortSpec) throws java.sql.SQLException
hostPortSpec
- The host:port specification.java.sql.SQLException
static void syncSessionState(Connection source, Connection target) throws java.sql.SQLException
source
- The connection where to get state from.target
- The connection where to set state.java.sql.SQLException
static void syncSessionState(Connection source, Connection target, boolean readOnly) throws java.sql.SQLException
source
- The connection where to get state from.target
- The connection where to set state.readOnly
- The new read-only status.java.sql.SQLException
abstract void doClose() throws java.sql.SQLException
java.sql.SQLException
abstract void doAbortInternal() throws java.sql.SQLException
java.sql.SQLException
abstract void doAbort(java.util.concurrent.Executor executor) 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
abstract java.lang.Object invokeMore(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
java.lang.Throwable
protected boolean allowedOnClosedConnection(java.lang.reflect.Method method)