public class NStateLatch
extends java.lang.Object
An N state synchronization latch useful for implementing hydration/dehydration. The
latch functions as follows. At any time, the latch is in one of N states and has a
count. Clients can "latch" and "release" the latch, which increments/decrements the
count; however, when latching, a state must be specified. If the state does not match
the current state, the latch blocks until the count is zero. Essentially, the latch
can change state only when the count is zero. Every time the latch changes state an
optional Runnable
corresponding to the new state is executed.