/** * Returns the total number of requests seen by this {@link * PerformanceMonitor}. * @return long */ public long getRequestCount() { return requestCounter.sample()[0]; }
/** Wrap the given service call with the {@link RequestCounter} * to count the number of calls made. * @param r the {@link Runnable} to attempt * * @throws Exception if <code>c</code> throws one during * execution */ public void invoke(Runnable r) throws Exception { try { r.run(); succeed(); } catch (Exception e) { fail(); throw e; } }
public <T> T invoke(final Callable<T> c) throws Exception { final LatencyTracker latencyTracker = new LatencyTracker(); try { T result = requestCounter.invoke(new Callable<T>() { public T call() throws Exception { return latencyTracker.invoke(c); } }); recordSuccess(latencyTracker); return result; } catch (Exception e) { recordFailure(latencyTracker); if (WRAP_MSG.equals(e.getMessage())) { throw (Exception)e.getCause(); } else { throw e; } } }
/** * Default constructor. Any {@link Throwable} will cause the breaker to trip. */ @SuppressWarnings("unchecked") public PercentErrPerTimeFailureInterpreter() { setIgnore(defaultIgnore); requestCounter = new RequestCounter(); }
public void invoke(final Runnable r) throws Exception { final LatencyTracker latencyTracker = new LatencyTracker(); try { requestCounter.invoke(new Runnable() { public void run() { try { latencyTracker.invoke(r); } catch (Exception e) { throw new RuntimeException(WRAP_MSG, e); } } }); recordSuccess(latencyTracker); } catch (RuntimeException re) { recordFailure(latencyTracker); if (WRAP_MSG.equals(re.getMessage())) { throw (Exception)re.getCause(); } else { throw re; } } }
/** * Returns the number of failed requests seen by this {@link * PerformanceMonitor}. * @return long */ public long getFailureCount() { return requestCounter.sample()[2]; }
/** Wrap the given service call with the {@link RequestCounter} * to count the number of calls made. * @param c the {@link Callable} to attempt * * @return whatever c would return on success * * @throws Exception if <code>c</code> throws one during * execution */ public <T> T invoke(Callable<T> c) throws Exception { try { T result = c.call(); succeed(); return result; } catch (Exception e) { fail(); throw e; } }
/** * Returns the number of successful requests seen by this {@link * PerformanceMonitor}. * @return long */ public long getSuccessCount() { return requestCounter.sample()[1]; }
/** Wrap the given service call with the {@link RequestCounter} * to count the number of calls made. * @param r the {@link Runnable} to attempt * @param result what to return after <code>r</code> succeeds * * @return result * * @throws Exception if <code>c</code> throws one during * execution */ public <T> T invoke(Runnable r, T result) throws Exception { try { r.run(); succeed(); return result; } catch (Exception e) { fail(); throw e; } }
/** * Returns the average request rate in requests per second of * all requests, as measured since this object was initialized. * @return double */ public double getTotalRequestsPerSecondLifetime() { long deltaT = System.currentTimeMillis() - startupMillis; return (((double)requestCounter.sample()[0])/(double)deltaT) * 1000; }
/** * Returns the average request rate in requests per second of * successful requests, as measured since this object was * initialized. * @return double */ public double getSuccessRequestsPerSecondLifetime() { long deltaT = System.currentTimeMillis() - startupMillis; return (((double)requestCounter.sample()[1])/(double)deltaT) * 1000; }
/** * Returns the average request rate in requests per second of * failed requests, as measured since this object was * initialized. * @return double */ public double getFailureRequestsPerSecondLifetime() { long deltaT = System.currentTimeMillis() - startupMillis; return (((double)requestCounter.sample()[2])/(double)deltaT) * 1000; }
@ManagedOperation @Override /** * {@inheritDoc} */ public synchronized long[] sample() { return super.sample(); }
public boolean shouldTrip(Throwable cause) { if (isExceptionIgnorable(cause)) return false; // if Exception is of specified type, and window conditions exist, // keep circuit open unless exception threshold has passed if (hasWindowConditions()) { Long currentRequestCount = -1L; long numberOfErrorsAfter; synchronized (modificationLock) { errorTimes.add(System.currentTimeMillis()); requestCounts.add(requestCounter.sample()[0]); // calculates time for which we remove any errors before final long removeTimeBeforeMillis = System.currentTimeMillis() - windowMillis; final int numberOfErrorsBefore = this.errorTimes.size(); removeErrorsPriorToCutoffTime(numberOfErrorsBefore, removeTimeBeforeMillis); numberOfErrorsAfter = this.errorTimes.size(); currentRequestCount = this.requestCounts.get(requestCounts.size() - 1); } long windowRequests = (currentRequestCount - previousRequestHighWaterMark); // Trip if the number of errors over the total of requests over the same period // is over the percentage limit. return windowRequests >= requestThreshold && (((double) numberOfErrorsAfter / (double) windowRequests) * 100d >= percent); } return true; }
long[] currCounts = counter.sample(); long now = System.currentTimeMillis();