Class 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.
    • 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 as Callable
      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 flow
      protected 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CycleProtector

        public CycleProtector()
    • 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.
        Throws:
        CycleProtector.CycleDetectedException
      • clear

        public static void clear()
        Forcibly clear the protector. Use with caution, if at all
      • 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 as Callable
        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.