- public class DbLockTable
- extends java.lang.Object
The "DbLockTable" class represents a table of locks
with the following features:A
- It maintain locks as elements of the form (recNum,Setter).
Setter is the id of the Client who has placed a lock on the recNum.
There are two levels of Locking:
- DataBase Locking : recNum is "-1"
- Record Locking : recNum is an integer greater than 0
- Record/DataBase can be locked and unlocked on the request of a client.
- 1.0 07/31/99
The method to release all locks from the DataBase.
The method releases all the locks currently held by the "clientID".
The method to remove a lock set by the clientID before.
The method to set a lock on a record/DataBase by a clientID.
|Methods inherited from class java.lang.Object
public void setLock(int recNum,
- The method to set a lock on a record/DataBase by a clientID.
It places the lock based on the following conditions:
If the same client who has placed the lock before,request
again to lock the same record or DataBase, no new lock is
added into the lockTable.This is achieved by the default
behaviour of Hashtable.put() method, which returns "false"
if the (key) already exist.
If the locking cannot be achieved, the thread/cllient
blocks itself by calling "wait()".With this call, it releases
the lock on the "DbLockTable" instance and hence allows any other
client who holds the lock, to come in and remove the lock.
Once the blocking Client is notified by another Client who has released
a lock, it tries to place a lock again. It returns after it has obtained
the desired lock.
- No DataBase Level locking has been placed by other
- No Record Level lock already exist on the record
placed by another user.
recNum - : The record number of the record requested to be locked
If it is "-1" the request is to lock the DataBase.
clientID - : The Id of the Client requesting the Lock.
This is a Globally unique ID obtained as the
concatenation of "hostname of client" and the
unique id returned by "java.rmi.UID" at client side.
public void removeLock(int recNum,
- The method to remove a lock set by the clientID before.
If the lock does not exist, it does nothing and return.
If the setter of the lock is not the clientID specified,
then do nothing.
If the clientID is the setter of the lock and the lock already
exist from before,then remove the lock from the lockTable and
calls "notifyAll()" to inform clients waiting on to place a lock
to try again.
recNum: - The record number from which lock is to be released.
clientID: - The clientID who wants to release the lock from recNum.
public void releaseLocks(java.lang.String clientID)
- The method releases all the locks currently held by the "clientID".
This method must be called whenever a connection is severed
with the client having the id "clientId".
clientId - : The clientID whose connection has been just severed.
public void releaseLocks()
- The method to release all locks from the DataBase.
This routine is called from:
- finalize() method of the RMI server, when the server managing this
DataBase is being garbage collected.
- unreferenced() method of RMI server,when there is no client
connection to the server.