org.mariadb.jdbc.internal.mysql.listener

## Class AbstractMastersListener

- java.lang.Object
- - org.mariadb.jdbc.internal.mysql.listener.AbstractMastersListener

All Implemented Interfaces:
  Listener

Direct Known Subclasses:
  AbstractMastersSlavesListener, MastersFailoverListener

    public abstract class AbstractMastersListener
    extends Object
    implements Listener

### Nested Class Summary

Nested Classes
`protected class` `AbstractMastersListener.FailLoop` private class to permit a timer reconnection loop

### Field Summary

Fields
`protected static Map<HostAddress,Long>` `blacklist` list the recent failedConnection
`protected AtomicInteger` `currentConnectionAttempts`
`protected Protocol` `currentProtocol`
`protected AtomicBoolean` `currentReadOnlyAsked`
`protected ScheduledExecutorService` `executorService`
`protected boolean` `explicitClosed`
`protected AtomicBoolean` `isLooping`
`JDBCUrl` `jdbcUrl`
`protected long` `lastRetry`
`protected FailoverProxy` `proxy`
`protected ScheduledFuture` `scheduledFailover`

### Constructor Summary

Constructors
`protected` `AbstractMastersListener(JDBCUrl jdbcUrl)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `addToBlacklist(HostAddress hostAddress)` After a failover, put the hostAddress in a static list so the other connection will not take this host in account for a time
`Map<HostAddress,Long>` `getBlacklist()`
`Protocol` `getCurrentProtocol()`
`SearchFilter` `getFilterForFailedHost()`
`JDBCUrl` `getJdbcUrl()`
`long` `getMasterHostFailTimestamp()`
`FailoverProxy` `getProxy()`
`int` `getRetriesAllDown()`
`HandleErrorResult` `handleFailover(Method method, Object[] args)`
`boolean` `hasHostFail()`
`abstract void` `initializeConnection()`
`Object` `invoke(Method method, Object[] args)`
`boolean` `isAutoReconnect()`
`boolean` `isClosed()`
`boolean` `isExplicitClosed()`
`boolean` `isMasterHostFail()`
`boolean` `isReadOnly()`
`protected void` `launchFailLoopIfNotlaunched(boolean now)` launch the scheduler loop every 250 milliseconds, to reconnect a failed connection.
`abstract void` `preClose()`
`abstract void` `preExecute()`
`abstract HandleErrorResult` `primaryFail(Method method, Object[] args)`
`abstract void` `reconnect()`
`abstract void` `reconnectFailedConnection(SearchFilter filter)`
`HandleErrorResult` `relaunchOperation(Method method, Object[] args)` After a failover that has bean done, relaunche the operation that was in progress.
`protected void` `resetMasterFailoverData()`
`void` `resetOldsBlackListHosts()` Permit to remove Host to blacklist after loadBalanceBlacklistTimeout seconds
`void` `setExplicitClosed(boolean explicitClosed)`
`boolean` `setMasterHostFail()`
`void` `setProxy(FailoverProxy proxy)`
`protected void` `setSessionReadOnly(boolean readOnly, Protocol protocol)`
`abstract boolean` `shouldReconnect()`
`protected void` `stopFailover()`
`abstract void` `switchReadOnlyConnection(Boolean readonly)`
`void` `syncConnection(Protocol from, Protocol to)` when switching between 2 connections, report existing connection parameter to the new used connection
`abstract void` `throwFailoverMessage(QueryException queryException, boolean reconnected)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.mariadb.jdbc.internal.mysql.listener.Listener

`foundActiveMaster`

### Field Detail

#### blacklist

    protected static Map<HostAddress,Long> blacklist

list the recent failedConnection

#### jdbcUrl

    public final JDBCUrl jdbcUrl

#### currentConnectionAttempts

    protected AtomicInteger currentConnectionAttempts

#### currentReadOnlyAsked

    protected AtomicBoolean currentReadOnlyAsked

#### isLooping

    protected AtomicBoolean isLooping

#### scheduledFailover

    protected ScheduledFuture scheduledFailover

#### currentProtocol

    protected Protocol currentProtocol

#### proxy

    protected FailoverProxy proxy

#### lastRetry

    protected long lastRetry

#### explicitClosed

    protected boolean explicitClosed

#### executorService

    protected ScheduledExecutorService executorService

### Constructor Detail

#### AbstractMastersListener

    protected AbstractMastersListener(JDBCUrl jdbcUrl)

### Method Detail

#### getProxy

    public FailoverProxy getProxy()

Specified by:
  `getProxy` in interface `Listener`

#### setProxy

    public void setProxy(FailoverProxy proxy)

Specified by:
  `setProxy` in interface `Listener`

#### getBlacklist

    public Map<HostAddress,Long> getBlacklist()

Specified by:
  `getBlacklist` in interface `Listener`

#### handleFailover

    public HandleErrorResult handleFailover(Method method,
                                            Object[] args)
                                     throws Throwable

Specified by:
  `handleFailover` in interface `Listener`
Throws:
  `Throwable`

#### addToBlacklist

    public void addToBlacklist(HostAddress hostAddress)

After a failover, put the hostAddress in a static list so the other connection will not take this host in account for a time

Parameters:
  `hostAddress` - the HostAddress to add to blacklist

#### resetOldsBlackListHosts

    public void resetOldsBlackListHosts()

Permit to remove Host to blacklist after loadBalanceBlacklistTimeout seconds

#### resetMasterFailoverData

    protected void resetMasterFailoverData()

#### setSessionReadOnly

    protected void setSessionReadOnly(boolean readOnly,
                                      Protocol protocol)
                               throws QueryException

Throws:
  `QueryException`

#### stopFailover

    protected void stopFailover()

#### launchFailLoopIfNotlaunched

    protected void launchFailLoopIfNotlaunched(boolean now)

launch the scheduler loop every 250 milliseconds, to reconnect a failed connection. Will verify if there is an existing scheduler

Parameters:
  `now` - now will launch the loop immediatly, 250ms after if false

#### getCurrentProtocol

    public Protocol getCurrentProtocol()

#### getMasterHostFailTimestamp

    public long getMasterHostFailTimestamp()

#### setMasterHostFail

    public boolean setMasterHostFail()

#### isMasterHostFail

    public boolean isMasterHostFail()

#### hasHostFail

    public boolean hasHostFail()

#### getFilterForFailedHost

    public SearchFilter getFilterForFailedHost()

#### relaunchOperation

    public HandleErrorResult relaunchOperation(Method method,
                                               Object[] args)
                                        throws IllegalAccessException,
                                               InvocationTargetException

After a failover that has bean done, relaunche the operation that was in progress. In case of special operation that crash serveur, doesn't relaunched it;

Parameters:
  `method` - the methode accessed
  `args` - the parameters
Returns:
  An object that indicate the result or that the exception as to be thrown
Throws:
  `IllegalAccessException` - if the initial call is not permit
  `InvocationTargetException` - if there is any error relaunching initial method

#### invoke

    public Object invoke(Method method,
                         Object[] args)
                  throws Throwable

Specified by:
  `invoke` in interface `Listener`
Throws:
  `Throwable`

#### syncConnection

    public void syncConnection(Protocol from,
                               Protocol to)
                        throws QueryException

when switching between 2 connections, report existing connection parameter to the new used connection

Specified by:
  `syncConnection` in interface `Listener`
Parameters:
  `from` - used connection
  `to` - will-be-current connection
Throws:
  `QueryException` - if catalog cannot be set

#### isClosed

    public boolean isClosed()

Specified by:
  `isClosed` in interface `Listener`

#### isReadOnly

    public boolean isReadOnly()

Specified by:
  `isReadOnly` in interface `Listener`

#### isExplicitClosed

    public boolean isExplicitClosed()

Specified by:
  `isExplicitClosed` in interface `Listener`

#### setExplicitClosed

    public void setExplicitClosed(boolean explicitClosed)

Specified by:
  `setExplicitClosed` in interface `Listener`

#### getRetriesAllDown

    public int getRetriesAllDown()

Specified by:
  `getRetriesAllDown` in interface `Listener`

#### isAutoReconnect

    public boolean isAutoReconnect()

Specified by:
  `isAutoReconnect` in interface `Listener`

#### getJdbcUrl

    public JDBCUrl getJdbcUrl()

Specified by:
  `getJdbcUrl` in interface `Listener`

#### initializeConnection

    public abstract void initializeConnection()
                                       throws QueryException

Specified by:
  `initializeConnection` in interface `Listener`
Throws:
  `QueryException`

#### preExecute

    public abstract void preExecute()
                             throws QueryException

Specified by:
  `preExecute` in interface `Listener`
Throws:
  `QueryException`

#### preClose

    public abstract void preClose()
                           throws SQLException

Specified by:
  `preClose` in interface `Listener`
Throws:
  `SQLException`

#### shouldReconnect

    public abstract boolean shouldReconnect()

Specified by:
  `shouldReconnect` in interface `Listener`

#### reconnectFailedConnection

    public abstract void reconnectFailedConnection(SearchFilter filter)
                                            throws QueryException

Specified by:
  `reconnectFailedConnection` in interface `Listener`
Throws:
  `QueryException`

#### switchReadOnlyConnection

    public abstract void switchReadOnlyConnection(Boolean readonly)
                                           throws QueryException

Specified by:
  `switchReadOnlyConnection` in interface `Listener`
Throws:
  `QueryException`

#### primaryFail

    public abstract HandleErrorResult primaryFail(Method method,
                                                  Object[] args)
                                           throws Throwable

Specified by:
  `primaryFail` in interface `Listener`
Throws:
  `Throwable`

#### throwFailoverMessage

    public abstract void throwFailoverMessage(QueryException queryException,
                                              boolean reconnected)
                                       throws QueryException

Specified by:
  `throwFailoverMessage` in interface `Listener`
Throws:
  `QueryException`

#### reconnect

    public abstract void reconnect()
                            throws QueryException

Specified by:
  `reconnect` in interface `Listener`
Throws:
  `QueryException`