ProgramixGenericLib v5.0.1

com.programix.thread
Class BooleanState

java.lang.Object
  extended by com.programix.thread.BooleanState
All Implemented Interfaces:
ThreadSafe

public class BooleanState
extends Object
implements ThreadSafe

This class serves as a thread-safe tracker of a boolean state.

Author:
Paul Hyde

Constructor Summary
BooleanState()
          Creates an instance that is initially false and synchronizes on itself.
BooleanState(boolean initialState)
          Creates an instance that is initially set to the state of initialState and synchronizes on itself.
BooleanState(boolean initialState, Object lockObject)
          Creates an instance that is initially set to the state of initialState and synchronizes on the specified lockObject.
BooleanState(boolean initialState, Waiter waiter)
          Creates an instance that is initially set to the state of initialState and synchronizes on the lock used by the specified waiter.
BooleanState(Object lockObject)
          Creates an instance that is initially false and synchronizes on the specified lockObject.
 
Method Summary
 Object getLockObject()
           
 Waiter getWaiter()
           
 boolean ifFalseSetTrue()
          If the current state is false, then the state is changed to true.
 boolean ifTrueSetFalse()
          If the current state is true, then the state is changed to false.
 boolean isFalse()
          Returns true if the internal state is currently false.
 boolean isShutdown()
           
 boolean isTrue()
          Returns true if the internal state is currently true.
 void setState(boolean newState)
          Sets the internal state to the specified newState.
 void shutdown()
          Called to shutdown all access to this counter and to dislodge any threads waiting on conditions.
 void toggleState()
          Sets the internal state to the opposite of whatever is was before the call.
 void waitUntilFalse()
          Waits until the state is false.
 void waitUntilFalse(long msTimeout)
          Waits until the state is false up to the specified maximum amount of time.
 void waitUntilTrue()
          Waits until the state is true.
 void waitUntilTrue(long msTimeout)
          Waits until the state is true up to the specified maximum amount of time.
 void waitWhileFalse()
          Waits while the state is false.
 void waitWhileFalse(long msTimeout)
          Waits while the state is false up to the specified maximum amount of time.
 void waitWhileTrue()
          Waits while the state is true.
 void waitWhileTrue(long msTimeout)
          Waits while the state is true up to the specified maximum amount of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BooleanState

public BooleanState(boolean initialState,
                    Waiter waiter)
Creates an instance that is initially set to the state of initialState and synchronizes on the lock used by the specified waiter.


BooleanState

public BooleanState(boolean initialState,
                    Object lockObject)
Creates an instance that is initially set to the state of initialState and synchronizes on the specified lockObject.


BooleanState

public BooleanState(boolean initialState)
Creates an instance that is initially set to the state of initialState and synchronizes on itself.


BooleanState

public BooleanState(Object lockObject)
Creates an instance that is initially false and synchronizes on the specified lockObject.


BooleanState

public BooleanState()
Creates an instance that is initially false and synchronizes on itself.

Method Detail

isTrue

public boolean isTrue()
               throws ShutdownException
Returns true if the internal state is currently true.

Throws:
ShutdownException

isFalse

public boolean isFalse()
                throws ShutdownException
Returns true if the internal state is currently false.

Throws:
ShutdownException

setState

public void setState(boolean newState)
              throws ShutdownException
Sets the internal state to the specified newState.

Throws:
ShutdownException

toggleState

public void toggleState()
                 throws ShutdownException
Sets the internal state to the opposite of whatever is was before the call.

Throws:
ShutdownException

ifTrueSetFalse

public boolean ifTrueSetFalse()
                       throws ShutdownException
If the current state is true, then the state is changed to false. If not, then the state is left unchanged. The return value indicates whether or not a change occurred.

Returns:
true if the state was changed, false is it was not changed.
Throws:
ShutdownException

ifFalseSetTrue

public boolean ifFalseSetTrue()
                       throws ShutdownException
If the current state is false, then the state is changed to true. If not, then the state is left unchanged. The return value indicates whether or not a change occurred.

Returns:
true if the state was changed, false is it was not changed.
Throws:
ShutdownException

waitWhileTrue

public void waitWhileTrue(long msTimeout)
                   throws TimedOutException,
                          ShutdownException,
                          InterruptException
Waits while the state is true up to the specified maximum amount of time.

Throws:
TimedOutException
ShutdownException
InterruptException

waitWhileTrue

public void waitWhileTrue()
                   throws ShutdownException,
                          InterruptException
Waits while the state is true.

Throws:
ShutdownException
InterruptException

waitUntilTrue

public void waitUntilTrue(long msTimeout)
                   throws TimedOutException,
                          ShutdownException,
                          InterruptException
Waits until the state is true up to the specified maximum amount of time.

Throws:
TimedOutException
ShutdownException
InterruptException

waitUntilTrue

public void waitUntilTrue()
                   throws ShutdownException,
                          InterruptException
Waits until the state is true.

Throws:
ShutdownException
InterruptException

waitWhileFalse

public void waitWhileFalse(long msTimeout)
                    throws TimedOutException,
                           ShutdownException,
                           InterruptException
Waits while the state is false up to the specified maximum amount of time.

Throws:
TimedOutException
ShutdownException
InterruptException

waitWhileFalse

public void waitWhileFalse()
                    throws ShutdownException,
                           InterruptException
Waits while the state is false.

Throws:
ShutdownException
InterruptException

waitUntilFalse

public void waitUntilFalse(long msTimeout)
                    throws TimedOutException,
                           ShutdownException,
                           InterruptException
Waits until the state is false up to the specified maximum amount of time.

Throws:
TimedOutException
ShutdownException
InterruptException

waitUntilFalse

public void waitUntilFalse()
                    throws ShutdownException,
                           InterruptException
Waits until the state is false.

Throws:
ShutdownException
InterruptException

getWaiter

public Waiter getWaiter()

shutdown

public void shutdown()
Called to shutdown all access to this counter and to dislodge any threads waiting on conditions.


isShutdown

public boolean isShutdown()

getLockObject

public Object getLockObject()

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.