org.egothor.lock.server
Class LockServerThread.LockServerRecord

java.lang.Object
  extended by org.egothor.lock.server.LockServerThread.LockServerRecord
Enclosing class:
LockServerThread

public class LockServerThread.LockServerRecord
extends java.lang.Object

Record of single location, holds information about lock in it and reservations.


Nested Class Summary
 class LockServerThread.LockServerRecord.LockEntry
           
 class LockServerThread.LockServerRecord.ReservationEntry
           
 
Field Summary
protected  java.util.LinkedList<LockServerThread.LockServerRecord.LockEntry> lockEntryList
          list of lock entries (locks) that are present in one location
 
Constructor Summary
LockServerThread.LockServerRecord(java.lang.String location)
           
 
Method Summary
 boolean addLockEntry(long lockId, LockType lockType, long expirationTime)
           
 LockResult addReservationEntry(LockType lockType, long reservationExpirationTime, boolean addFirst)
           
 boolean containsValidOrExpiredLock(long validationTime)
          Finds out if entries contains valid lock entry in comparison to time expiration or if there is any expired write or read lock (that means thread crashed and index is in incosistent state).
 boolean containsValidReservation(long now)
          Checks reservation for a valid one.
 LockServerThread.LockServerRecord.LockEntry getFirstLockEntry(long validationTime)
          Either set of read locks is present or one single write lock, so this method returns a fine representant.
 LockServerThread.LockServerRecord.LockEntry getLockEntryWithId(long lockId)
           
 long getLockExpirationTime()
           
 int indexOfReservation(long reservationId, LockType lockType)
           
 boolean isWLReservationPreceedingThisOne(int reservationIndex)
          Checks if there is a write lock reservation in the reservation list that precedes the one with input index.
 void removeFirstReservation()
           
 void removeLockEntry(LockServerThread.LockServerRecord.LockEntry lockEntry)
           
 void removeReservation(int index)
           
 int sizeOfReservationList()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lockEntryList

protected java.util.LinkedList<LockServerThread.LockServerRecord.LockEntry> lockEntryList
list of lock entries (locks) that are present in one location

Constructor Detail

LockServerThread.LockServerRecord

public LockServerThread.LockServerRecord(java.lang.String location)
Method Detail

addLockEntry

public boolean addLockEntry(long lockId,
                            LockType lockType,
                            long expirationTime)
Parameters:
lockId -
lockType -
expirationTime -

removeLockEntry

public void removeLockEntry(LockServerThread.LockServerRecord.LockEntry lockEntry)
Parameters:
lockEntry -

containsValidOrExpiredLock

public boolean containsValidOrExpiredLock(long validationTime)
Finds out if entries contains valid lock entry in comparison to time expiration or if there is any expired write or read lock (that means thread crashed and index is in incosistent state). If it finds any expired lock, it launches recovery process in that location.

Parameters:
validationTime -
Returns:

getFirstLockEntry

public LockServerThread.LockServerRecord.LockEntry getFirstLockEntry(long validationTime)
Either set of read locks is present or one single write lock, so this method returns a fine representant.

Parameters:
validationTime -
Returns:

getLockEntryWithId

public LockServerThread.LockServerRecord.LockEntry getLockEntryWithId(long lockId)
Parameters:
lockId -
Returns:

getLockExpirationTime

public long getLockExpirationTime()
Returns:

containsValidReservation

public boolean containsValidReservation(long now)
Checks reservation for a valid one. It discards the invalid ones.

Parameters:
lockRecord -
now -
Returns:

addReservationEntry

public LockResult addReservationEntry(LockType lockType,
                                      long reservationExpirationTime,
                                      boolean addFirst)
Parameters:
lockRecord -
lockType -
reservationExpirationTime -
Returns:

isWLReservationPreceedingThisOne

public boolean isWLReservationPreceedingThisOne(int reservationIndex)
Checks if there is a write lock reservation in the reservation list that precedes the one with input index.

Parameters:
reservationIndex -
Returns:

indexOfReservation

public int indexOfReservation(long reservationId,
                              LockType lockType)

sizeOfReservationList

public int sizeOfReservationList()

removeFirstReservation

public void removeFirstReservation()

removeReservation

public void removeReservation(int index)