Package com.zfabrik.work
Class CycleProtector
- java.lang.Object
-
- com.zfabrik.work.CycleProtector
-
public class CycleProtector extends java.lang.ObjectA 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 classCycleProtector.CycleDetectedExceptionException thrown when a cycle was detectedstatic classCycleProtector.PendingCycleProtectionExceptionException 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> Tcall(java.lang.String node, java.util.concurrent.Callable<T> call)Call a control flow asCallablestatic voidclear()Forcibly clear the protector.static intdepth()Returns depth of current traversal.static voidenter(java.lang.String node)Enter a control flow that is not to be traversed again deeper.static voidleave(java.lang.String node)Leave a control flow again.static voidrun(java.lang.String node, java.lang.Runnable run)Run a control flowprotected static java.lang.StringstateToString()static <T> Tsupply(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.CycleDetectedExceptionEnter 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.CycleDetectedExceptionLeave 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.ExceptionCall 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.
-
-