Class ReadyMonitor


  • public class ReadyMonitor
    extends Object
    Provides a barrier to block operations until a resource signals that it is ready. This class encapsulates a wait / notify operation using a lock and condition. Instances are initialized with the resource unavailable - call setReady() when the resource is available
    • Constructor Detail

      • ReadyMonitor

        public ReadyMonitor​(String resourceName,
                            long timeout)
        Create an instance of a ready monitor.
        Parameters:
        resourceName - the resource name guarded by this monitor (used by logging)
        timeout - the max time in milliseconds this will block waiting.
    • Method Detail

      • test

        public boolean test()
        Non-blocking call to get ready state. It will throw is the ZooKeeper connection has closed (non-recoverable condition)
        Returns:
        true if resource is ready, false otherwise
      • isReady

        public void isReady()
        Method blocks until the resource is ready. If the resource does not become ready within the timeout an IllegalStateException is thrown.
        Throws:
        IllegalStateException - if the resource does not signal ready withing timeout.
      • setClosed

        public void setClosed()
        ZooKeeper has closed the connection. This is a terminal state that cannot be recoved from without creating a new ZooKeeper client.
      • setReady

        public void setReady()
        Indicate that the resource is ready.
      • clearReady

        public void clearReady()
        Indicate that resource is NOT available and that calls to isReady() should block.