@Override
  public void unlock() {
    lock.unlock();

    if (hook != null) {
      hook.lockReleased(this);
    }
  }
  @Override
  public void lockInterruptibly() throws InterruptedException {
    if (hook != null) {
      hook.attemptingAcquisition(this);
    }

    lock.lockInterruptibly();

    if (hook != null) {
      hook.lockAcquired(this);
    }
  }
  @Override
  public void lock() {
    if (hook != null) {
      hook.attemptingAcquisition(this);
    }

    lock.lock();

    if (hook != null) {
      hook.lockAcquired(this);
    }
  }
  @Override
  public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
    if (hook != null) {
      hook.attemptingAcquisition(this);
    }

    boolean result = lock.tryLock(timeout, unit);

    if (result && (hook != null)) {
      hook.lockAcquired(this);
    }

    return result;
  }
  @Override
  public boolean tryLock() {
    if (hook != null) {
      hook.attemptingAcquisition(this);
    }

    boolean result = lock.tryLock();

    if (result && (hook != null)) {
      hook.lockAcquired(this);
    }

    return result;
  }
Esempio n. 6
0
  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean present_lockid = true;
    list.add(present_lockid);
    if (present_lockid) list.add(lockid);

    boolean present_dbname = true && (isSetDbname());
    list.add(present_dbname);
    if (present_dbname) list.add(dbname);

    boolean present_tablename = true && (isSetTablename());
    list.add(present_tablename);
    if (present_tablename) list.add(tablename);

    boolean present_partname = true && (isSetPartname());
    list.add(present_partname);
    if (present_partname) list.add(partname);

    boolean present_state = true && (isSetState());
    list.add(present_state);
    if (present_state) list.add(state.getValue());

    boolean present_type = true && (isSetType());
    list.add(present_type);
    if (present_type) list.add(type.getValue());

    boolean present_txnid = true && (isSetTxnid());
    list.add(present_txnid);
    if (present_txnid) list.add(txnid);

    boolean present_lastheartbeat = true;
    list.add(present_lastheartbeat);
    if (present_lastheartbeat) list.add(lastheartbeat);

    boolean present_acquiredat = true && (isSetAcquiredat());
    list.add(present_acquiredat);
    if (present_acquiredat) list.add(acquiredat);

    boolean present_user = true && (isSetUser());
    list.add(present_user);
    if (present_user) list.add(user);

    boolean present_hostname = true && (isSetHostname());
    list.add(present_hostname);
    if (present_hostname) list.add(hostname);

    return list.hashCode();
  }
Esempio n. 7
0
  /**
   * Attempt to acquire a lock of <i>type</i> on <i>nodeId</i>. If the lock acquisition would result
   * in a deadlock, throw an exception.<br>
   * If the requested lock is not currently available, block until it is or until timeout
   * milliseconds have elapsed.<br>
   * If a lock of <i>type</i> is already held, return EXISTING.<br>
   * If a WRITE lock is held and a READ lock is requested, return PROMOTION.<br>
   * If a lock request is for a lock that is not currently held, return either NEW or DENIED
   * depending on whether the lock is granted or not.<br>
   *
   * @param nodeId The NodeId to lock.
   * @param locker The Locker to lock this on behalf of.
   * @param type The lock type requested.
   * @param timeout milliseconds to time out after if lock couldn't be obtained. 0 means block
   *     indefinitely. Not used if nonBlockingRequest is true.
   * @param nonBlockingRequest if true, means don't block if lock can't be acquired, and ignore the
   *     timeout parameter.
   * @return a LockGrantType indicating whether the request was fulfilled or not. LockGrantType.NEW
   *     means the lock grant was fulfilled and the caller did not previously hold the lock.
   *     PROMOTION means the lock was granted and it was a promotion from READ to WRITE. EXISTING
   *     means the lock was already granted (not a promotion). DENIED means the lock was not granted
   *     because the timeout passed without acquiring the lock or timeout was 0 and the lock was not
   *     immediately available.
   * @throws LockConflictException if lock could not be acquired.
   * @throws IllegalArgumentException via db/cursor read/write methods, if non-transactional access
   *     to a replicated environment is attempted, and read-uncommitted is not specified.
   */
  public LockGrantType lock(
      long nodeId,
      Locker locker,
      LockType type,
      long timeout,
      boolean nonBlockingRequest,
      DatabaseImpl database)
      throws LockConflictException, DatabaseException {

    assert timeout >= 0;

    /* No lock needed for dirty-read, return as soon as possible. */
    if (type == LockType.NONE) {
      return LockGrantType.NONE_NEEDED;
    }

    /*
     * Assert that a replication-defined locker is used for locks on
     * replicated databases.  Two cases are exempt from this rule:
     * - Only NameLNs that identify replicated DBs are replicated, not
     *   all NameLNs in the naming DB, so the naming DB is exempt.
     * - Non-preemption is permissible for selected internal operations
     *   because we can ensure that they are not long running and will not
     *   hold locks interminably.  A BasicLocker is often used internally
     *   in such cases.
     */
    if (envImpl.isReplicated()
        && database != null
        && database.isReplicated()
        && !database.getId().equals(DbTree.NAME_DB_ID)
        && (locker.getPreemptable() || type.isWriteLock())
        && !locker.isReplicationDefined()) {
      throw EnvironmentFailureException.unexpectedState("Locker: " + locker.getClass().getName());
    }

    /*
     * Lock on locker before latching the lockTable to avoid having another
     * notifier perform the notify before the waiter is actually waiting.
     */
    synchronized (locker) {
      LockGrantType ret = null;
      ret = lockInternal(nodeId, locker, type, timeout, nonBlockingRequest, database);
      return ret;
    }
  }
 @Override
 public Condition newCondition() {
   return lock.newCondition();
 }
Esempio n. 9
0
 public static LockType fromString(String lockType) {
   for (LockType lock : LockType.values())
     if (lock.toString().equals(lockType.toLowerCase())) return lock;
   return null;
 }