org.infinispan.util.concurrent
Class WatchableValue

java.lang.Object
  extended by java.util.concurrent.locks.AbstractQueuedSynchronizer
      extended by org.infinispan.util.concurrent.WatchableValue
All Implemented Interfaces:
Serializable

public class WatchableValue
extends AbstractQueuedSynchronizer

Allows threads to watch a variable and be notified when the state of the variable reaches a specific value.

E.g.,

ValueNotifier v = new ValueNotifier(0);

Thread1:

v.setValue(10);

Thread2:

v.awaitValue(5); // will block until another thread sets the value to 5

Since:
4.0
Author:
Manik Surtani
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer
AbstractQueuedSynchronizer.ConditionObject
 
Constructor Summary
WatchableValue(int initValue)
           
 
Method Summary
 void awaitValue(int value)
           
 boolean awaitValue(int value, long time, TimeUnit unit)
           
 int getValue()
           
 void setValue(int value)
           
 int tryAcquireShared(int value)
           
 boolean tryReleaseShared(int state)
           
 
Methods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer
acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedThreads, hasWaiters, isHeldExclusively, isQueued, owns, release, releaseShared, setState, toString, tryAcquire, tryAcquireNanos, tryAcquireSharedNanos, tryRelease
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WatchableValue

public WatchableValue(int initValue)
Method Detail

tryAcquireShared

public final int tryAcquireShared(int value)
Overrides:
tryAcquireShared in class AbstractQueuedSynchronizer

tryReleaseShared

public final boolean tryReleaseShared(int state)
Overrides:
tryReleaseShared in class AbstractQueuedSynchronizer

setValue

public final void setValue(int value)

awaitValue

public final void awaitValue(int value)
                      throws InterruptedException
Throws:
InterruptedException

awaitValue

public final boolean awaitValue(int value,
                                long time,
                                TimeUnit unit)
                         throws InterruptedException
Throws:
InterruptedException

getValue

public int getValue()

Google Analytics

Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.