SHARE
TWEET

Untitled

a guest Nov 15th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top