Esempio n. 1
0
  /**
   * @param cacheCtx Cache context.
   * @param cand Cache lock candidate to add.
   * @return {@code True} if added as a result of this operation, {@code false} if was previously
   *     added.
   */
  public boolean addNext(GridCacheContext cacheCtx, GridCacheMvccCandidate cand) {
    assert cand != null;
    assert !cand.reentry() : "Lock reentries should not be linked: " + cand;

    // Don't order near candidates by thread as they will be ordered on
    // DHT node. Also, if candidate is implicit, no point to order him.
    if (cacheCtx.isNear() || cand.singleImplicit()) return true;

    LinkedList<GridCacheMvccCandidate> queue = pending.get();

    GridCacheMvccCandidate prev = null;

    if (!queue.isEmpty()) prev = queue.getLast();

    queue.add(cand);

    if (prev != null) {
      prev.next(cand);

      cand.previous(prev);
    }

    if (log.isDebugEnabled()) log.debug("Linked new candidate: " + cand);

    return true;
  }
Esempio n. 2
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;
  }
Esempio n. 3
0
  /**
   * @param threadId Thread ID.
   * @param reentry Reentry flag.
   * @return Local candidate for the thread.
   */
  @Nullable
  private GridCacheMvccCandidate localCandidate(long threadId, boolean reentry) {
    if (locs != null)
      for (GridCacheMvccCandidate cand : locs) {
        if (cand.threadId() == threadId) {
          if (cand.reentry() && !reentry) continue;

          return cand;
        }
      }

    return null;
  }