Class ReentrantCircuit
java.lang.Object
net.jodah.concurrentunit.internal.ReentrantCircuit
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classSynchronization state of 0 = closed, 1 = open. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidawait()Waits for the circuit to be closed, aborting if interrupted.booleanWaits for thewaitDurationuntil the circuit has been closed, aborting if interrupted, returning true if the circuit is closed else false.voidclose()Closes the circuit, releasing any waiting threads.voidInterrupts waiting threads.booleanisClosed()Returns whether the circuit is closed.voidopen()Opens the circuit.toString()
-
Constructor Details
-
ReentrantCircuit
public ReentrantCircuit()
-
-
Method Details
-
await
Waits for the circuit to be closed, aborting if interrupted.- Throws:
InterruptedException- when wait is interrupted
-
await
Waits for thewaitDurationuntil the circuit has been closed, aborting if interrupted, returning true if the circuit is closed else false.- Parameters:
waitDuration- the maximum timetimeUnit- the unit of the time- Returns:
trueif acquired;falseif 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:
- whether the circuit is closed.
-
open
public void open()Opens the circuit. -
toString
-