com.ibm.tspaces
Class Semaphore
java.lang.Object
|
+--com.ibm.tspaces.Semaphore
- public final class Semaphore
- extends java.lang.Object
- implements java.io.Serializable
Class semaphore is a simple counting semaphore.
semaphore.decr() will wait
semaphore.incr() will notify
Be careful not to use it
when already in a synchronized method. Although semaphore uses wait, I
don't think that recusively releases all locks on classes that are on
the stack
This version of the semaphore is a bit unique in that the decr() method
passes a superTuple that will then be returned by the incr() method.
It has also been enhanced (by jthomas Aug99) to allow it to be interrupted
or timedout, in which case it will return null from incr().
- Author:
- Pete Wyckoff
- See Also:
- Serialized Form
|
Field Summary |
static java.lang.String |
TIMEOUT
Indicator returned when semophore is interrupted or timed out |
|
Method Summary |
java.lang.Object |
decr(long waitTime_)
decrement the semaphore, make sure your code is able to call this method ---
wherever you call decr from had better not be holding locks that are needed
for the other part to call incr
We support the caller specifing a max waittime after which it will
return null. |
void |
incr(SuperTuple waitingFor_)
increment the semaphore, make sure your code is able to call this method ---
wherever you call decr from had better not be holding locks that are needed
for the other part to call incr |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
TIMEOUT
public static final java.lang.String TIMEOUT
- Indicator returned when semophore is interrupted or timed out
Semaphore
public Semaphore()
incr
public void incr(SuperTuple waitingFor_)
- increment the semaphore, make sure your code is able to call this method ---
wherever you call decr from had better not be holding locks that are needed
for the other part to call incr
- Parameters:
waitingFor_ - A SuperTuple that contains the response from the
server that we are waiting for.
decr
public java.lang.Object decr(long waitTime_)
- decrement the semaphore, make sure your code is able to call this method ---
wherever you call decr from had better not be holding locks that are needed
for the other part to call incr
We support the caller specifing a max waittime after which it will
return null.
- Parameters:
waittime_ - A max timeinterval(in ms) that we should wait.- Returns:
- A SuperTuple that was passed in the incr() method.
If this Thread is interrupted, it will return null.