edu.ksu.cis.projects.bogor.module.value
Interface ILockValue

All Superinterfaces:
Comparable<IValue>, Disposable, INonPrimitiveValue, IValue, Serializable
All Known Implementing Classes:
DefaultLockValue

public interface ILockValue
extends INonPrimitiveValue

Represents a lock value.

Version:
CVS $Revision: 1.7 $ $Date: 2005/06/06 19:15:31 $
Author:
Robby

Method Summary
 ILockValue clone(Map<Object,Object> cloneMap)
          Override to specialize return type
 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.
 IntSet getWaiting()
          Gets the wait set of this lock value.
 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.
 void undoOp(LockOp lockOp, int owner, int lockCounter, int[] notification, int[] waiting, int notifiedThreadId)
          Undo a lock op.
 
Methods inherited from interface edu.ksu.cis.projects.bogor.module.value.INonPrimitiveValue
getReferenceId
 
Methods inherited from interface edu.ksu.cis.projects.bogor.module.value.IValue
equals, getType, getTypeId, hashCode, toString, validate
 
Methods inherited from interface edu.ksu.cis.projects.bogor.util.Disposable
dispose
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Method Detail

setLockCounter

void setLockCounter(int lockCounter)
Sets the lock counter of the owner of this lock.

Parameters:
lockCounter - The lock counter if this lock is held.

getLockCounter

int getLockCounter()
Gets the lock counter of the owner of this lock.

Returns:
The lock counter if this lock is held.

getNotification

IntSet getNotification()
Gets the notification set of this lock value.

Returns:
The notification set of this lock value. Non-null.

setOwner

void setOwner(int threadId)
Sets the thread id who holds this lock.

Parameters:
threadId - The thread id who holds this lock.

getOwner

int getOwner()
Gets the thread id who hold this lock.

Returns:
The thread id if this lock is held, or EPSILON if free.

getWaiting

IntSet getWaiting()
Gets the wait set of this lock value.

Returns:
The wait set of this lock value. Non-null.

linearize

byte[][] linearize(int bitsPerNonPrimitiveValue,
                   ObjectIntTable nonPrimitiveValueIdMap,
                   int bitsPerThreadId,
                   IntIntTable threadOrderMap)
Linearizes this lock value.

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

void opLock(int threadId)
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.

Parameters:
threadId - The thread id that wants to lock this lock value.
Throws:
BadMonitorBogorException - When the lock value is held by other thread.

opNotify

void opNotify(int threadId,
              int nextThreadId)
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.

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).
Throws:
BadMonitorBogorException - When the lock value is held by other thread or the lock value is free.

opNotifyAll

void opNotifyAll(int threadId)
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.

Parameters:
threadId - The thread id that wants to notify this lock value.
Throws:
BadMonitorBogorException - When the lock value is held by other thread or the lock value is free.

opUnlock

void opUnlock(int threadId)
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.

Parameters:
threadId - The thread id that wants to unlock this lock value.
Throws:
BadMonitorBogorException - When the lock value is held by other thread or the lock value is free.

opUnwait

void opUnwait(int threadId,
              int i)
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.

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.
Throws:
BadMonitorBogorException - When the lock value is not free, or the given thread id is not in this lock value's notification set.

opWait

int opWait(int threadId)
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.

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.
Throws:
BadMonitorBogorException - When the lock value is free, or held by another thread.

testHasLock

boolean testHasLock(int threadId)
Tests whether a particular thread holds this lock value.

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

boolean testLockAvailable(int threadId)
Tests whether this lock value is available to do operation on by a particular thread.

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

testWasNotified

boolean testWasNotified(int threadId)
Tests whether a particular thread was notified in this lock value.

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.

undoOp

void undoOp(LockOp lockOp,
            int owner,
            int lockCounter,
            int[] notification,
            int[] waiting,
            int notifiedThreadId)
Undo a lock op.

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.

clone

ILockValue clone(Map<Object,Object> cloneMap)
Override to specialize return type

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.