edu.ksu.cis.projects.bogor.module.value
Class DefaultLockValue

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.module.value.DefaultLockValue
All Implemented Interfaces:
ILockValue, INonPrimitiveValue, IValue, Disposable, Serializable, Comparable<IValue>

public class DefaultLockValue
extends Object
implements ILockValue

The default implementation of ILockValue.

Version:
CVS $Revision: 1.21 $ $Date: 2005/06/06 19:15:31 $
Author:
Robby , Matt Hoosier
See Also:
Serialized Form

Field Summary
protected  int lockCounter
          Holds the lock counter of this lock value's owner.
protected  IntSet notification
          Holds the notification set of this lock value.
protected  int owner
          Holds the owner id of this lock value.
protected  int referenceId
          Holds the reference id of this lock.
protected  LockType type
          Holds the lock type of this lock value.
protected  IValueFactory vf
          Holds the value factory of this lock value.
protected  IntSet waiting
          Holds the wait set of this lock value.
 
Constructor Summary
protected DefaultLockValue()
          Private constructor for cloning purposes.
protected DefaultLockValue(IValueFactory vf, int referenceId, LockType type, IntSet waiting, IntSet notification)
          Default constructor.
 
Method Summary
 ILockValue clone(Map<Object,Object> cloneMap)
          Override to specialize return type
 int compareTo(IValue o)
           
 void dispose()
          Remove references.
 boolean equals(Object o)
          Classes implementing IValue should provide their own equality tests.
 int getLockCounter()
          Gets the lock counter of the owner of this lock.
 IntSet getNotification()
          Gets the notification set of this lock value.
 int getOwner()
          Gets the thread id who hold this lock.
 int getReferenceId()
          Gets this non-primitive value reference id.
 Type getType()
          Gets the type of this value.
 int getTypeId()
          Gets the type id of this value.
 IntSet getWaiting()
          Gets the wait set of this lock value.
 int hashCode()
          Classes implementing IValue should provide their own hashing method.
 byte[][] linearize(int bitsPerNonPrimitiveValue, ObjectIntTable nonPrimitiveValueIdMap, int bitsPerThreadId, IntIntTable threadOrderMap)
          Linearizes this lock value.
 void opLock(int threadId)
          Does a lock operation on this lock value.
 void opNotify(int threadId, int nextThreadId)
          Does a notify operation on this lock value.
 void opNotifyAll(int threadId)
          Does a notify all operation on this lock value.
 void opUnlock(int threadId)
          Does an unlock operation on this lock.
 void opUnwait(int threadId, int i)
          Does an unwait operation on this lock value.
 int opWait(int threadId)
          Does a wait operation on this lock value.
 void setLockCounter(int lockCounter)
          Sets the lock counter of the owner of this lock.
 void setOwner(int threadId)
          Sets the thread id who holds this lock.
 boolean testHasLock(int threadId)
          Tests whether a particular thread holds this lock value.
 boolean testLockAvailable(int threadId)
          Tests whether this lock value is available to do operation on by a particular thread.
 boolean testWasNotified(int threadId)
          Tests whether a particular thread was notified in this lock value.
 String toString()
          Gets the string representation of this value.
 void undoOp(LockOp lockOp, int owner, int lockCounter, int[] notification, int[] waiting, int notifiedThreadId)
          Undo a lock op.
 void validate(IBogorConfiguration bc)
           Freshen references to Bogor model checking components and other non-serializable objects.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

vf

protected transient IValueFactory vf
Holds the value factory of this lock value. Non-null.


notification

protected IntSet notification
Holds the notification set of this lock value. Non-null.


waiting

protected IntSet waiting
Holds the wait set of this lock value. Non-null.


lockCounter

protected int lockCounter
Holds the lock counter of this lock value's owner.


owner

protected int owner
Holds the owner id of this lock value. IStateFactory.EPSILON_THREAD, if free.


type

protected LockType type
Holds the lock type of this lock value. Non-null.


referenceId

protected int referenceId
Holds the reference id of this lock. Must be greater than 0.

Constructor Detail

DefaultLockValue

protected DefaultLockValue(IValueFactory vf,
                           int referenceId,
                           LockType type,
                           IntSet waiting,
                           IntSet notification)
Default constructor.

Parameters:
vf - The value factory of this lock value. Must be non-null.
referenceId - The reference id for this lock value. Must be greater than 0.
type - The lock type for this lock value. Must be non-null.
waiting - The wait set for this lock value. Must be non-null.
notification - The notification set for this lock value. Must be non-null.

DefaultLockValue

protected DefaultLockValue()
Private constructor for cloning purposes.

Method Detail

setLockCounter

public void setLockCounter(int lockCounter)
Description copied from interface: ILockValue
Sets the lock counter of the owner of this lock.

Specified by:
setLockCounter in interface ILockValue
Parameters:
lockCounter - The lock counter if this lock is held.

getLockCounter

public int getLockCounter()
Description copied from interface: ILockValue
Gets the lock counter of the owner of this lock.

Specified by:
getLockCounter in interface ILockValue
Returns:
The lock counter if this lock is held.

getNotification

public IntSet getNotification()
Description copied from interface: ILockValue
Gets the notification set of this lock value.

Specified by:
getNotification in interface ILockValue
Returns:
The notification set of this lock value. Non-null.

setOwner

public void setOwner(int threadId)
Description copied from interface: ILockValue
Sets the thread id who holds this lock.

Specified by:
setOwner in interface ILockValue
Parameters:
threadId - The thread id who holds this lock.

getOwner

public int getOwner()
Description copied from interface: ILockValue
Gets the thread id who hold this lock.

Specified by:
getOwner in interface ILockValue
Returns:
The thread id if this lock is held, or EPSILON if free.

getReferenceId

public int getReferenceId()
Description copied from interface: INonPrimitiveValue
Gets this non-primitive value reference id.

Specified by:
getReferenceId in interface INonPrimitiveValue
Returns:
This value reference id.

getType

public Type getType()
Description copied from interface: IValue
Gets the type of this value.

Specified by:
getType in interface IValue
Returns:
The type of this value. Non-null.
See Also:
Type.getTypeId()

getTypeId

public int getTypeId()
Description copied from interface: IValue
Gets the type id of this value.

Specified by:
getTypeId in interface IValue
Returns:
The type id of this value.
See Also:
Type.getTypeId()

getWaiting

public IntSet getWaiting()
Description copied from interface: ILockValue
Gets the wait set of this lock value.

Specified by:
getWaiting in interface ILockValue
Returns:
The wait set of this lock value. Non-null.

clone

public ILockValue clone(Map<Object,Object> cloneMap)
Description copied from interface: ILockValue
Override to specialize return type

Specified by:
clone in interface ILockValue
Specified by:
clone in interface INonPrimitiveValue
Specified by:
clone in interface IValue
Parameters:
cloneMap - Original values (IValue) to their clones ( IValue) mapping. The clone map to solve circular references in values. If this value is a key in the map, then this method returns the value of the key in the map. Must be non-null.
Returns:
The clone of this value. Non-null.

dispose

public void dispose()
Description copied from interface: Disposable
Remove references. Once called, avoid using this object.

Specified by:
dispose in interface Disposable

linearize

public byte[][] linearize(int bitsPerNonPrimitiveValue,
                          ObjectIntTable nonPrimitiveValueIdMap,
                          int bitsPerThreadId,
                          IntIntTable threadOrderMap)
Description copied from interface: ILockValue
Linearizes this lock value.

Specified by:
linearize in interface ILockValue
Parameters:
bitsPerNonPrimitiveValue - The number of bits used to encode a non-primitive value.
nonPrimitiveValueIdMap - A mapping of non-primitive values to their unique id. Must be non-null.
bitsPerThreadId - The number of bits used to encode a thread descriptor.
threadOrderMap - A mapping of thread descriptors to their order number. Must be non-null.
Returns:
The bit-vectors representation of this lock value. Non-null. Each element is non-null.

opLock

public void opLock(int threadId)
Description copied from interface: ILockValue
Does a lock operation on this lock value. When successful, the given thread holds the lock value, and its lock counter is increased by one.

Specified by:
opLock in interface ILockValue
Parameters:
threadId - The thread id that wants to lock this lock value.

opNotify

public void opNotify(int threadId,
                     int nextThreadId)
Description copied from interface: ILockValue
Does a notify operation on this lock value. When successful, the given next thread id is notified (put to this lock value's notification set), and removed from the wait set.

Specified by:
opNotify in interface ILockValue
Parameters:
threadId - The thread id that wants to notify this lock value. This thread id must be contained in this lock value's wait set.
nextThreadId - If not EPSILON, then this thread id is notified (put to this lock value's notification set).

opNotifyAll

public void opNotifyAll(int threadId)
Description copied from interface: ILockValue
Does a notify all operation on this lock value. When successful, all waiting threads are notified (their thread ids are put to the notification set), if any. The wait set is then cleared.

Specified by:
opNotifyAll in interface ILockValue
Parameters:
threadId - The thread id that wants to notify this lock value.

opUnlock

public void opUnlock(int threadId)
Description copied from interface: ILockValue
Does an unlock operation on this lock. When successful, the given thread's lock counter is decreased by one. If the counter is one originally, then the thread releases the lock.

Specified by:
opUnlock in interface ILockValue
Parameters:
threadId - The thread id that wants to unlock this lock value.

opUnwait

public void opUnwait(int threadId,
                     int i)
Description copied from interface: ILockValue
Does an unwait operation on this lock value. When successful, the given thread holds this lock value with its lock counter set to i. The thread is then removed from the notification set.

Specified by:
opUnwait in interface ILockValue
Parameters:
threadId - The thread id that wants to unwait this lock value.
i - The lock counter of this lock value for the given thread. Must be at least one.

opWait

public int opWait(int threadId)
Description copied from interface: ILockValue
Does a wait operation on this lock value. When successful, this lock value is released by the thread. The thread is then put to this lock value's wait set.

Specified by:
opWait in interface ILockValue
Parameters:
threadId - The thread id that wants to wait this lock value.
Returns:
The lock counter of the thread for this lock value. At least one.

testHasLock

public boolean testHasLock(int threadId)
Description copied from interface: ILockValue
Tests whether a particular thread holds this lock value.

Specified by:
testHasLock in interface ILockValue
Parameters:
threadId - The thread id that wants to test whether it holds this lock value.
Returns:
True, if the given thread holds this lock value. False, otherwise.

testLockAvailable

public boolean testLockAvailable(int threadId)
Description copied from interface: ILockValue
Tests whether this lock value is available to do operation on by a particular thread.

Specified by:
testLockAvailable in interface ILockValue
Parameters:
threadId - The thread id that wants to test this lock value's availability.
Returns:
True, if available. False, otherwise.

testWasNotified

public boolean testWasNotified(int threadId)
Description copied from interface: ILockValue
Tests whether a particular thread was notified in this lock value.

Specified by:
testWasNotified in interface ILockValue
Parameters:
threadId - The thread id that wants to test whether it has been notified in this lock value.
Returns:
True, if the given thread has been notified. False, otherwise.

toString

public String toString()
Description copied from interface: IValue
Gets the string representation of this value.

Specified by:
toString in interface IValue
Overrides:
toString in class Object
Returns:
The string representation of this value. Non-null.

undoOp

public void undoOp(LockOp lockOp,
                   int owner,
                   int lockCounter,
                   int[] notification,
                   int[] waiting,
                   int notifiedThreadId)
Description copied from interface: ILockValue
Undo a lock op.

Specified by:
undoOp in interface ILockValue
Parameters:
lockOp - The lock op. Must be a valid.
owner - The owner of this lock value.
lockCounter - The lock counter. Must be equal or greater than 0.
notification - The notification set. Must be non-null.
waiting - The waiting set. Must be non-null.

validate

public void validate(IBogorConfiguration bc)
Description copied from interface: IValue

Freshen references to Bogor model checking components and other non-serializable objects. Generally, this can be done in a few steps:

Model checking components (IModule implementations) should be reacquired by fetching them from the parameter, bc:

     valueFactory = bc.getValueFactory();
     scheduler = bc.getSchedulingStrategist();
 

Any fields storing Type objects should be treated as stale, but still uniquely identifier by their integer typeId field. This can be used as a key to look up the correct Type instances in the new symbol table's typeId-to-type table:

     typeField = bc.getSymbolTable().getTypeIdTypeTable().get(typeField.getTypeId());
 

Any IValueArray objects contained can simply be "chained" by their IValueArray.validate(IBogorConfiguration) method:

     someValueArray.validate(bc);
 

IValue objects contained directly should not be handled manually by this method; they will be dealt with directly when they are visited later

Specified by:
validate in interface IValue
Parameters:
bc - The Bogor configuration to validate to.

equals

public boolean equals(Object o)
Description copied from interface: IValue
Classes implementing IValue should provide their own equality tests.

Specified by:
equals in interface IValue
Overrides:
equals in class Object

hashCode

public int hashCode()
Description copied from interface: IValue
Classes implementing IValue should provide their own hashing method.

Specified by:
hashCode in interface IValue
Overrides:
hashCode in class Object

compareTo

public int compareTo(IValue o)
Specified by:
compareTo in interface Comparable<IValue>