Class Lock


  • public final class Lock
    extends java.lang.Object
    This is a lock on a table in the LockingMechanism class. A new instance of this class is created whenever a new lock for a table is made. A Lock may be either a READ lock or a WRITE lock. A lock is within a LockingQueue object.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private DebugLogger debug
      The DebugLogger object that we log debug message to.
      private LockingQueue queue
      The table queue this lock is 'inside'.
      static int READ
      These statics are used to define whether the lock is a READ or WRITE lock.
      private int type
      This stores the type of lock.
      private boolean was_checked
      This is set to true when the 'checkAccess' method is called on this lock.
      static int WRITE  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void checkAccess​(int access_type)
      Checks the access for this lock.
      (package private) DataTable getTable()
      Returns the DataTable object this lock is locking
      (package private) int getType()
      Returns the type of lock.
      (package private) java.lang.String getTypeAsString()
      Returns the type of the lock as a string.
      (package private) void release()
      Removes this lock from the queue.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • READ

        public static final int READ
        These statics are used to define whether the lock is a READ or WRITE lock.
        See Also:
        Constant Field Values
      • type

        private int type
        This stores the type of lock. It is either set to 'READ' or 'WRITE'
      • queue

        private LockingQueue queue
        The table queue this lock is 'inside'.
      • was_checked

        private boolean was_checked
        This is set to true when the 'checkAccess' method is called on this lock.
      • debug

        private final DebugLogger debug
        The DebugLogger object that we log debug message to.
    • Constructor Detail

      • Lock

        Lock​(int type,
             LockingQueue queue,
             DebugLogger logger)
        The Constructor. As well as setting up the state of this object, it also puts this lock into the table queue.
    • Method Detail

      • getType

        int getType()
        Returns the type of lock.
      • getTypeAsString

        java.lang.String getTypeAsString()
        Returns the type of the lock as a string.
      • getTable

        DataTable getTable()
        Returns the DataTable object this lock is locking
      • release

        void release()
        Removes this lock from the queue. This is called when lock is released from the table queues. NOTE: This method does not need to be synchronized because synchronization is handled by the 'LockingMechanism.unlockTables' method.
      • checkAccess

        void checkAccess​(int access_type)
        Checks the access for this lock. This asks the queue that contains this lock if it is currently safe to access the table. If it is unsafe for the table to be accessed, then it blocks until it is safe. Therefore, when this method returns, it is safe to access the table for this lock. The 'access_type' variable contains either 'READ' or 'WRITE' and is set to the type of access that is currently being done to the table. If access_type == WRITE then this.type must be WRITE. If access_type == READ then this.type may be either READ or WRITE.

        NOTE: After the first call to this method, following calls will not block.

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object