Guest User

Untitled

a guest
Nov 15th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. static <T> Supplier<T> decorateSupplier(CircuitBreaker circuitBreaker, Supplier<T> supplier){
  2. return () -> {
  3. CircuitBreakerUtils.isCallPermitted(circuitBreaker);
  4. long start = System.nanoTime();
  5. try {
  6. T returnValue = supplier.get();
  7. long durationInNanos = System.nanoTime() - start;
  8. circuitBreaker.onSuccess(durationInNanos);
  9. return returnValue;
  10. } catch (Throwable throwable) {
  11. long durationInNanos = System.nanoTime() - start;
  12. circuitBreaker.onError(durationInNanos, throwable);
  13. throw throwable;
  14. }
  15. };
  16. }
Add Comment
Please, Sign In to add comment