org.mariadb.jdbc.internal.failover.impl

## Class MastersSlavesListener

- java.lang.Object
- - org.mariadb.jdbc.internal.failover.AbstractMastersListener
  - - org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener
    - - org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener

All Implemented Interfaces:
  Listener

Direct Known Subclasses:
  AuroraListener

    public class MastersSlavesListener
    extends AbstractMastersSlavesListener

this class handle the operation when multiple hosts.

### Nested Class Summary

Nested Classes
`protected class` `MastersSlavesListener.PingLoop` private class to chech of currents connections are still ok.

### Nested classes/interfaces inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener

`AbstractMastersListener.FailLoop`

### Field Summary

Fields
`protected long` `lastQueryTime`
`protected Protocol` `masterProtocol`
`protected ScheduledFuture` `scheduledPing`
`protected Protocol` `secondaryProtocol`

### Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener

`queriesSinceFailover`

### Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener

`blacklist, currentConnectionAttempts, currentProtocol, currentReadOnlyAsked, executorService, explicitClosed, isLooping, lastRetry, proxy, scheduledFailover, urlParser`

### Constructor Summary

Constructors
Constructor and Description
`MastersSlavesListener(UrlParser urlParser)` Initialisation.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `checkInitialConnection()`
`void` `checkMasterStatus(SearchFilter searchFilter)` Check master status.
`void` `foundActiveMaster(Protocol newMasterProtocol)` Method called when a new Master connection is found after a fallback.
`void` `foundActiveSecondary(Protocol newSecondaryProtocol)` Method called when a new secondary connection is found after a fallback.
`void` `initializeConnection()` Initialize connections.
`void` `preClose()` Called after a call on Connection.close().
`void` `preExecute()`
`HandleErrorResult` `primaryFail(Method method, Object[] args)` To handle the newly detected failover on the master connection.
`void` `reconnect()` Reconnect failed connection.
`void` `reconnectFailedConnection(SearchFilter searchFilter)` Loop to connect.
`HandleErrorResult` `secondaryFail(Method method, Object[] args)` To handle the newly detected failover on the secondary connection.
`boolean` `shouldReconnect()` When failing to a different type of host, when to retry So he doesn't appear here.
`void` `switchReadOnlyConnection(Boolean mustBeReadOnly)` Switch to a read-only(secondary) or read and write connection(master).
`void` `throwFailoverMessage(QueryException queryException, boolean reconnected)` Throw a human readable message after a failoverException.

### Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener

`getFilterForFailedHost, getSecondaryHostFailTimestamp, handleFailover, hasHostFail, isSecondaryHostFail, resetMasterFailoverData, resetSecondaryFailoverData, setSecondaryHostFail`

### Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener

`addToBlacklist, clearBlacklist, getBlacklist, getCurrentProtocol, getMasterHostFailTimestamp, getProxy, getRetriesAllDown, getUrlParser, invoke, isAutoReconnect, isClosed, isExplicitClosed, isMasterHostFail, isReadOnly, launchFailLoopIfNotlaunched, relaunchOperation, resetOldsBlackListHosts, setExplicitClosed, setMasterHostFail, setProxy, setSessionReadOnly, stopFailover, syncConnection`

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

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

### Field Detail

#### masterProtocol

    protected Protocol masterProtocol

#### secondaryProtocol

    protected Protocol secondaryProtocol

#### lastQueryTime

    protected long lastQueryTime

#### scheduledPing

    protected ScheduledFuture scheduledPing

### Constructor Detail

#### MastersSlavesListener

    public MastersSlavesListener(UrlParser urlParser)

Initialisation.

Parameters:
  `urlParser` - connection string object.

### Method Detail

#### initializeConnection

    public void initializeConnection()
                              throws QueryException

Initialize connections.

Specified by:
  `initializeConnection` in interface `Listener`
Specified by:
  `initializeConnection` in class `AbstractMastersListener`
Throws:
  `QueryException` - if a connection error append.

#### checkInitialConnection

    protected void checkInitialConnection()

#### preClose

    public void preClose()
                  throws SQLException

Called after a call on Connection.close(). Will explicitly closed all connections.

Specified by:
  `preClose` in interface `Listener`
Specified by:
  `preClose` in class `AbstractMastersListener`
Throws:
  `SQLException` - if error append during closing those connections.

#### preExecute

    public void preExecute()
                    throws QueryException

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

#### shouldReconnect

    public boolean shouldReconnect()

When failing to a different type of host, when to retry So he doesn't appear here.

Specified by:
  `shouldReconnect` in interface `Listener`
Specified by:
  `shouldReconnect` in class `AbstractMastersListener`
Returns:
  true if should reconnect.

#### reconnectFailedConnection

    public void reconnectFailedConnection(SearchFilter searchFilter)
                                   throws QueryException

Loop to connect.

Specified by:
  `reconnectFailedConnection` in interface `Listener`
Specified by:
  `reconnectFailedConnection` in class `AbstractMastersListener`
Throws:
  `QueryException` - if there is any error during reconnection
  `QueryException` - sqlException

#### foundActiveMaster

    public void foundActiveMaster(Protocol newMasterProtocol)

Method called when a new Master connection is found after a fallback.

Parameters:
  `newMasterProtocol` - the new active connection

#### foundActiveSecondary

    public void foundActiveSecondary(Protocol newSecondaryProtocol)
                              throws QueryException

Method called when a new secondary connection is found after a fallback.

Specified by:
  `foundActiveSecondary` in class `AbstractMastersSlavesListener`
Parameters:
  `newSecondaryProtocol` - the new active connection
Throws:
  `QueryException`

#### switchReadOnlyConnection

    public void switchReadOnlyConnection(Boolean mustBeReadOnly)
                                  throws QueryException

Switch to a read-only(secondary) or read and write connection(master).

Specified by:
  `switchReadOnlyConnection` in interface `Listener`
Specified by:
  `switchReadOnlyConnection` in class `AbstractMastersListener`
Parameters:
  `mustBeReadOnly` - the read-only status asked
Throws:
  `QueryException` - if operation hasn't change protocol

#### primaryFail

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

To handle the newly detected failover on the master connection.

Specified by:
  `primaryFail` in interface `Listener`
Specified by:
  `primaryFail` in class `AbstractMastersListener`
Parameters:
  `method` - the initial called method
  `args` - the initial args
Returns:
  an object to indicate if the previous Exception must be thrown, or the object resulting if a failover worked
Throws:
  `Throwable` - if failover has not been catch

#### reconnect

    public void reconnect()
                   throws QueryException

Reconnect failed connection.

Specified by:
  `reconnect` in interface `Listener`
Specified by:
  `reconnect` in class `AbstractMastersListener`
Throws:
  `QueryException` - if reconnection has failed

#### secondaryFail

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

To handle the newly detected failover on the secondary connection.

Specified by:
  `secondaryFail` in class `AbstractMastersSlavesListener`
Parameters:
  `method` - the initial called method
  `args` - the initial args
Returns:
  an object to indicate if the previous Exception must be thrown, or the object resulting if a failover worked
Throws:
  `Throwable` - if failover has not catch error

#### checkMasterStatus

    public void checkMasterStatus(SearchFilter searchFilter)
                           throws QueryException

Check master status.

Parameters:
  `searchFilter` - search filter
Throws:
  `QueryException` - exception

#### throwFailoverMessage

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

Throw a human readable message after a failoverException.

Specified by:
  `throwFailoverMessage` in interface `Listener`
Specified by:
  `throwFailoverMessage` in class `AbstractMastersListener`
Parameters:
  `queryException` - internal error
  `reconnected` - connection status
Throws:
  `QueryException` - error with failover information