Class FailoverProxy
- java.lang.Object
-
- org.mariadb.jdbc.internal.failover.FailoverProxy
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
public class FailoverProxy extends java.lang.Object implements java.lang.reflect.InvocationHandler
-
-
Field Summary
Fields Modifier and Type Field Description private Listenerlistenerjava.util.concurrent.locks.ReentrantLocklockprivate static Loggerloggerprivate static java.lang.StringMETHOD_ABORTprivate static java.lang.StringMETHOD_CLOSED_EXPLICITprivate static java.lang.StringMETHOD_COM_MULTI_PREPARE_EXECUTESprivate static java.lang.StringMETHOD_EXECUTE_PREPARED_QUERYprivate static java.lang.StringMETHOD_EXECUTE_QUERYprivate static java.lang.StringMETHOD_GET_CATALOGprivate static java.lang.StringMETHOD_GET_LOCKprivate static java.lang.StringMETHOD_GET_MAJOR_VERSIONprivate static java.lang.StringMETHOD_GET_NO_BACKSLASHprivate static java.lang.StringMETHOD_GET_OPTIONSprivate static java.lang.StringMETHOD_GET_PROXYprivate static java.lang.StringMETHOD_GET_READ_ONLYprivate static java.lang.StringMETHOD_GET_SERVER_THREAD_IDprivate static java.lang.StringMETHOD_GET_TIMEOUTprivate static java.lang.StringMETHOD_GET_URLPARSERprivate static java.lang.StringMETHOD_IN_TRANSACTIONprivate static java.lang.StringMETHOD_IS_CLOSEDprivate static java.lang.StringMETHOD_IS_EXPLICIT_CLOSEDprivate static java.lang.StringMETHOD_IS_MARIADBprivate static java.lang.StringMETHOD_IS_MASTER_CONNECTIONprivate static java.lang.StringMETHOD_IS_VALIDprivate static java.lang.StringMETHOD_PROLOGprivate static java.lang.StringMETHOD_PROLOG_PROXYprivate static java.lang.StringMETHOD_RESETprivate static java.lang.StringMETHOD_SESSION_STATE_AWAREprivate static java.lang.StringMETHOD_SET_READ_ONLYprivate static java.lang.StringMETHOD_VERSION_GREATER_OR_EQUALLruTraceCachetraceCache
-
Constructor Summary
Constructors Constructor Description FailoverProxy(Listener listener, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache)Proxy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.sql.SQLExceptionaddHostInformationToException(java.sql.SQLException exception, Protocol protocol)Add Host information ("on HostAddress...") to exception.private java.lang.ObjectexecuteInvocation(java.lang.reflect.Method method, java.lang.Object[] args, boolean isSecondExecution)ListenergetListener()private java.lang.ObjecthandleFailOver(java.sql.SQLException qe, java.lang.reflect.Method method, java.lang.Object[] args, Protocol protocol, boolean isClosed)After a connection exception, launch failover.booleanhasToHandleFailover(java.sql.SQLException exception)Check if this Sqlerror is a connection exception.java.lang.Objectinvoke(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.voidreconnect()Launch reconnect implementation.
-
-
-
Field Detail
-
METHOD_IS_EXPLICIT_CLOSED
private static final java.lang.String METHOD_IS_EXPLICIT_CLOSED
- See Also:
- Constant Field Values
-
METHOD_GET_OPTIONS
private static final java.lang.String METHOD_GET_OPTIONS
- See Also:
- Constant Field Values
-
METHOD_GET_URLPARSER
private static final java.lang.String METHOD_GET_URLPARSER
- See Also:
- Constant Field Values
-
METHOD_GET_PROXY
private static final java.lang.String METHOD_GET_PROXY
- See Also:
- Constant Field Values
-
METHOD_EXECUTE_QUERY
private static final java.lang.String METHOD_EXECUTE_QUERY
- See Also:
- Constant Field Values
-
METHOD_SET_READ_ONLY
private static final java.lang.String METHOD_SET_READ_ONLY
- See Also:
- Constant Field Values
-
METHOD_GET_READ_ONLY
private static final java.lang.String METHOD_GET_READ_ONLY
- See Also:
- Constant Field Values
-
METHOD_IS_MASTER_CONNECTION
private static final java.lang.String METHOD_IS_MASTER_CONNECTION
- See Also:
- Constant Field Values
-
METHOD_VERSION_GREATER_OR_EQUAL
private static final java.lang.String METHOD_VERSION_GREATER_OR_EQUAL
- See Also:
- Constant Field Values
-
METHOD_SESSION_STATE_AWARE
private static final java.lang.String METHOD_SESSION_STATE_AWARE
- See Also:
- Constant Field Values
-
METHOD_CLOSED_EXPLICIT
private static final java.lang.String METHOD_CLOSED_EXPLICIT
- See Also:
- Constant Field Values
-
METHOD_ABORT
private static final java.lang.String METHOD_ABORT
- See Also:
- Constant Field Values
-
METHOD_IS_CLOSED
private static final java.lang.String METHOD_IS_CLOSED
- See Also:
- Constant Field Values
-
METHOD_EXECUTE_PREPARED_QUERY
private static final java.lang.String METHOD_EXECUTE_PREPARED_QUERY
- See Also:
- Constant Field Values
-
METHOD_COM_MULTI_PREPARE_EXECUTES
private static final java.lang.String METHOD_COM_MULTI_PREPARE_EXECUTES
- See Also:
- Constant Field Values
-
METHOD_PROLOG_PROXY
private static final java.lang.String METHOD_PROLOG_PROXY
- See Also:
- Constant Field Values
-
METHOD_RESET
private static final java.lang.String METHOD_RESET
- See Also:
- Constant Field Values
-
METHOD_IS_VALID
private static final java.lang.String METHOD_IS_VALID
- See Also:
- Constant Field Values
-
METHOD_GET_LOCK
private static final java.lang.String METHOD_GET_LOCK
- See Also:
- Constant Field Values
-
METHOD_GET_NO_BACKSLASH
private static final java.lang.String METHOD_GET_NO_BACKSLASH
- See Also:
- Constant Field Values
-
METHOD_GET_SERVER_THREAD_ID
private static final java.lang.String METHOD_GET_SERVER_THREAD_ID
- See Also:
- Constant Field Values
-
METHOD_PROLOG
private static final java.lang.String METHOD_PROLOG
- See Also:
- Constant Field Values
-
METHOD_GET_CATALOG
private static final java.lang.String METHOD_GET_CATALOG
- See Also:
- Constant Field Values
-
METHOD_GET_TIMEOUT
private static final java.lang.String METHOD_GET_TIMEOUT
- See Also:
- Constant Field Values
-
METHOD_GET_MAJOR_VERSION
private static final java.lang.String METHOD_GET_MAJOR_VERSION
- See Also:
- Constant Field Values
-
METHOD_IN_TRANSACTION
private static final java.lang.String METHOD_IN_TRANSACTION
- See Also:
- Constant Field Values
-
METHOD_IS_MARIADB
private static final java.lang.String METHOD_IS_MARIADB
- See Also:
- Constant Field Values
-
logger
private static final Logger logger
-
lock
public final java.util.concurrent.locks.ReentrantLock lock
-
traceCache
public final LruTraceCache traceCache
-
listener
private final Listener listener
-
-
Constructor Detail
-
FailoverProxy
public FailoverProxy(Listener listener, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache) throws java.sql.SQLException
Proxy constructor.- Parameters:
listener- failover implementation.lock- synchronisation locktraceCache- trace cache- Throws:
java.sql.SQLException- if connection error occur
-
-
Method Detail
-
addHostInformationToException
private static java.sql.SQLException addHostInformationToException(java.sql.SQLException exception, Protocol protocol)Add Host information ("on HostAddress...") to exception.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- Parameters:
exception- current exceptionprotocol- protocol to have hostname
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.ThrowableProxy that catch Protocol call, to permit to catch errors and handle failover when multiple hosts.- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Parameters:
proxy- the current protocolmethod- the called method on the protocolargs- methods parameters- Returns:
- protocol method result
- Throws:
java.lang.Throwable- the method throwed error if not catch by failover
-
executeInvocation
private java.lang.Object executeInvocation(java.lang.reflect.Method method, java.lang.Object[] args, boolean isSecondExecution) throws java.lang.Throwable- Throws:
java.lang.Throwable
-
handleFailOver
private java.lang.Object handleFailOver(java.sql.SQLException qe, java.lang.reflect.Method method, java.lang.Object[] args, Protocol protocol, boolean isClosed) throws java.lang.ThrowableAfter a connection exception, launch failover.- Parameters:
qe- the exception thrownmethod- the method to call if failover works wellargs- the arguments of the method- Returns:
- the object return from the method
- Throws:
java.lang.Throwable- throwable
-
hasToHandleFailover
public boolean hasToHandleFailover(java.sql.SQLException exception)
Check if this Sqlerror is a connection exception. if that's the case, must be handle by failovererror 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 if error code is "1927"
- Parameters:
exception- the Exception- Returns:
- true if there has been a connection error that must be handled by failover
-
reconnect
public void reconnect() throws java.sql.SQLExceptionLaunch reconnect implementation.- Throws:
java.sql.SQLException- exception
-
getListener
public Listener getListener()
-
-