示例#1
0
  /**
   * Local release.
   *
   * @param threadId ID of the thread.
   * @return Removed candidate.
   */
  @Nullable
  public GridCacheMvccCandidate releaseLocal(long threadId) {
    CacheLockCandidates owners = localOwners();

    // Release had no effect.
    if (owners == null) return null;

    GridCacheMvccCandidate owner = null;

    for (int i = 0; i < owners.size(); i++) {
      GridCacheMvccCandidate owner0 = owners.candidate(i);

      if (owner0.threadId() == threadId) {
        owner = owner0;

        break;
      }
    }

    if (owner != null) {
      owner.setUsed();

      remove0(owner.version(), true);

      return owner;
    } else return null;
  }
示例#2
0
  /**
   * @param lockVer Lock ID.
   * @param threadId Thread ID.
   * @return {@code True} if locked by lock ID or thread ID.
   */
  boolean isLocallyOwnedByIdOrThread(GridCacheVersion lockVer, long threadId) {
    CacheLockCandidates owners = localOwners();

    if (owners != null) {
      for (int i = 0; i < owners.size(); i++) {
        GridCacheMvccCandidate owner = owners.candidate(i);

        if ((owner.version().equals(lockVer) || owner.threadId() == threadId)) return true;
      }
    }

    return false;
  }
示例#3
0
  /**
   * @param threadId Thread ID to check.
   * @param exclude Versions to ignore.
   * @return {@code True} if lock is owned by the thread with given ID.
   */
  boolean isLocallyOwnedByThread(long threadId, boolean allowDhtLoc, GridCacheVersion... exclude) {
    CacheLockCandidates owners = localOwners();

    if (owners != null) {
      for (int i = 0; i < owners.size(); i++) {
        GridCacheMvccCandidate owner = owners.candidate(i);

        if (owner.threadId() == threadId
            && owner.nodeId().equals(cctx.nodeId())
            && (allowDhtLoc || !owner.dhtLocal())
            && !U.containsObjectArray(exclude, owner.version())) return true;
      }
    }

    return false;
  }
示例#4
0
  /** @return All local owners. */
  @Nullable
  public CacheLockCandidates localOwners() {
    if (locs != null) {
      assert !locs.isEmpty();

      CacheLockCandidates owners = null;

      GridCacheMvccCandidate first = locs.getFirst();

      if (first.read()) {
        for (GridCacheMvccCandidate cand : locs) {
          if (cand.owner()) {
            assert cand.read() : this;

            if (owners != null) {
              CacheLockCandidatesList list;

              if (owners.size() == 1) {
                GridCacheMvccCandidate owner = owners.candidate(0);

                owners = list = new CacheLockCandidatesList();

                ((CacheLockCandidatesList) owners).add(owner);
              } else list = ((CacheLockCandidatesList) owners);

              list.add(cand);
            } else owners = cand;
          }

          if (!cand.read()) break;
        }
      } else if (first.owner()) owners = first;

      return owners;
    }

    return null;
  }
示例#5
0
  /**
   * @param ver Version to check for ownership.
   * @return {@code True} if lock is owned by the specified version.
   */
  boolean isOwnedBy(GridCacheVersion ver) {
    CacheLockCandidates owners = allOwners();

    return owners != null && owners.hasCandidate(ver);
  }
示例#6
0
  /**
   * @param lockVer ID of lock candidate.
   * @return {@code True} if candidate is owner.
   */
  boolean isLocallyOwned(GridCacheVersion lockVer) {
    CacheLockCandidates owners = localOwners();

    return owners != null && owners.hasCandidate(lockVer);
  }