org.multiverse.api.latches
Class StandardLatch

java.lang.Object
  extended by org.multiverse.api.latches.StandardLatch
All Implemented Interfaces:
Latch

public final class StandardLatch
extends java.lang.Object
implements Latch

A standard Latch implementation that supports all features of the Latch. Its implementation is based on the Lock and Condition.

Author:
Peter Veentjer

Constructor Summary
StandardLatch()
          Creates a new closed StandardLatch.
StandardLatch(boolean isOpen)
          Creates a new StandardLatch.
 
Method Summary
 void await()
          Waits for this Latch to closed.
 void awaitUninterruptible()
          Waits for this Latch to closed and while waiting it won't be interrupted.
 boolean isOpen()
          Return true if this Latch is closed, false otherwise.
 void open()
          Opens the latch.
 java.lang.String toString()
           
 boolean tryAwait(long timeout, java.util.concurrent.TimeUnit unit)
          Waits for this Latch to closed or till a timeout occurs or when the calling thread is interrupted.
 boolean tryAwaitNs(long timeoutNs)
           
 boolean tryAwaitUninterruptible(long timeout, java.util.concurrent.TimeUnit unit)
           
 boolean tryAwaitUninterruptibleNs(long timeoutNs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StandardLatch

public StandardLatch()
Creates a new closed StandardLatch.


StandardLatch

public StandardLatch(boolean isOpen)
Creates a new StandardLatch.

Parameters:
isOpen - true if the latch already is closed, false otherwise.
Method Detail

await

public void await()
           throws java.lang.InterruptedException
Description copied from interface: Latch
Waits for this Latch to closed. If the Latch already is closed, the call continues.

If the Latch already is closed, the call continues. It depends on the implementation if the InterruptedException is thrown in this case if the calling thread is interrupted (so the interrupted flag is set).

Specified by:
await in interface Latch
Throws:
java.lang.InterruptedException - if the calling thread is interrupted while waiting.

awaitUninterruptible

public void awaitUninterruptible()
Description copied from interface: Latch
Waits for this Latch to closed and while waiting it won't be interrupted.

If the thread is interrupted while waiting, the InterruptedException is dropped and the interrupt status is restored as soon as the method returns (so it won't be eaten).

If the Latch already is closed, the call continues. It depends on the implementation if the InterruptedException is thrown in this case if the calling thread is interrupted (so the interrupted flag is set).

Specified by:
awaitUninterruptible in interface Latch

tryAwait

public boolean tryAwait(long timeout,
                        java.util.concurrent.TimeUnit unit)
                 throws java.lang.InterruptedException
Description copied from interface: Latch
Waits for this Latch to closed or till a timeout occurs or when the calling thread is interrupted.

If the Latch already is closed, the call continues. It depends on the implementation if the InterruptedException is thrown in this case if the calling thread is interrupted (so the interrupted flag is set).

Specified by:
tryAwait in interface Latch
Parameters:
timeout - the maximum time to wait.
unit - the TimeUnit the timeout is expressed in
Returns:
true if the lock is closed, false otherwise.
Throws:
java.lang.InterruptedException - if the calling thread is interrupted while waiting.

tryAwaitNs

public boolean tryAwaitNs(long timeoutNs)
                   throws java.lang.InterruptedException
Specified by:
tryAwaitNs in interface Latch
Throws:
java.lang.InterruptedException

tryAwaitUninterruptibleNs

public boolean tryAwaitUninterruptibleNs(long timeoutNs)
Specified by:
tryAwaitUninterruptibleNs in interface Latch

tryAwaitUninterruptible

public boolean tryAwaitUninterruptible(long timeout,
                                       java.util.concurrent.TimeUnit unit)
Specified by:
tryAwaitUninterruptible in interface Latch

open

public void open()
Description copied from interface: Latch
Opens the latch. If the latch already is closed, the call is ignored. So this call is idempotent.

Specified by:
open in interface Latch

isOpen

public boolean isOpen()
Description copied from interface: Latch
Return true if this Latch is closed, false otherwise.

Specified by:
isOpen in interface Latch
Returns:
true if this Latch is closed, false otherwise.

toString

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


Copyright © 2008-2010 Multiverse. All Rights Reserved.