com.atlassian.util.concurrent
Class PhasedLatch

java.lang.Object
  extended by com.atlassian.util.concurrent.PhasedLatch
All Implemented Interfaces:
Awaitable, ReusableLatch

@ThreadSafe
public class PhasedLatch
extends java.lang.Object
implements ReusableLatch

A PhasedLatch is a shared latch that resets after it is released and can be reused. Potentially waiting threads can test the current phase before performing an action. The action is then guarded by that phase and can await that phase to be advanced via a call to release the current phase.


Constructor Summary
PhasedLatch()
           
 
Method Summary
 void await()
          Await the current phase.
 boolean await(long time, java.util.concurrent.TimeUnit unit)
          Await the current phase for the specified period.
 void awaitPhase(int phase)
          Await the specified phase.
 boolean awaitPhase(int phase, long period, java.util.concurrent.TimeUnit unit)
          Await the specified phase for the specified period.
 int getPhase()
           
 void release()
          Release the current phase.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhasedLatch

public PhasedLatch()
Method Detail

release

public void release()
Release the current phase.

Specified by:
release in interface ReusableLatch

await

public void await()
           throws java.lang.InterruptedException
Await the current phase.

Specified by:
await in interface Awaitable
Throws:
java.lang.InterruptedException - if interrupted

await

public boolean await(long time,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException
Await the current phase for the specified period.

Specified by:
await in interface Awaitable
Parameters:
time - the period of time
unit - of time to measure the period in
Returns:
true if the phase was passed, false otherwise
Throws:
java.lang.InterruptedException - if interrupted

awaitPhase

public void awaitPhase(int phase)
                throws java.lang.InterruptedException
Await the specified phase.

Parameters:
phase - the phase to wait for
Throws:
java.lang.InterruptedException - if interrupted

awaitPhase

public boolean awaitPhase(int phase,
                          long period,
                          java.util.concurrent.TimeUnit unit)
                   throws java.lang.InterruptedException
Await the specified phase for the specified period.

Parameters:
phase - the phase to wait for
period - the period of time to wait for, as specified by:
unit - of time to measure the period in
Returns:
true if the phase was passed, false otherwise
Throws:
java.lang.InterruptedException - if interrupted

getPhase

public int getPhase()


Copyright © 2011 Atlassian. All Rights Reserved.