Example #1
0
  /**
   * Add a lock to this file
   *
   * @param lock FileLock
   * @exception LockConflictException
   */
  public final void addLock(FileLock lock) throws LockConflictException {

    //	Check if the lock list has been allocated

    if (m_lockList == null) {

      synchronized (this) {

        //	Allocate the lock list, check if the lock list has been allocated elsewhere
        //	as we may have been waiting for the lock

        if (m_lockList == null) m_lockList = new FileLockList();
      }
    }

    //	Add the lock to the list, check if there are any lock conflicts

    synchronized (m_lockList) {

      //	Check if the new lock overlaps with any existing locks

      if (m_lockList.allowsLock(lock)) {

        //	Add the new lock to the list

        m_lockList.addLock(lock);
      } else throw new LockConflictException();
    }
  }
Example #2
0
  /**
   * Remove a lock on this file
   *
   * @param lock FileLock
   * @exception NotLockedException
   */
  public final void removeLock(FileLock lock) throws NotLockedException {

    //	Check if the lock list has been allocated

    if (m_lockList == null) throw new NotLockedException();

    //	Remove the lock from the active list

    synchronized (m_lockList) {

      //	Remove the lock, check if we found the matching lock

      if (m_lockList.removeLock(lock) == null) throw new NotLockedException();
    }
  }
Example #3
0
  /**
   * Check if the file is writeable for the specified section of the file and process id
   *
   * @param offset long
   * @param len long
   * @param pid int
   * @return boolean
   */
  public final boolean canWriteFile(long offset, long len, int pid) {

    //	Check if the lock list is valid

    if (m_lockList == null) return true;

    //	Check if the file section is writeable by the specified process

    boolean writeOK = false;

    synchronized (m_lockList) {

      //	Check if the file section is writeable

      writeOK = m_lockList.canWriteFile(offset, len, pid);
    }

    //	Return the write status

    return writeOK;
  }
Example #4
0
 /**
  * Return the count of active locks on this file
  *
  * @return int
  */
 public final int numberOfLocks() {
   if (m_lockList != null) return m_lockList.numberOfLocks();
   return 0;
 }
Example #5
0
 /**
  * Check if there are active locks on this file
  *
  * @return boolean
  */
 public final boolean hasActiveLocks() {
   if (m_lockList != null && m_lockList.numberOfLocks() > 0) return true;
   return false;
 }