Class ReentrantCircuit


  • public class ReentrantCircuit
    extends java.lang.Object
    A circuit that accepts re-entrant open() and close() calls, allows waiting threads to be interrupted, and ensures fairness when releasing waiting threads.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  ReentrantCircuit.Sync
      Synchronization state of 0 = closed, 1 = open.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void await()
      Waits for the circuit to be closed, aborting if interrupted.
      boolean await​(long waitDuration, java.util.concurrent.TimeUnit timeUnit)
      Waits for the waitDuration until the circuit has been closed, aborting if interrupted, returning true if the circuit is closed else false.
      void close()
      Closes the circuit, releasing any waiting threads.
      void interruptWaiters()
      Interrupts waiting threads.
      boolean isClosed()
      Returns whether the circuit is closed.
      void open()
      Opens the circuit.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • ReentrantCircuit

        public ReentrantCircuit()
    • Method Detail

      • await

        public void await()
                   throws java.lang.InterruptedException
        Waits for the circuit to be closed, aborting if interrupted.
        Throws:
        java.lang.InterruptedException
      • await

        public boolean await​(long waitDuration,
                             java.util.concurrent.TimeUnit timeUnit)
                      throws java.lang.InterruptedException
        Waits for the waitDuration until the circuit has been closed, aborting if interrupted, returning true if the circuit is closed else false.
        Throws:
        java.lang.InterruptedException
      • 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.
      • open

        public void open()
        Opens the circuit.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object