private static int newPausedVersion(int oldVersion) { int v; Random versionSource = ThreadLocalRandom.current(); do { v = versionSource.nextInt(); } while (!isPaused(v) || v == oldVersion); return v; }
/** * Returns the current continuation of this call. * * <p>The call must be in the paused state; otherwise, an {@link IllegalStateException} is * thrown.</p> * * @return the current continuation of the call * * @throws IllegalStateException if this call is not in the paused state */ public OneShotContinuation getCurrentContinuation() { int version = currentVersion.get(); if (!isPaused(version)) { State s = versionToState(version); throw new IllegalStateException("Cannot get continuation of a " + s + " call"); } else { return new CallContinuation(version); } }