public abstract class MultiHostConnectionProxy
extends java.lang.Object
implements java.lang.reflect.InvocationHandler
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
autoReconnect |
protected boolean |
closedExplicitly |
protected java.lang.String |
closedReason |
protected ConnectionUrl |
connectionUrl |
protected JdbcConnection |
currentConnection |
protected java.util.List<HostInfo> |
hostsList |
protected boolean |
isClosed |
protected java.lang.Throwable |
lastExceptionDealtWith |
protected JdbcConnection |
thisAsConnection |
| Modifier | Constructor and Description |
|---|---|
protected |
MultiHostConnectionProxy(ConnectionUrl connectionUrl)
Constructs a MultiHostConnectionProxy instance for the given connection URL.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
allowedOnClosedConnection(java.lang.reflect.Method method)
Checks if the given method is allowed on closed connections.
|
protected ConnectionImpl |
createConnectionForHost(HostInfo hostInfo)
Creates a new physical connection for the given
HostInfo. |
protected void |
dealWithInvocationException(java.lang.reflect.InvocationTargetException e)
Deals with InvocationException from proxied objects.
|
protected abstract void |
doAbort(java.util.concurrent.Executor executor)
Executes a abort() invocation;
|
protected abstract void |
doAbortInternal()
Executes a abortInternal() invocation;
|
protected abstract void |
doClose()
Executes a close() invocation;
|
protected java.lang.reflect.InvocationHandler |
getNewJdbcInterfaceProxy(java.lang.Object toProxy)
Instantiates a new JdbcInterfaceProxy for the given object.
|
protected JdbcConnection |
getParentProxy()
Get this connection's parent proxy.
|
protected JdbcConnection |
getProxy()
Get this connection's proxy.
|
protected void |
invalidateConnection(JdbcConnection conn)
Invalidates the specified connection by closing it.
|
protected 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.
|
protected 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.
|
protected abstract boolean |
isSourceConnection()
Checks if current connection is to a source host.
|
protected abstract void |
pickNewConnection()
Picks the "best" connection to use from now on.
|
protected void |
propagateProxyDown(JdbcConnection proxyConn)
Propagates the connection proxy down through the multi-host connections chain.
|
protected 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(JdbcConnection proxyConn)
Sets this connection's proxy.
|
protected abstract boolean |
shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
Checks if the given throwable should trigger a connection switch.
|
protected void |
syncSessionState(JdbcConnection source,
JdbcConnection target,
boolean readOnly)
Synchronizes session state between two connections, allowing to override the read-only status.
|
protected java.util.List<HostInfo> hostsList
protected ConnectionUrl connectionUrl
protected boolean autoReconnect
protected JdbcConnection thisAsConnection
protected JdbcConnection currentConnection
protected boolean isClosed
protected boolean closedExplicitly
protected java.lang.String closedReason
protected java.lang.Throwable lastExceptionDealtWith
protected MultiHostConnectionProxy(ConnectionUrl connectionUrl) throws java.sql.SQLException
connectionUrl - The connection URL.java.sql.SQLException - if an error occursprotected JdbcConnection getProxy()
protected JdbcConnection getParentProxy()
protected final void setProxy(JdbcConnection proxyConn)
proxyConn - The top level connection in the multi-host connections chain.protected void propagateProxyDown(JdbcConnection proxyConn)
proxyConn - The top level connection in the multi-host connections chain.protected 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.protected java.lang.reflect.InvocationHandler getNewJdbcInterfaceProxy(java.lang.Object toProxy)
toProxy - The object instance to be proxied.protected 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 - if an error occursjava.lang.Throwable - if an error occursjava.lang.reflect.InvocationTargetException - if an error occursprotected abstract boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
t - The Throwable instance to analyze.protected abstract boolean isSourceConnection()
protected void invalidateCurrentConnection()
throws java.sql.SQLException
java.sql.SQLException - if an error occursprotected void invalidateConnection(JdbcConnection conn) throws java.sql.SQLException
conn - The connection instance to invalidate.java.sql.SQLException - if an error occursprotected abstract void pickNewConnection()
throws java.sql.SQLException
java.sql.SQLException - if an error occursprotected ConnectionImpl createConnectionForHost(HostInfo hostInfo) throws java.sql.SQLException
HostInfo.hostInfo - The host info instance.java.sql.SQLException - if an error occursprotected void syncSessionState(JdbcConnection source, JdbcConnection 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 - if an error occursprotected abstract void doClose()
throws java.sql.SQLException
java.sql.SQLException - if an error occursprotected abstract void doAbortInternal()
throws java.sql.SQLException
java.sql.SQLException - if an error occursprotected abstract void doAbort(java.util.concurrent.Executor executor)
throws java.sql.SQLException
executor - executorjava.sql.SQLException - if an error occurspublic 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.InvocationHandlerproxy - proxy objectmethod - method to invokeargs - method parametersjava.lang.Throwable - if an error occursprotected abstract java.lang.Object invokeMore(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
proxy - proxy objectmethod - method to invokeargs - method parametersjava.lang.Throwable - if an error occursprotected boolean allowedOnClosedConnection(java.lang.reflect.Method method)
method - method