Class ZooWorker

  • class ZooWorker
    extends java.lang.Object
    Provide a mechanism to perform an operation on ZooKeeper that is safe on disconnections and recoverable errors.
    • Field Detail

      • attempts

        int attempts
      • startTimeNanos

        long startTimeNanos
      • elapsedTimeMs

        long elapsedTimeMs
    • Method Detail

      • allowRetry

        public boolean allowRetry​(int rc)
      • nextRetryWaitTime

        public long nextRetryWaitTime()
      • isRecoverableException

        public static boolean isRecoverableException​(int rc)
        Check whether the given result code is recoverable by retry.
        rc - result code
        true if given result code is recoverable.
      • isRecoverableException

        public static boolean isRecoverableException​(org.apache.zookeeper.KeeperException exception)
        Check whether the given exception is recoverable by retry.
        exception - given exception
        true if given exception is recoverable.
      • syncCallWithRetries

        public static <T> T syncCallWithRetries​(ZooKeeperClient client,
                                                ZooWorker.ZooCallable<T> proc,
                                                RetryPolicy retryPolicy,
                                                OpStatsLogger statsLogger)
                                         throws org.apache.zookeeper.KeeperException,
        Execute a sync zookeeper operation with a given retry policy.
        client - ZooKeeper client.
        proc - Synchronous zookeeper operation wrapped in a Callable.
        retryPolicy - Retry policy to execute the synchronous operation.
        rateLimiter - Rate limiter for zookeeper calls
        statsLogger - Stats Logger for zookeeper client.
        result of the zookeeper operation
        org.apache.zookeeper.KeeperException - any non-recoverable exception or recoverable exception exhausted all retires.
        java.lang.InterruptedException - the operation is interrupted.