org.multiverse.api
Interface Latch

All Known Implementing Classes:
CheapLatch, StandardLatch

public interface Latch

A structure that can be used as a waiting point (just like a Future or a CountDownLatch. As long as it is closed, the waiting thread block (unless it is interrupted or a timeout occurs). As soon as it opens, all waiting threads are woken up and continue. Threads that call the wait after the Latch is opened, can continue. Once the Latch has been opened, it can never be closed.

A Latch is thread-safe to use.

Author:
Peter Veentjer.

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.
 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 tryAwaitUninterruptible(long timeout, java.util.concurrent.TimeUnit unit)
           
 

Method Detail

open

void open()
Opens the latch. If the latch already is closed, the call is ignored. So this call is idempotent.


isOpen

boolean isOpen()
Return true if this Latch is closed, false otherwise.

Returns:
true if this Latch is closed, false otherwise.

await

void await()
           throws java.lang.InterruptedException
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).

Throws:
java.lang.InterruptedException - if the calling thread is interrupted while waiting.

awaitUninterruptible

void awaitUninterruptible()
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).

Throws:
java.lang.UnsupportedOperationException - if the implementation doesn't support this functionality.

tryAwait

boolean tryAwait(long timeout,
                 java.util.concurrent.TimeUnit unit)
                 throws java.lang.InterruptedException
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).

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.
java.lang.NullPointerException - if unit is null
java.lang.UnsupportedOperationException - if the implementation doesn't support this functionality.

tryAwaitUninterruptible

boolean tryAwaitUninterruptible(long timeout,
                                java.util.concurrent.TimeUnit unit)


Copyright © 2008-2010 Multiverse. All Rights Reserved.