Package com.guinetik.rr.http
Class CircuitBreakerOpenException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.guinetik.rr.http.RocketRestException
-
- com.guinetik.rr.http.CircuitBreakerOpenException
-
- All Implemented Interfaces:
Serializable
public class CircuitBreakerOpenException extends RocketRestException
Exception thrown when a request is rejected due to an open circuit breaker.This exception indicates that the downstream service is considered unhealthy and requests are being fast-failed to prevent cascading failures. It provides timing information to help callers decide when to retry.
Handling Circuit Open
try { User user = client.get("/users/1", User.class); } catch (CircuitBreakerOpenException e) { long waitTime = e.getEstimatedMillisUntilReset(); if (waitTime > 0) { System.out.println("Service unavailable, retry in " + waitTime + "ms"); // Schedule retry after waitTime } else { // Circuit should be half-open soon, retry immediately System.out.println("Circuit may reset soon, retrying..."); } }Using with Fluent API
Result<User, ApiError> result = client.fluent().get("/users/1", User.class); result.match( user -> System.out.println("Success"), error -> { if (error.isCircuitOpen()) { System.out.println("Circuit breaker is open"); } } );- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
CircuitBreakerClient,RocketRestException, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CircuitBreakerOpenException(String message)Creates a new CircuitBreakerOpenException with the specified message.CircuitBreakerOpenException(String message, long millisSinceLastFailure, long resetTimeoutMs)Creates a new CircuitBreakerOpenException with the specified message and timing information about when the circuit might reset.CircuitBreakerOpenException(String message, Throwable cause, long millisSinceLastFailure, long resetTimeoutMs)Creates a new CircuitBreakerOpenException with the specified message, cause, and timing information about when the circuit might reset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThrowablegetCause()Gets the underlying cause of the circuit opening.longgetEstimatedMillisUntilReset()Gets an estimated time in milliseconds until the circuit might reset.longgetMillisSinceLastFailure()Gets the milliseconds since the last failure that caused the circuit to open.longgetResetTimeoutMs()Gets the configured timeout after which the circuit will try to reset.-
Methods inherited from class com.guinetik.rr.http.RocketRestException
getResponseBody, getStatusCode
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
CircuitBreakerOpenException
public CircuitBreakerOpenException(String message)
Creates a new CircuitBreakerOpenException with the specified message.- Parameters:
message- The error message
-
CircuitBreakerOpenException
public CircuitBreakerOpenException(String message, long millisSinceLastFailure, long resetTimeoutMs)
Creates a new CircuitBreakerOpenException with the specified message and timing information about when the circuit might reset.- Parameters:
message- The error messagemillisSinceLastFailure- Milliseconds since the last failureresetTimeoutMs- Milliseconds until the circuit will attempt to reset
-
CircuitBreakerOpenException
public CircuitBreakerOpenException(String message, Throwable cause, long millisSinceLastFailure, long resetTimeoutMs)
Creates a new CircuitBreakerOpenException with the specified message, cause, and timing information about when the circuit might reset.- Parameters:
message- The error messagecause- The cause of this exceptionmillisSinceLastFailure- Milliseconds since the last failureresetTimeoutMs- Milliseconds until the circuit will attempt to reset
-
-
Method Detail
-
getMillisSinceLastFailure
public long getMillisSinceLastFailure()
Gets the milliseconds since the last failure that caused the circuit to open.- Returns:
- milliseconds since the last failure, or 0 if not available
-
getResetTimeoutMs
public long getResetTimeoutMs()
Gets the configured timeout after which the circuit will try to reset.- Returns:
- reset timeout in milliseconds, or 0 if not available
-
getEstimatedMillisUntilReset
public long getEstimatedMillisUntilReset()
Gets an estimated time in milliseconds until the circuit might reset. A negative value indicates the circuit should have already attempted to reset.- Returns:
- estimated milliseconds until reset, or 0 if timing data is unavailable
-
-