org.jgroups.util

Class CondVar


public class CondVar
extends java.lang.Object

Class that checks on a condition and - if condition doesn't match the expected result - waits until the result matches the expected result, or a timeout occurs. First version used WaitableBoolean from util.concurrent, but that class would not allow for timeouts.
Version:
$Id: CondVar.java,v 1.3 2004/12/31 14:10:40 belaban Exp $
Author:
Bela Ban

Constructor Summary

CondVar(String name, Object cond)
CondVar(String name, Object cond, Object lock)

Method Summary

Object
get()
Object
getLock()
void
set(Object result)
Sets the result
String
toString()
void
waitUntil(Object result)
void
waitUntil(Object result, long timeout)
Waits until the condition matches the expected result.
void
waitUntilWithTimeout(Object result, long timeout)
Waits until the condition matches the expected result.

Constructor Details

CondVar

public CondVar(String name,
               Object cond)

CondVar

public CondVar(String name,
               Object cond,
               Object lock)

Method Details

get

public Object get()

getLock

public Object getLock()

set

public void set(Object result)
Sets the result

toString

public String toString()

waitUntil

public void waitUntil(Object result)

waitUntil

public void waitUntil(Object result,
                      long timeout)
Waits until the condition matches the expected result. Returns immediately if they match, otherwise waits for timeout milliseconds or until the results match. This method doesn't throw a TimeoutException
Parameters:
result - The result, needs to match the condition (using equals()).
timeout - Number of milliseconds to wait. A value of <= 0 means to wait forever

waitUntilWithTimeout

public void waitUntilWithTimeout(Object result,
                                 long timeout)
            throws TimeoutException
Waits until the condition matches the expected result. Returns immediately if they match, otherwise waits for timeout milliseconds or until the results match.
Parameters:
result - The result, needs to match the condition (using equals()).
timeout - Number of milliseconds to wait. A value of <= 0 means to wait forever
Throws:
TimeoutException - Thrown if the result still doesn't match the condition after timeout milliseconds have elapsed

Copyright B) 1998-2005 Bela Ban. All Rights Reserved.