Package com.zfabrik.work
Class CycleProtector
- java.lang.Object
-
- com.zfabrik.work.CycleProtector
-
public class CycleProtector extends java.lang.Object
A generic cycle detection utility that can be used in methods that may run into recursive control flows.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CycleProtector.CycleDetectedException
Exception thrown when a cycle was detectedstatic class
CycleProtector.PendingCycleProtectionException
Exception thrown when a protection stack was not cleanly resolved at the end of a work unit.
-
Constructor Summary
Constructors Constructor Description CycleProtector()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
call(java.lang.String node, java.util.concurrent.Callable<T> call)
Call a control flow asCallable
static void
clear()
Forcibly clear the protector.static int
depth()
Returns depth of current traversal.static void
enter(java.lang.String node)
Enter a control flow that is not to be traversed again deeper.static void
leave(java.lang.String node)
Leave a control flow again.static void
run(java.lang.String node, java.lang.Runnable run)
Run a control flowprotected static java.lang.String
stateToString()
static <T> T
supply(java.lang.String node, java.util.function.Supplier<T> supplier)
Call a control flow as Supplier
-
-
-
Method Detail
-
enter
public static void enter(java.lang.String node) throws CycleProtector.CycleDetectedException
Enter a control flow that is not to be traversed again deeper. This may be some dependency inspection, some graph traversal, anything where a cyclic repetition is to be avoided. The node string passed identifies the control flow.
-
clear
public static void clear()
Forcibly clear the protector. Use with caution, if at all
-
leave
public static void leave(java.lang.String node) throws CycleProtector.CycleDetectedException
Leave a control flow again. This must be the last entered.
-
run
public static void run(java.lang.String node, java.lang.Runnable run)
Run a control flow
-
call
public static <T> T call(java.lang.String node, java.util.concurrent.Callable<T> call) throws java.lang.Exception
Call a control flow asCallable
- Throws:
java.lang.Exception
-
supply
public static <T> T supply(java.lang.String node, java.util.function.Supplier<T> supplier)
Call a control flow as Supplier
-
stateToString
protected static java.lang.String stateToString()
-
depth
public static int depth()
Returns depth of current traversal.
-
-