/** Wrap the given service call with the {@link ConstantFlowRegulator} * protection logic. * @param r the {@link Runnable} to attempt * * @throws FlowRateExceededException if the total requests per second * through the flow regulator exceeds the configured value * @throws Exception if <code>c</code> throws one during * execution */ public void invoke(Runnable r) throws Exception { if (canProceed()) { r.run(); } else { throw mapException(new FlowRateExceededException()); } }
/** * Wrap the given service call with the {@link ConstantFlowRegulator} * protection logic. * @param c the {@link Callable} to attempt * * @return whatever c would return on success * * @throws FlowRateExceededException if the total requests per second * through the flow regulator exceeds the configured value * @throws Exception if <code>c</code> throws one during * execution */ public <T> T invoke(Callable<T> c) throws Exception { if (canProceed()) { return c.call(); } else { throw mapException(new FlowRateExceededException()); } }
/** Wrap the given service call with the {@link ConstantFlowRegulator} * protection logic. * @param r the {@link Runnable} to attempt * @param result what to return after <code>r</code> succeeds * * @return result * * @throws FlowRateExceededException if the total requests per second * through the flow regulator exceeds the configured value * @throws Exception if <code>c</code> throws one during * execution */ public <T> T invoke(Runnable r, T result) throws Exception { if (canProceed()) { r.run(); return result; } else { throw mapException(new FlowRateExceededException()); } }