## org.mariadb.jdbc.internal.failover.impl
Class MastersFailoverListener

    java.lang.Object
      org.mariadb.jdbc.internal.failover.AbstractMastersListener
          org.mariadb.jdbc.internal.failover.impl.MastersFailoverListener

All Implemented Interfaces:
  Listener

    public class MastersFailoverListener

extends AbstractMastersListener

Field Summary

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

Constructor Summary
`MastersFailoverListener(UrlParser urlParser)` Initialisation.

Method Summary
`boolean` `checkMasterStatus(SearchFilter searchFilter)` Check master status.
`void` `foundActiveMaster(Protocol protocol)` method called when a new Master connection is found after a fallback.
`void` `handleFailLoop()` Add listener to FailoverLoop if master connection is not active, so a reconnection will be done.
`void` `initializeConnection()` Connect to database.
`boolean` `isMasterConnected()`
`void` `preClose()`
`void` `preExecute()` Before executing query, reconnect if connection is closed, and autoReconnect option is set.
`HandleErrorResult` `primaryFail(Method method, Object[] args)`
`void` `reconnect()` Try to reconnect connection.
`void` `reconnectFailedConnection(SearchFilter searchFilter)` Loop to connect failed hosts.
`void` `rePrepareOnSlave(ServerPrepareResult oldServerPrepareResult, boolean mustExecuteOnSlave)`
`void` `switchReadOnlyConnection(Boolean mustBeReadOnly)` Force session to read-only according to options.

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

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

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MastersFailoverListener

    public MastersFailoverListener(UrlParser urlParser)

  Initialisation.

  Parameters:
    `urlParser` - url options.

Method Detail

### initializeConnection

    public void initializeConnection()
                              throws SQLException

  Connect to database.

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

### preExecute

    public void preExecute()
                    throws SQLException

  Before executing query, reconnect if connection is closed, and autoReconnect option is set.

  Specified by:
    `preExecute` in interface `Listener`
  Specified by:
    `preExecute` in class `AbstractMastersListener`
  Throws:
    `SQLException` - if connection has been explicitly closed.

### preClose

    public void preClose()
                  throws SQLException

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

### primaryFail

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

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

### reconnectFailedConnection

    public void reconnectFailedConnection(SearchFilter searchFilter)
                                   throws SQLException

  Loop to connect failed hosts.

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

### switchReadOnlyConnection

    public void switchReadOnlyConnection(Boolean mustBeReadOnly)
                                  throws SQLException

  Force session to read-only according to options.

  Specified by:
    `switchReadOnlyConnection` in interface `Listener`
  Specified by:
    `switchReadOnlyConnection` in class `AbstractMastersListener`
  Parameters:
    `mustBeReadOnly` - is read-only flag
  Throws:
    `SQLException` - if a connection error occur

### foundActiveMaster

    public void foundActiveMaster(Protocol protocol)
                           throws SQLException

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

  Parameters:
    `protocol` - the new active connection
  Throws:
    `SQLException`

### reconnect

    public void reconnect()
                   throws SQLException

  Try to reconnect connection.

  Specified by:
    `reconnect` in interface `Listener`
  Specified by:
    `reconnect` in class `AbstractMastersListener`
  Throws:
    `SQLException` - if reconnect a new connection but there was an active transaction.

### handleFailLoop

    public void handleFailLoop()

  Add listener to FailoverLoop if master connection is not active, so a reconnection will be done. (the reconnection will be done by failover or if append before by the next query/method that will use the failed connection) Remove listener from FailoverLoop is master connection is active.

  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 mustExecuteOnSlave)

Copyright © 2017. All rights reserved.