Ejemplo n.º 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();
    }
  }