net.spy.concurrent
Class SynchronizationObject<T>

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.concurrent.SynchronizationObject<T>

public class SynchronizationObject<T>
extends SpyObject

Object that will wait until a predicate determines that the value has been set to a particular value. Note that the predicate is not guaranteed to see every value change. It is quite likely that changes will be missed when the value is changing rapidly.


Nested Class Summary
static interface SynchronizationObject.Predicate<T>
          Synchronization object predicate for evaluation in waitUntilTrue.
 
Constructor Summary
SynchronizationObject(T o)
          Construct a synchronization object on the given object.
 
Method Summary
 T get()
          Get the current value of this lock.
 T set(T o)
          Set a new value and signal anyone listening for a value change.
 String toString()
          String this SynchronizationObject.
 void waitUntilEquals(T val, long timeout, TimeUnit timeunit)
          Wait for the contained object to become equal to the provided value.
 void waitUntilNotNull(long timeout, TimeUnit timeunit)
          Wait for the contained object to become non-null.
 void waitUntilTrue(SynchronizationObject.Predicate<T> p, long timeout, TimeUnit timeunit)
          Wait for the given predicate to become true in respect to the contained object.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SynchronizationObject

public SynchronizationObject(T o)
Construct a synchronization object on the given object.

Method Detail

get

public T get()
Get the current value of this lock.


set

public T set(T o)
Set a new value and signal anyone listening for a value change.


toString

public String toString()
String this SynchronizationObject.

Overrides:
toString in class Object

waitUntilTrue

public void waitUntilTrue(SynchronizationObject.Predicate<T> p,
                          long timeout,
                          TimeUnit timeunit)
                   throws InterruptedException,
                          TimeoutException
Wait for the given predicate to become true in respect to the contained object.

Parameters:
p - the predicate
timeout - how long to wait for this condition to become true
timeunit - the time unit for the timeout
Throws:
InterruptedException
TimeoutException - if a timeout occurs before the condition becomes true

waitUntilNotNull

public void waitUntilNotNull(long timeout,
                             TimeUnit timeunit)
                      throws InterruptedException,
                             TimeoutException
Wait for the contained object to become non-null.

Parameters:
timeout - how long to wait for this condition to become true
timeunit - the time unit for the timeout
Throws:
InterruptedException
TimeoutException - if a timeout occurs before the condition becomes true

waitUntilEquals

public void waitUntilEquals(T val,
                            long timeout,
                            TimeUnit timeunit)
                     throws InterruptedException,
                            TimeoutException
Wait for the contained object to become equal to the provided value. If the provided value is null, then this also waits for the contained object to become null.

Parameters:
val - the value to wait for
timeout - how long to wait for this condition to become true
timeunit - the time unit for the timeout
Throws:
InterruptedException
TimeoutException - if a timeout occurs before the condition becomes true


Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.