Skip to content

Commit e80e135

Browse files
committed
Issue ReactiveX#117: documentation update
1 parent 9283167 commit e80e135

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

README.adoc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,25 @@ The CircuitBreaker is implemented via a finite state machine with three states:
274274

275275
image::resilience4j-documentation/src/docs/asciidoc/images/state_machine.jpg[]
276276

277-
The CircuitBreaker does not know anything about the backend's state by itself, but uses the information provided by the decorators via `CircuitBreaker::onSuccess()` and `CircuitBreaker::onError(throwable)`. See example:
277+
The CircuitBreaker does not know anything about the backend's state by itself,
278+
but uses the information provided by the decorators
279+
via `CircuitBreaker::onSuccess` and `CircuitBreaker::onError`. See example:
278280

279281
[source,java]
280282
----
281-
static <T> Supplier<T> decorateSupplier(Supplier<T> supplier, CircuitBreaker circuitBreaker){
283+
static <T> Supplier<T> decorateSupplier(CircuitBreaker circuitBreaker, Supplier<T> supplier){
282284
return () -> {
283-
circuitBreaker.isCallPermitted();
285+
CircuitBreakerUtils.isCallPermitted(circuitBreaker);
286+
long start = System.nanoTime();
284287
try {
285288
T returnValue = supplier.get();
286-
circuitBreaker.onSuccess();
289+
long durationInNanos = System.nanoTime() - start;
290+
circuitBreaker.onSuccess(durationInNanos);
287291
return returnValue;
288-
} catch (Exception exception) {
289-
circuitBreaker.onFailure(exception);
290-
throw exception;
292+
} catch (Throwable throwable) {
293+
long durationInNanos = System.nanoTime() - start;
294+
circuitBreaker.onError(durationInNanos, throwable);
295+
throw throwable;
291296
}
292297
};
293298
}
@@ -304,7 +309,7 @@ The Ring Bit Buffer must be full, before the failure rate can be calculated.
304309
For example, if the size of the Ring Buffer is 10, then at least 10 calls must evaluated, before the failure rate can be calculated. If only 9 calls have been evaluated the CircuitBreaker will not trip open even if all 9 calls have failed.
305310

306311
After the time duration has elapsed, the CircuitBreaker state changes from `OPEN` to `HALF_OPEN` and allows calls to see if the backend is still unavailable or has become available again. The CircuitBreaker uses another (configurable) Ring Bit Buffer to evaluate the failure rate in the `HALF_OPEN` state. If the failure rate is above the configured threshold, the state changes back to `OPEN`. If the failure rate is below or equal to the threshold, the state changes back to `CLOSED`.
307-
`CircuitBreaker::onError(exception)` checks if the exception should be recorded as a failure or should be ignored. You can configure a custom `Predicate` which decides whether an exception should be recorded as a failure. The default Predicate records all exceptions as a failure.
312+
`CircuitBreaker::onError` checks if the exception should be recorded as a failure or should be ignored. You can configure a custom `Predicate` which decides whether an exception should be recorded as a failure. The default Predicate records all exceptions as a failure.
308313

309314
== RateLimiter implementation details
310315
Conceptually `RateLimiter` splits all nanoseconds from the start of epoch into cycles.

resilience4j-documentation/src/docs/asciidoc/usage_guide.adoc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,20 +483,23 @@ The CircuitBreaker is implemented via a finite state machine with three states:
483483

484484
image::images/state_machine.jpg[]
485485

486-
The CircuitBreaker does not know anything about the backend's state by itself, but uses the information provided by the decorators via `CircuitBreaker::onSuccess()` and `CircuitBreaker::onError(throwable)`. See example:
486+
The CircuitBreaker does not know anything about the backend's state by itself, but uses the information provided by the decorators via `CircuitBreaker::onSuccess` and `CircuitBreaker::onError`. See example:
487487

488488
[source,java]
489489
----
490-
static <T> Supplier<T> decorateSupplier(Supplier<T> supplier, CircuitBreaker circuitBreaker){
490+
static <T> Supplier<T> decorateSupplier(CircuitBreaker circuitBreaker, Supplier<T> supplier){
491491
return () -> {
492-
circuitBreaker.isCallPermitted();
492+
CircuitBreakerUtils.isCallPermitted(circuitBreaker);
493+
long start = System.nanoTime();
493494
try {
494495
T returnValue = supplier.get();
495-
circuitBreaker.onSuccess();
496+
long durationInNanos = System.nanoTime() - start;
497+
circuitBreaker.onSuccess(durationInNanos);
496498
return returnValue;
497-
} catch (Exception exception) {
498-
circuitBreaker.onFailure(exception);
499-
throw exception;
499+
} catch (Throwable throwable) {
500+
long durationInNanos = System.nanoTime() - start;
501+
circuitBreaker.onError(durationInNanos, throwable);
502+
throw throwable;
500503
}
501504
};
502505
}
@@ -513,7 +516,7 @@ The Ring Bit Buffer must be full, before the failure rate can be calculated.
513516
For example, if the size of the Ring Buffer is 10, then at least 10 calls must evaluated, before the failure rate can be calculated. If only 9 calls have been evaluated the CircuitBreaker will not trip open even if all 9 calls have failed.
514517

515518
After the time duration has elapsed, the CircuitBreaker state changes from `OPEN` to `HALF_OPEN` and allows calls to see if the backend is still unavailable or has become available again. The CircuitBreaker uses another (configurable) Ring Bit Buffer to evaluate the failure rate in the `HALF_OPEN` state. If the failure rate is above the configured threshold, the state changes back to `OPEN`. If the failure rate is below or equal to the threshold, the state changes back to `CLOSED`.
516-
`CircuitBreaker::onError(exception)` checks if the exception should be recorded as a failure or should be ignored. You can configure a custom `Predicate` which decides whether an exception should be recorded as a failure. The default Predicate records all exceptions as a failure.
519+
`CircuitBreaker::onError` checks if the exception should be recorded as a failure or should be ignored. You can configure a custom `Predicate` which decides whether an exception should be recorded as a failure. The default Predicate records all exceptions as a failure.
517520

518521
The CircuitBreaker publishes a stream of CircuitBreakerEvents to any Subscriber/Consumer who subscribes. An event can be a state transition or a recorded error. This library uses RxJava to to provide this functionality. If you want to consume events, you have to subscribe to the event stream. This library provides a consumer `CircuitBreakerEventConsumer` which can be used to store events in a circular buffer with a fixed capacity. You can use RxJava to filter certain events.
519522

0 commit comments

Comments
 (0)