## 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.

Field Summary
`protected Protocol` `masterProtocol`
`protected Protocol` `secondaryProtocol`

Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener
`waitNewMasterProtocol, waitNewSecondaryProtocol`

Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener
`currentConnectionAttempts, currentProtocol, currentReadOnlyAsked, explicitClosed, lastQueryNanos, lastRetry, proxy, urlParser`

Constructor Summary
`MastersSlavesListener(UrlParser urlParser)` Initialisation.

Method Summary
`protected void` `checkInitialConnection(SQLException queryException)`
`boolean` `checkMasterStatus(SearchFilter searchFilter)` Check master status.
`void` `checkWaitingConnection()` Verify that there is waiting connection that have to replace failing one.
`List<HostAddress>` `connectedHosts()` List current connected HostAddress.
`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` `handleFailLoop()`
`void` `initializeConnection()` Initialize connections.
`boolean` `isMasterConnected()`
`void` `lockAndSwitchMaster(Protocol newMasterProtocol)` Use the parameter newMasterProtocol as new current master connection.
`void` `lockAndSwitchSecondary(Protocol newSecondaryProtocol)` Use the parameter newSecondaryProtocol as new current secondary connection.
`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.
`protected void` `removeListenerFromSchedulers()`
`void` `rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult, boolean mustBeOnMaster)`
`HandleErrorResult` `secondaryFail(Method method, Object[] args)` To handle the newly detected failover on the secondary connection.
`void` `switchReadOnlyConnection(Boolean mustBeReadOnly)` Switch to a read-only(secondary) or read and write connection(master).

Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener
`getFilterForFailedHost, getSecondaryHostFailNanos, handleFailover, hasHostFail, isMasterHostFailReconnect, isSecondaryHostFail, isSecondaryHostFailReconnect, resetMasterFailoverData, resetSecondaryFailoverData, setSecondaryHostFail`

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

`addToBlacklist, canRetryFailLoop, clearBlacklist, closeConnection, getBlacklistKeys, getCurrentProtocol, getLastQueryNanos, getMasterHostFailNanos, getProxy, getRetriesAllDown, getUrlParser, invoke, invoke, isAutoReconnect, isClosed, isExplicitClosed, isMasterHostFail, isQueryRelaunchable, isReadOnly, pingMasterProtocol, preAutoReconnect, relaunchOperation, removeFromBlacklist, resetOldsBlackListHosts, setMasterHostFail, setProxy, setSessionReadOnly, syncConnection, throwFailoverMessage`

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

Constructor Detail

### MastersSlavesListener

    public MastersSlavesListener(UrlParser urlParser)

  Initialisation.

  Parameters:
    `urlParser` - connection string object.

Method Detail

### removeListenerFromSchedulers

    protected void removeListenerFromSchedulers()

  Overrides:
    `removeListenerFromSchedulers` in class `AbstractMastersListener`

### initializeConnection

    public void initializeConnection()
                              throws SQLException

  Initialize connections.

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

### checkInitialConnection

    protected void checkInitialConnection(SQLException queryException)
                                   throws SQLException

  Throws:
    `SQLException`

### 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 SQLException

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

### checkWaitingConnection

    public void checkWaitingConnection()
                                throws SQLException

  Verify that there is waiting connection that have to replace failing one. If there is replace failed connection with new one.

  Throws:
    `SQLException` - if error occur

### reconnectFailedConnection

    public void reconnectFailedConnection(SearchFilter searchFilter)
                                   throws SQLException

  Loop to connect.

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

### foundActiveMaster

    public void foundActiveMaster(Protocol newMasterProtocol)

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

  Parameters:
    `newMasterProtocol` - the new active connection

### lockAndSwitchMaster

    public void lockAndSwitchMaster(Protocol newMasterProtocol)
                             throws ReconnectDuringTransactionException

  Use the parameter newMasterProtocol as new current master connection.

  Lock must be set

  Parameters:
    `newMasterProtocol` - new master connection
  Throws:
    `ReconnectDuringTransactionException` - if there was an active transaction.

### foundActiveSecondary

    public void foundActiveSecondary(Protocol newSecondaryProtocol)
                              throws SQLException

  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:
    `SQLException` - if switch failed

### lockAndSwitchSecondary

    public void lockAndSwitchSecondary(Protocol newSecondaryProtocol)
                                throws SQLException

  Use the parameter newSecondaryProtocol as new current secondary connection.

  Parameters:
    `newSecondaryProtocol` - new secondary connection
  Throws:
    `SQLException` - if an error occur during setting session read-only

### switchReadOnlyConnection

    public void switchReadOnlyConnection(Boolean mustBeReadOnly)
                                  throws SQLException

  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:
    `SQLException` - 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 SQLException

  Reconnect failed connection.

  Specified by:
    `reconnect` in interface `Listener`
  Specified by:
    `reconnect` in class `AbstractMastersListener`
  Throws:
    `SQLException` - 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

### handleFailLoop

    public void handleFailLoop()

  Specified by:
    `handleFailLoop` in class `AbstractMastersListener`

### isMasterConnected

    public boolean isMasterConnected()

### checkMasterStatus

    public boolean checkMasterStatus(SearchFilter searchFilter)

  Check master status.

  Specified by:
    `checkMasterStatus` in interface `Listener`
  Specified by:
    `checkMasterStatus` in class `AbstractMastersListener`
  Parameters:
    `searchFilter` - search filter
  Returns:
    has some status changed

### rePrepareOnSlave

    public void rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult,
                                 boolean mustBeOnMaster)
                          throws SQLException

  Throws:
    `SQLException`

### connectedHosts

    public List<HostAddress> connectedHosts()

  List current connected HostAddress.

  Returns:
    hostAddress List.

Copyright © 2017. All rights reserved.