/** * Configures number of requests per second to allow through this flow regulator * onto a configured back end service. * * @param i the requests per second threshold for this flow regulator */ public void setRequestPerSecondThreshold(int i) { this.requestPerSecondThreshold = i; calculateDeltaWaitTime(); }
/** 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()); } }
@ManagedAttribute @Override /** * {@inheritDoc} */ public void setRequestPerSecondThreshold(int i) { super.setRequestPerSecondThreshold(i); }
@ManagedAttribute @Override /** * {@inheritDoc} */ public int getRequestPerSecondThreshold() { return super.getRequestPerSecondThreshold(); } }
/** * 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()); } }
public ConstantFlowRegulator(int requestsPerSecond, ConstantFlowRegulatorExceptionMapper<? extends Exception> mapper) { requestPerSecondThreshold = requestsPerSecond; calculateDeltaWaitTime(); exceptionMapper = mapper; }
public ConstantFlowRegulator(int requestsPerSecond) { requestPerSecondThreshold = requestsPerSecond; calculateDeltaWaitTime(); }