/** * Call this method in a key verification loop in order to enforce a * suspension penalty for providing a wrong key of at least * {@link #MIN_KEY_RETRY_DELAY} milliseconds. * Interrupting the current thread does not show any effect on this method. * * @param last the last try time. * This should be zero upon the first call. * Subsequent calls should provide the return value of the last * call. * @return The new try time. */ public static long enforce(final long last) { final long start = System.currentTimeMillis(); final long elapsed = start - last; final long delay = MIN_KEY_RETRY_DELAY - elapsed; if (0 < delay) { Threads.pause(delay); return start + delay; // ~ System.currentTimeMillis() } else { return start; // ~ System.currentTimeMillis() } } }