public class FailoverProxy
extends java.lang.Object
implements java.lang.reflect.InvocationHandler
Modifier and Type | Field and Description |
---|---|
private Listener |
listener |
java.util.concurrent.locks.ReentrantLock |
lock |
private static Logger |
logger |
static java.lang.String |
METHOD_CLOSED_EXPLICIT |
static java.lang.String |
METHOD_COM_MULTI_PREPARE_EXECUTES |
static java.lang.String |
METHOD_EXECUTE_PREPARED_QUERY |
static java.lang.String |
METHOD_EXECUTE_QUERY |
static java.lang.String |
METHOD_GET_OPTIONS |
static java.lang.String |
METHOD_GET_PROXY |
static java.lang.String |
METHOD_IS_CLOSED |
static java.lang.String |
METHOD_IS_EXPLICIT_CLOSED |
static java.lang.String |
METHOD_IS_READ_ONLY |
static java.lang.String |
METHOD_PROLOG_PROXY |
static java.lang.String |
METHOD_SET_READ_ONLY |
Constructor and Description |
---|
FailoverProxy(Listener listener,
java.util.concurrent.locks.ReentrantLock lock)
Proxy constructor.
|
Modifier and Type | Method and Description |
---|---|
private static java.sql.SQLException |
addHostInformationToException(java.sql.SQLException exception,
Protocol protocol)
Add Host information ("on HostAddress...") to exception.
|
private java.lang.Object |
executeInvocation(java.lang.reflect.Method method,
java.lang.Object[] args,
boolean isSecondExecution) |
Listener |
getListener() |
private java.lang.Object |
handleFailOver(java.sql.SQLException qe,
java.lang.reflect.Method method,
java.lang.Object[] args,
Protocol protocol)
After a connection exception, launch failover.
|
boolean |
hasToHandleFailover(java.sql.SQLException exception)
Check if this Sqlerror is a connection exception.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Proxy that catch Protocol call, to permit to catch errors and handle failover when multiple hosts.
|
void |
reconnect()
Launch reconnect implementation.
|
public static final java.lang.String METHOD_IS_EXPLICIT_CLOSED
public static final java.lang.String METHOD_GET_OPTIONS
public static final java.lang.String METHOD_GET_PROXY
public static final java.lang.String METHOD_EXECUTE_QUERY
public static final java.lang.String METHOD_SET_READ_ONLY
public static final java.lang.String METHOD_IS_READ_ONLY
public static final java.lang.String METHOD_CLOSED_EXPLICIT
public static final java.lang.String METHOD_IS_CLOSED
public static final java.lang.String METHOD_EXECUTE_PREPARED_QUERY
public static final java.lang.String METHOD_COM_MULTI_PREPARE_EXECUTES
public static final java.lang.String METHOD_PROLOG_PROXY
private static Logger logger
public final java.util.concurrent.locks.ReentrantLock lock
private Listener listener
public FailoverProxy(Listener listener, java.util.concurrent.locks.ReentrantLock lock) throws java.sql.SQLException
listener
- failover implementation.lock
- synchronisation lockjava.sql.SQLException
- if connection error occurprivate static java.sql.SQLException addHostInformationToException(java.sql.SQLException exception, Protocol protocol)
example :
java.sql.SQLException: (conn:603) Cannot execute statement in a READ ONLY transaction.
Query is: INSERT INTO TableX VALUES (21)
on HostAddress{host='mydb.example.com', port=3306},master=true
exception
- current exceptionprotocol
- protocol to have hostnamepublic 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
proxy
- the current protocolmethod
- the called method on the protocolargs
- methods parametersjava.lang.Throwable
- the method throwed error if not catch by failoverprivate java.lang.Object executeInvocation(java.lang.reflect.Method method, java.lang.Object[] args, boolean isSecondExecution) throws java.lang.Throwable
java.lang.Throwable
private java.lang.Object handleFailOver(java.sql.SQLException qe, java.lang.reflect.Method method, java.lang.Object[] args, Protocol protocol) throws java.lang.Throwable
qe
- the exception thrownmethod
- the method to call if failover works wellargs
- the arguments of the methodjava.lang.Throwable
- throwablepublic boolean hasToHandleFailover(java.sql.SQLException exception)
error codes : 08000 : connection exception 08001 : SQL client unable to establish SQL connection 08002 : connection name in use 08003 : connection does not exist 08004 : SQL server rejected SQL connection 08006 : connection failure 08007 : transaction resolution unknown 70100 : connection was killed
exception
- the Exceptionpublic void reconnect() throws java.sql.SQLException
java.sql.SQLException
- exceptionpublic Listener getListener()