/** * Creates a new call based rate limit. * <p> * Calling {@link #check()} on will only return <tt>true</tt> every n-th call and <tt>false</tt> otherwise. * * @param n the number of calls to skip (returning <tt>false</tt>) by {@link #check()} before <tt>true</tt> * is returned * @return a new call based rate limit */ public static RateLimit everyNthCall(long n) { return new RateLimit(n, 0, Mode.CALL_BASED); }
/** * Creates a new time based rate limit which permits up to N calls per interval. * <p> * Calling {@link #check()} on will only return <tt>true</tt> N times in every given interval, * <tt>false</tt> otherwise. * * @param interval the amount of time after a call to {@link #check()} returns <tt>true</tt> again * @param unit the unit for amount * @param permitsPerInterval the number of times to return <tt>true</tt> per interval * @return a new time based rate limit */ public static RateLimit nTimesPerInterval(long interval, TimeUnit unit, int permitsPerInterval) { return new RateLimit(TimeUnit.MILLISECONDS.convert(interval, unit), permitsPerInterval, Mode.TIME_BASED); }