public abstract class RecursionGuard<Key>
extends java.lang.Object
RecursionManager
. It's obtained from RecursionManager.createGuard(String)
.Modifier and Type | Class and Description |
---|---|
static interface |
RecursionGuard.StackStamp |
Constructor and Description |
---|
RecursionGuard() |
Modifier and Type | Method and Description |
---|---|
abstract java.util.List<? extends Key> |
currentStack()
Note: if you make decisions based on the result of this method, you'd better couple it with
prohibitResultCaching(Key) ,
otherwise you might cache inconsistent values. |
abstract <T> T |
doPreventingRecursion(Key key,
boolean memoize,
Computable<T> computation)
Run the given computation, unless it's already running in this thread.
|
RecursionGuard.StackStamp |
markStack()
Deprecated.
Use
RecursionManager.markStack() instead |
abstract void |
prohibitResultCaching(Key since)
Makes
RecursionGuard.StackStamp.mayCacheNow() return false for all stamps created since a computation with
key since began. |
public abstract <T> T doPreventingRecursion(Key key, boolean memoize, Computable<T> computation)
key
- an id of the computation. It's stored internally to ensure that a recursive calls with the same key won't lead to endless recursion.memoize
- whether the result of the computation may be cached thread-locally until the last currently active doPreventingRecursion
call
completes. May be used to speed up things when recursion re-entrance happens: otherwise nothing would be cached at all and
in some cases exponential performance may be observed. Pass true
if your computation has no side effects
and doesn't depend on method parameters.computation
- a piece of code to compute.null
if we're entering a computation with this key on this thread recursively,@Deprecated public RecursionGuard.StackStamp markStack()
RecursionManager.markStack()
insteadpublic abstract java.util.List<? extends Key> currentStack()
prohibitResultCaching(Key)
,
otherwise you might cache inconsistent values.#doPreventingRecursion(Key, boolean, Computable)
.public abstract void prohibitResultCaching(Key since)
RecursionGuard.StackStamp.mayCacheNow()
return false for all stamps created since a computation with
key since
began.
Used to prevent caching of results that are non-reliable NOT due to recursion prevention: for example, too deep recursion
(currentStack()
may help in determining the recursion depth).
Also disables thread-local memoization (see the second parameter of doPreventingRecursion(Key, boolean, com.intellij.openapi.util.Computable<T>)
.since
- the id of a computation whose result is safe to cache whilst for more nested ones it's not.