Пример #1
0
  /**
   * Close this PersistentStore without destroying its contents
   *
   * @throws IOException If file system access errors are encountered
   */
  public void close() throws IOException {
    try {
      // Using write lock because we want an exclusive lock
      mutatorLock.writeLock();
      updateCount = 0;

      // Don't need to sync on this because
      // mutatorLock.writeLock() gives us an exclusive lock
      log.close();
    } finally {
      // Using write lock because we want an exclusive lock
      mutatorLock.writeUnlock();
    }
  }
Пример #2
0
  /**
   * Block until we can acquire a non-exclusive mutator lock on the servers 's persistent state.
   * This lock should be acquired in a <code>try</code> block and a <code>releaseMutatorLock</code>
   * call should be placed in a <code>finally</code> block.
   */
  public void acquireMutatorLock() {
    // Do we already hold a lock?

    Long lockStateVal = lockState.get();
    if (lockStateVal == null) lockStateVal = zero;

    final long longVal = lockStateVal;

    if (longVal == 0) {
      // No, this thread currently does not hold a lock,
      // grab non-exclusive lock (which for mutatorLock is a
      // read lock)
      mutatorLock.readLock();
    }

    // Ether way, bump the lock count and update our thread state
    lockState.set(longVal + 1);
  }
Пример #3
0
  /** Release one level of mutator locks if this thread holds at lease one. */
  public void releaseMutatorLock() {
    Long lockStateVal = lockState.get();
    if (lockStateVal == null) lockStateVal = zero;

    final long longVal = lockStateVal;

    if (longVal == 0)
      // No lock to release, return
      return;

    if (longVal == 1) {
      // Last one on stack release lock
      // Using read lock because we want a non-exclusive lock
      mutatorLock.readUnlock();
      lockStateVal = zero;
    } else {
      lockStateVal = longVal - 1;
    }

    lockState.set(lockStateVal);
  }