Class ConnectionStateManager

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ConnectionStateManager
    extends java.lang.Object
    implements java.io.Closeable
    Used internally to manage connection state
    • Constructor Detail

      • ConnectionStateManager

        public ConnectionStateManager​(CuratorFramework client,
                                      java.util.concurrent.ThreadFactory threadFactory,
                                      int sessionTimeoutMs,
                                      int sessionExpirationPercent)
        Parameters:
        client - the client
        threadFactory - thread factory to use or null for a default
        sessionTimeoutMs - the ZK session timeout in milliseconds
        sessionExpirationPercent - percentage of negotiated session timeout to use when simulating a session timeout. 0 means don't simulate at all
      • ConnectionStateManager

        public ConnectionStateManager​(CuratorFramework client,
                                      java.util.concurrent.ThreadFactory threadFactory,
                                      int sessionTimeoutMs,
                                      int sessionExpirationPercent,
                                      ConnectionStateListenerManagerFactory managerFactory)
        Parameters:
        client - the client
        threadFactory - thread factory to use or null for a default
        sessionTimeoutMs - the ZK session timeout in milliseconds
        sessionExpirationPercent - percentage of negotiated session timeout to use when simulating a session timeout. 0 means don't simulate at all
        managerFactory - manager factory to use
    • Method Detail

      • start

        public void start()
        Start the manager
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getListenable

        public Listenable<ConnectionStateListener> getListenable()
        Return the listenable
        Returns:
        listenable
        Since:
        4.2.0 return type has changed from ListenerContainer to Listenable
      • setToSuspended

        public boolean setToSuspended()
        Change to ConnectionState.SUSPENDED only if not already suspended and not lost
        Returns:
        true if connection is set to SUSPENDED
      • addStateChange

        public boolean addStateChange​(ConnectionState newConnectionState)
        Post a state change. If the manager is already in that state the change is ignored. Otherwise the change is queued for listeners.
        Parameters:
        newConnectionState - new state
        Returns:
        true if the state actually changed, false if it was already at that state
      • blockUntilConnected

        public boolean blockUntilConnected​(int maxWaitTime,
                                           java.util.concurrent.TimeUnit units)
                                    throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • isConnected

        public boolean isConnected()