Class ReentrantCircuit

java.lang.Object
net.jodah.concurrentunit.internal.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.
  • Nested Class Summary

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

    Fields
    Modifier and Type
    Field
    Description
    private final ReentrantCircuit.Sync
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Waits for the circuit to be closed, aborting if interrupted.
    boolean
    await(long waitDuration, 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
    Closes the circuit, releasing any waiting threads.
    void
    Interrupts waiting threads.
    boolean
    Returns whether the circuit is closed.
    void
    Opens the circuit.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • ReentrantCircuit

      public ReentrantCircuit()
  • Method Details

    • await

      public void await() throws InterruptedException
      Waits for the circuit to be closed, aborting if interrupted.
      Throws:
      InterruptedException
    • 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.
      Throws:
      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 String toString()
      Overrides:
      toString in class Object