Class ReentrantCircuit


  • public class ReentrantCircuit
    extends Object
    A circuit that accepts re-entrant open() and close() calls, allows waiting threads to be interrupted, and ensures fairness when releasing waiting threads.
    Author:
    Jonathan Halterman
    • Constructor Detail

      • ReentrantCircuit

        public ReentrantCircuit()
    • Method Detail

      • await

        public boolean await​(long waitDuration,
                             TimeUnit timeUnit)
                      throws InterruptedException
        Waits for the waitDuration until the circuit has been closed, aborting if interrupted, returning true if the circuit is closed else false.
        Parameters:
        waitDuration - the maximum time
        timeUnit - the unit of the time
        Returns:
        true if acquired; false if timed out
        Throws:
        InterruptedException - when wait is interrupted
      • close

        public void close()
        Closes the circuit, releasing any waiting threads.
      • interruptWaiters

        public void interruptWaiters()
        Interrupts waiting threads.
      • isClosed

        public boolean isClosed()
        Returns whether the circuit is closed.
        Returns:
        boolean; whether the circuit is closed.
      • open

        public void open()
        Opens the circuit.