Package com.guinetik.rr.http
Class RocketClientFactory.Builder
- java.lang.Object
-
- com.guinetik.rr.http.RocketClientFactory.Builder
-
- Enclosing class:
- RocketClientFactory
public static class RocketClientFactory.Builder extends Object
Builder class for constructing RocketClient instances with various decorators.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RocketClientbuild()Builds a synchronous RocketClient with the configured settings.AsyncHttpClientbuildAsync()Builds an asynchronous RocketClient with the configured settings.FluentHttpClientbuildFluent()Builds a fluent HTTP client with the configured settings.RocketClientFactory.BuilderwithCircuitBreaker()Enables the circuit breaker pattern with default settings.RocketClientFactory.BuilderwithCircuitBreaker(int failureThreshold, long resetTimeoutMs)Enables the circuit breaker pattern with custom settings.RocketClientFactory.BuilderwithCircuitBreaker(int failureThreshold, long resetTimeoutMs, long failureDecayTimeMs, CircuitBreakerClient.FailurePolicy failurePolicy)Enables the circuit breaker pattern with fully customized settings.RocketClientFactory.BuilderwithCustomDecorator(UnaryOperator<RocketClient> decorator)Adds a custom decorator function that will be applied to the client.RocketClientFactory.BuilderwithExecutorService(ExecutorService executorService)Sets the executor service for async operations.RocketClientFactory.BuilderwithFailurePredicate(Predicate<RocketRestException> failurePredicate)Sets a custom failure predicate for the circuit breaker.RocketClientFactory.BuilderwithInterceptor(RequestInterceptor interceptor)Adds an interceptor to the client.RocketClientFactory.BuilderwithMaxRetries(int maxRetries)Sets the maximum number of retries allowed by the interceptor chain.RocketClientFactory.BuilderwithOptions(RocketRestOptions options)Sets the client options.RocketClientFactory.BuilderwithRetry()Adds retry capability with default settings.RocketClientFactory.BuilderwithRetry(int maxRetries, long initialDelayMs)Adds retry capability with custom retry count and delay.RocketClientFactory.BuilderwithRetry(int maxRetries, long initialDelayMs, double backoffMultiplier)Adds retry capability with exponential backoff.
-
-
-
Method Detail
-
withOptions
public RocketClientFactory.Builder withOptions(RocketRestOptions options)
Sets the client options.- Parameters:
options- The RocketRestOptions to use- Returns:
- this builder instance
-
withExecutorService
public RocketClientFactory.Builder withExecutorService(ExecutorService executorService)
Sets the executor service for async operations.- Parameters:
executorService- The executor service to use- Returns:
- this builder instance
-
withCircuitBreaker
public RocketClientFactory.Builder withCircuitBreaker()
Enables the circuit breaker pattern with default settings.- Returns:
- this builder instance
-
withCircuitBreaker
public RocketClientFactory.Builder withCircuitBreaker(int failureThreshold, long resetTimeoutMs)
Enables the circuit breaker pattern with custom settings.- Parameters:
failureThreshold- Number of failures before opening circuitresetTimeoutMs- Timeout in ms before trying to close the circuit- Returns:
- this builder instance
-
withCircuitBreaker
public RocketClientFactory.Builder withCircuitBreaker(int failureThreshold, long resetTimeoutMs, long failureDecayTimeMs, CircuitBreakerClient.FailurePolicy failurePolicy)
Enables the circuit breaker pattern with fully customized settings.- Parameters:
failureThreshold- Number of failures before opening circuitresetTimeoutMs- Timeout in ms before trying to close the circuitfailureDecayTimeMs- Time after which failure count starts to decayfailurePolicy- Strategy to determine what counts as a failure- Returns:
- this builder instance
-
withFailurePredicate
public RocketClientFactory.Builder withFailurePredicate(Predicate<RocketRestException> failurePredicate)
Sets a custom failure predicate for the circuit breaker.- Parameters:
failurePredicate- Custom predicate to determine what counts as a failure- Returns:
- this builder instance
-
withCustomDecorator
public RocketClientFactory.Builder withCustomDecorator(UnaryOperator<RocketClient> decorator)
Adds a custom decorator function that will be applied to the client.- Parameters:
decorator- Function that takes a client and returns a decorated client- Returns:
- this builder instance
-
withInterceptor
public RocketClientFactory.Builder withInterceptor(RequestInterceptor interceptor)
Adds an interceptor to the client.Interceptors are applied in order based on their
RequestInterceptor.getOrder(). Lower order values run first for requests and last for responses.- Parameters:
interceptor- The interceptor to add- Returns:
- this builder instance
- See Also:
RequestInterceptor
-
withRetry
public RocketClientFactory.Builder withRetry()
Adds retry capability with default settings.Uses 3 retries with 1 second initial delay, 2x exponential backoff, and 30 second maximum delay.
- Returns:
- this builder instance
-
withRetry
public RocketClientFactory.Builder withRetry(int maxRetries, long initialDelayMs)
Adds retry capability with custom retry count and delay.- Parameters:
maxRetries- Maximum number of retriesinitialDelayMs- Initial delay between retries in milliseconds- Returns:
- this builder instance
-
withRetry
public RocketClientFactory.Builder withRetry(int maxRetries, long initialDelayMs, double backoffMultiplier)
Adds retry capability with exponential backoff.- Parameters:
maxRetries- Maximum number of retriesinitialDelayMs- Initial delay in millisecondsbackoffMultiplier- Multiplier for each retry (e.g., 2.0 doubles delay)- Returns:
- this builder instance
-
withMaxRetries
public RocketClientFactory.Builder withMaxRetries(int maxRetries)
Sets the maximum number of retries allowed by the interceptor chain.This is a global limit that applies across all retry interceptors. Default is 3.
- Parameters:
maxRetries- Maximum retries for the interceptor chain- Returns:
- this builder instance
-
build
public RocketClient build()
Builds a synchronous RocketClient with the configured settings.- Returns:
- A new RocketClient instance
-
buildFluent
public FluentHttpClient buildFluent()
Builds a fluent HTTP client with the configured settings. This client uses the Result pattern instead of exceptions.- Returns:
- A new FluentHttpClient instance
-
buildAsync
public AsyncHttpClient buildAsync()
Builds an asynchronous RocketClient with the configured settings.- Returns:
- A new AsyncHttpClient instance
- Throws:
IllegalStateException- if no executor service was provided
-
-