Class MastersSlavesListener

    • Field Detail

      • listenerCount

        private static final java.util.concurrent.atomic.AtomicInteger listenerCount
      • logger

        private static final Logger logger
      • masterProtocol

        protected Protocol masterProtocol
      • secondaryProtocol

        protected Protocol secondaryProtocol
      • hostAddresses

        protected java.util.List<HostAddress> hostAddresses
    • Constructor Detail

      • MastersSlavesListener

        public MastersSlavesListener​(UrlParser urlParser,
                                     GlobalStateInfo globalInfo)
        Initialisation.
        Parameters:
        urlParser - connection string object.
        globalInfo - server global variables information
    • Method Detail

      • loadScheduler

        private static void loadScheduler()
      • invoke

        public java.lang.Object invoke​(java.lang.reflect.Method method,
                                       java.lang.Object[] args)
                                throws java.lang.Throwable
        Specified by:
        invoke in interface Listener
        Overrides:
        invoke in class AbstractMastersListener
        Throws:
        java.lang.Throwable
      • getTimeout

        public int getTimeout()
                       throws java.net.SocketException
        Get timeout (master connection possibly down).
        Specified by:
        getTimeout in interface Listener
        Overrides:
        getTimeout in class AbstractMastersListener
        Returns:
        socket timeout in ms
        Throws:
        java.net.SocketException - if socket exception
      • getServerThreadId

        public long getServerThreadId()
        Get current connection server id.
        Returns:
        server id.
      • checkInitialConnection

        protected void checkInitialConnection​(java.sql.SQLException queryException)
                                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • preAbort

        public void preAbort()
      • checkWaitingConnection

        public void checkWaitingConnection()
                                    throws java.sql.SQLException
        Verify that there is waiting connection that have to replace failing one. If there is replace failed connection with new one.
        Throws:
        java.sql.SQLException - if error occur
      • 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 java.sql.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:
        java.sql.SQLException - if switch failed
      • lockAndSwitchSecondary

        public void lockAndSwitchSecondary​(Protocol newSecondaryProtocol)
                                    throws java.sql.SQLException
        Use the parameter newSecondaryProtocol as new current secondary connection.
        Parameters:
        newSecondaryProtocol - new secondary connection
        Throws:
        java.sql.SQLException - if an error occur during setting session read-only
      • switchReadOnlyConnection

        public void switchReadOnlyConnection​(java.lang.Boolean mustBeReadOnly)
                                      throws java.sql.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:
        java.sql.SQLException - if operation hasn't change protocol
      • primaryFail

        public HandleErrorResult primaryFail​(java.lang.reflect.Method method,
                                             java.lang.Object[] args,
                                             boolean killCmd,
                                             boolean isClosed)
        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
        killCmd - is the fail due to a KILL cmd
        Returns:
        an object to indicate if the previous Exception must be thrown, or the object resulting if a failover worked
      • blackListAndCloseConnection

        private void blackListAndCloseConnection​(Protocol protocol)
      • reconnect

        public void reconnect()
                       throws java.sql.SQLException
        Reconnect failed connection.
        Specified by:
        reconnect in interface Listener
        Specified by:
        reconnect in class AbstractMastersListener
        Throws:
        java.sql.SQLException - if reconnection has failed
      • pingSecondaryProtocol

        private boolean pingSecondaryProtocol​(Protocol protocol)
        Ping secondary protocol. ! lock must be set !
        Parameters:
        protocol - socket to ping
        Returns:
        true if ping is valid.
      • secondaryFail

        public HandleErrorResult secondaryFail​(java.lang.reflect.Method method,
                                               java.lang.Object[] args,
                                               boolean killCmd)
                                        throws java.sql.SQLException
        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
        killCmd - is fail due to a KILL command
        Returns:
        an object to indicate if the previous Exception must be thrown, or the object resulting if a failover worked
        Throws:
        java.sql.SQLException - if relaunch operation fails
      • isMasterConnected

        public boolean isMasterConnected()
      • rePrepareOnSlave

        public void rePrepareOnSlave​(ServerPrepareResult oldServerPrepareResult,
                                     boolean mustBeOnMaster)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • connectedHosts

        public java.util.List<HostAddress> connectedHosts()
        List current connected HostAddress.
        Returns:
        hostAddress List.
      • reset

        public void reset()
                   throws java.sql.SQLException
        Reset state of master and slave connection.
        Throws:
        java.sql.SQLException - if command fail.