Package com.qfs.util

Interface ILatch

  • All Known Implementing Classes:
    Latch

    public interface ILatch
    Simple latch with dynamic increment/decrement.

    The latch internal pending count is initialized to 'zero'. The activity associated with the latch can increment the count to register a sub task for instance, and decrement the count to signify the sub task is finished. A Latch to be registered as a quartet type to allow tracing.

    Author:
    ActiveViam
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void awaitCompletion()
      Wait until the latch is completed: when it is shutdown and the pending count reached zero.
      int decrement()
      Decrement the pending count (unregister a unit of activity).
      int getPending()
      Returns the pending count.
      int increment()
      Increment the pending count (register a unit of activity).
      boolean isCompleted()
      Returns true if the latch is completed (shutdown and pending count equal to zero).
      boolean isShutdown()
      Returns true if the latch is shutdown.
      void setCompletion​(ICompletion completion)
      Set the completion method that should run when the latch is complete.
      The completion must be set before the latch is shutdown.
      void shutdown()
      Shut down the latch: the latch will not accept any additional increment and can only await its completion.
    • Method Detail

      • getPending

        int getPending()
        Returns the pending count.
        Returns:
        the pending count
      • isShutdown

        boolean isShutdown()
        Returns true if the latch is shutdown.
        Returns:
        Whether the latch is shutdown
      • isCompleted

        boolean isCompleted()
        Returns true if the latch is completed (shutdown and pending count equal to zero).
        Returns:
        Whether the latch is completed
      • increment

        int increment()
        Increment the pending count (register a unit of activity).
        Returns:
        the incremented value
      • decrement

        int decrement()
               throws IllegalStateException
        Decrement the pending count (unregister a unit of activity). If the latch is shut down and this decrement brings the pending count to zero, then the optional completion is executed. If an exception is thrown by the completion, it will propagate through the decrement method.
        Returns:
        the decremented value
        Throws:
        IllegalStateException - if the actual pending count before decrementing is 0
      • awaitCompletion

        void awaitCompletion()
        Wait until the latch is completed: when it is shutdown and the pending count reached zero.
      • setCompletion

        void setCompletion​(ICompletion completion)
        Set the completion method that should run when the latch is complete.
        The completion must be set before the latch is shutdown.
        Parameters:
        completion - the completion to set
      • shutdown

        void shutdown()
               throws IllegalStateException
        Shut down the latch: the latch will not accept any additional increment and can only await its completion. Following a shutdown the latch will be considered complete the pending count reaches zero.

        When the latch will be completed (later or right now) the (optional) completion continuation will be executed.

        If the pending count is already zero when shutdown is called, then the completion is executed immediately, and if the completion throws an exception it is thrown through the shutdown method.

        Throws:
        IllegalStateException - if trying to shutdown a terminated latch