CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-curator--curator-client

Low-level API for Apache ZooKeeper client library providing connection management, retry policies, and basic ZooKeeper operations

Pending
Overview
Eval results
Files

retry-policies.mddocs/

Retry Policies

Comprehensive retry policy implementations for handling transient failures and network issues in distributed ZooKeeper operations. All retry policies implement the RetryPolicy interface and provide different strategies for timing and limiting retry attempts.

Capabilities

RetryPolicy Interface

Core interface that defines the contract for retry behavior in Apache Curator operations.

/**
 * Interface for retry policies that determine when operations should be retried
 */
public interface RetryPolicy {
    /**
     * Determine if an operation should be retried
     * @param retryCount Number of retries already attempted (0-based)
     * @param elapsedTimeMs Total elapsed time since first attempt
     * @param sleeper Sleeper for implementing retry delays
     * @return true if retry should be attempted, false to give up
     */
    boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper);
}

RetrySleeper Interface

Abstraction for sleeping during retry operations, allowing for custom sleep implementations and testing.

/**
 * Interface for sleeping during retry operations
 */
public interface RetrySleeper {
    /**
     * Sleep for the specified duration
     * @param time Duration to sleep
     * @param unit Time unit for the duration
     * @throws InterruptedException if sleep is interrupted
     */
    void sleepFor(long time, TimeUnit unit) throws InterruptedException;
}

Exponential Backoff Retry

Implements exponential backoff with jitter for retry delays, ideal for distributed systems to avoid thundering herd problems.

/**
 * Retry policy with exponential backoff and jitter
 */
public class ExponentialBackoffRetry implements RetryPolicy {
    /**
     * Create exponential backoff retry with unlimited max sleep time
     * @param baseSleepTimeMs Base sleep time in milliseconds
     * @param maxRetries Maximum number of retry attempts
     */
    public ExponentialBackoffRetry(int baseSleepTimeMs, int maxRetries);
    
    /**
     * Create exponential backoff retry with bounded sleep time
     * @param baseSleepTimeMs Base sleep time in milliseconds
     * @param maxRetries Maximum number of retry attempts
     * @param maxSleepMs Maximum sleep time between retries
     */
    public ExponentialBackoffRetry(int baseSleepTimeMs, int maxRetries, int maxSleepMs);
}

Usage Examples:

import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.CuratorZookeeperClient;

// Basic exponential backoff: 1s base, 3 retries, unbounded max sleep
RetryPolicy basicRetry = new ExponentialBackoffRetry(1000, 3);

// Bounded exponential backoff: 500ms base, 5 retries, max 10s sleep
RetryPolicy boundedRetry = new ExponentialBackoffRetry(500, 5, 10000);

// Use with client
CuratorZookeeperClient client = new CuratorZookeeperClient(
    "localhost:2181", 5000, 5000, null, basicRetry);

Bounded Exponential Backoff Retry

Extension of exponential backoff retry with explicit bounds on sleep time to prevent extremely long delays.

/**
 * Exponential backoff retry with explicit bounds on sleep time
 */
public class BoundedExponentialBackoffRetry extends ExponentialBackoffRetry {
    /**
     * Create bounded exponential backoff retry
     * @param baseSleepTimeMs Base sleep time in milliseconds
     * @param maxSleepTimeMs Maximum sleep time between retries
     * @param maxRetries Maximum number of retry attempts
     */
    public BoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries);
}

Fixed Count Retry

Retry policy that attempts a fixed number of retries with constant sleep intervals.

/**
 * Retry policy with fixed number of attempts and constant sleep time
 */
public class RetryNTimes implements RetryPolicy {
    /**
     * Create fixed count retry policy
     * @param n Number of retry attempts (after initial failure)
     * @param sleepMsBetweenRetries Sleep time in milliseconds between retries
     */
    public RetryNTimes(int n, int sleepMsBetweenRetries);
}

Usage Examples:

import org.apache.curator.retry.RetryNTimes;

// Retry 3 times with 2 second intervals
RetryPolicy fixedRetry = new RetryNTimes(3, 2000);

// Retry 5 times with 500ms intervals  
RetryPolicy quickRetry = new RetryNTimes(5, 500);

Single Retry

Simple retry policy that attempts exactly one retry with a fixed delay.

/**
 * Retry policy that attempts exactly one retry
 */
public class RetryOneTime implements RetryPolicy {
    /**
     * Create single retry policy
     * @param sleepMsBetweenRetry Sleep time in milliseconds before retry
     */
    public RetryOneTime(int sleepMsBetweenRetry);
}

Usage Examples:

import org.apache.curator.retry.RetryOneTime;

// Single retry after 1 second
RetryPolicy singleRetry = new RetryOneTime(1000);

Indefinite Retry

Retry policy that continues retrying indefinitely until interrupted, useful for critical operations that must eventually succeed.

/**
 * Retry policy that retries indefinitely until interrupted
 */
public class RetryForever implements RetryPolicy {
    /**
     * Create indefinite retry policy
     * @param retryIntervalMs Interval in milliseconds between retry attempts
     */
    public RetryForever(int retryIntervalMs);
}

Usage Examples:

import org.apache.curator.retry.RetryForever;

// Retry forever with 5 second intervals
RetryPolicy persistentRetry = new RetryForever(5000);

// Use with critical operations that must succeed
CuratorZookeeperClient criticalClient = new CuratorZookeeperClient(
    "localhost:2181", 30000, 15000, null, persistentRetry);

Time-Bounded Retry

Retry policy that continues retrying until a total elapsed time threshold is reached.

/**
 * Retry policy that retries until total elapsed time threshold is reached
 */
public class RetryUntilElapsed implements RetryPolicy {
    /**
     * Create time-bounded retry policy
     * @param maxElapsedTimeMs Maximum total elapsed time for all retries
     * @param sleepMsBetweenRetries Sleep time in milliseconds between retries
     */
    public RetryUntilElapsed(int maxElapsedTimeMs, int sleepMsBetweenRetries);
}

Usage Examples:

import org.apache.curator.retry.RetryUntilElapsed;

// Retry for up to 30 seconds with 2 second intervals
RetryPolicy timeBoundedRetry = new RetryUntilElapsed(30000, 2000);

// Use for operations with hard time limits
CuratorZookeeperClient timedClient = new CuratorZookeeperClient(
    "localhost:2181", 5000, 5000, null, timeBoundedRetry);

Base Sleeping Retry Class

Abstract base class for retry policies that implement sleep-based retry behavior.

/**
 * Abstract base class for retry policies that sleep between attempts
 */
public abstract class SleepingRetry implements RetryPolicy {
    // Base functionality for sleep-based retry policies
    // Concrete implementations provide specific sleep calculation logic
}

Retry Policy Selection Guide

ExponentialBackoffRetry

Best for: Most distributed system scenarios where you want to back off progressively Use when: Network issues are common and you want to reduce load during outages

RetryNTimes

Best for: Operations with known failure patterns or when you need predictable retry behavior Use when: You have specific SLA requirements or testing scenarios

RetryOneTime

Best for: Quick operations where multiple retries are not cost-effective Use when: Failures are rare and operations are lightweight

RetryForever

Best for: Critical operations that must eventually succeed Use when: System availability is more important than operation latency

RetryUntilElapsed

Best for: Operations with hard time constraints or SLA requirements Use when: You need to guarantee operation completion within a specific time window

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-curator--curator-client

docs

client-connection.md

connection-handling.md

ensemble-providers.md

index.md

path-utilities.md

retry-policies.md

tracing-metrics.md

tile.json