org.glite.ce.commonj.utils
Class BooleanLock

java.lang.Object
  extended byorg.glite.ce.commonj.utils.BooleanLock

public class BooleanLock
extends java.lang.Object

This class is a simple semaphore used to synchronize access to shared resources.

Author:
Luigi Zangrando (zangrando@pd.infn.it)

Constructor Summary
BooleanLock()
          Creates a new BooleanLock object with initial value false.
BooleanLock(boolean initialValue)
          Creates a new BooleanLock object with specified initial value
 
Method Summary
 boolean isFalse()
          Check if BooleanLock value is false
 boolean isTrue()
          Check if BooleanLock value is true
 void setValue(boolean newValue)
          Set a new value to BooleanLock.
 boolean waitToSetFalse(long msTimeout)
          Set BooleanLock value to false if it is set to true before the timeout.
 boolean waitToSetTrue(long msTimeout)
          Set BooleanLock value to true if it is set to false before the timeout.
 boolean waitUntilFalse(long msTimeout)
          Check if the value of the BooleanLock is false or wait for a maximum amount of time specified by msTimeout that the value is set to false.
 boolean waitUntilStateIs(boolean state, long msTimeout)
          Check if the value of the BooleanLock equals the specified state or wait for a maximum amount of time specified by msTimeout that the value is set to the specified state.
 boolean waitUntilTrue(long msTimeout)
          Check if the value of the BooleanLock is true or wait for a maximum amount of time specified by msTimeout that the value is set to true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BooleanLock

public BooleanLock()
Creates a new BooleanLock object with initial value false.


BooleanLock

public BooleanLock(boolean initialValue)
Creates a new BooleanLock object with specified initial value

Method Detail

setValue

public void setValue(boolean newValue)
Set a new value to BooleanLock. When changed all objects synchronized will be notified.

Parameters:
newValue - The boolean new value.

waitToSetTrue

public boolean waitToSetTrue(long msTimeout)
                      throws java.lang.InterruptedException
Set BooleanLock value to true if it is set to false before the timeout.

Parameters:
msTimeout - The timeout expressed in milliseconds. If 0L wait indefinitely.
Returns:
A boolean representing the final outcome. This will be true if the BooleanLock value has been successfully set to true before the timeout, false otherwise.
Throws:
java.lang.InterruptedException

waitToSetFalse

public boolean waitToSetFalse(long msTimeout)
                       throws java.lang.InterruptedException
Set BooleanLock value to false if it is set to true before the timeout.

Parameters:
msTimeout - The timeout expressed in milliseconds. If 0L wait indefinitely.
Returns:
A boolean representing the final outcome. This will be true if the BooleanLock value has been successfully set to false before the timeout, false otherwise.
Throws:
java.lang.InterruptedException

isTrue

public boolean isTrue()
Check if BooleanLock value is true

Returns:
The boolean the response

isFalse

public boolean isFalse()
Check if BooleanLock value is false

Returns:
The boolean representing the response

waitUntilTrue

public boolean waitUntilTrue(long msTimeout)
                      throws java.lang.InterruptedException
Check if the value of the BooleanLock is true or wait for a maximum amount of time specified by msTimeout that the value is set to true.

Parameters:
msTimeout - The maximum amount of time to wait before return a response. This is expressed in milliseconds. If 0L wait indefinitely.
Returns:
A boolean representing the response of the operation.
Throws:
java.lang.InterruptedException

waitUntilFalse

public boolean waitUntilFalse(long msTimeout)
                       throws java.lang.InterruptedException
Check if the value of the BooleanLock is false or wait for a maximum amount of time specified by msTimeout that the value is set to false.

Parameters:
msTimeout - The maximum amount of time to wait before return a response. This is expressed in milliseconds. If 0L wait indefinitely.
Returns:
A boolean representing the response of the operation.
Throws:
java.lang.InterruptedException

waitUntilStateIs

public boolean waitUntilStateIs(boolean state,
                                long msTimeout)
                         throws java.lang.InterruptedException
Check if the value of the BooleanLock equals the specified state or wait for a maximum amount of time specified by msTimeout that the value is set to the specified state.

Parameters:
msTimeout - The maximum amount of time to wait before return a response. This is expressed in milliseconds. If 0L wait indefinitely.
Returns:
A boolean representing the response of the operation.
Throws:
java.lang.InterruptedException