Example #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;
  }
Example #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;
  }
Example #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;
  }
Example #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;
  }