Ejemplo n.º 1
0
  /**
   * @param exclude Versions to exclude form check.
   * @return {@code True} if lock is empty.
   */
  public boolean isEmpty(GridCacheVersion... exclude) {
    if (locs == null && rmts == null) return true;

    if (locs != null) {
      assert !locs.isEmpty();

      if (F.isEmpty(exclude)) return false;

      for (GridCacheMvccCandidate cand : locs)
        if (!U.containsObjectArray(exclude, cand.version())) return false;
    }

    if (rmts != null) {
      assert !rmts.isEmpty();

      if (F.isEmpty(exclude)) return false;

      for (GridCacheMvccCandidate cand : rmts)
        if (!U.containsObjectArray(exclude, cand.version())) return false;
    }

    return true;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  /**
   * @param col Collection of candidates.
   * @param reentries Reentry flag.
   * @param cp Whether to copy or not.
   * @param excludeVers Exclude versions.
   * @return Collection of candidates minus the exclude versions.
   */
  private List<GridCacheMvccCandidate> candidates(
      List<GridCacheMvccCandidate> col,
      boolean reentries,
      boolean cp,
      GridCacheVersion... excludeVers) {
    if (col == null) return Collections.emptyList();

    assert !col.isEmpty();

    if (!cp && F.isEmpty(excludeVers)) return col;

    List<GridCacheMvccCandidate> cands = new ArrayList<>(col.size());

    for (GridCacheMvccCandidate c : col) {
      // Don't include reentries.
      if ((!c.reentry() || (reentries && c.reentry()))
          && !U.containsObjectArray(excludeVers, c.version())) cands.add(c);
    }

    return cands;
  }