/** {@inheritDoc} */
  @Nullable
  @Override
  public Map<? extends GridComputeJob, GridNode> map(
      List<GridNode> subgrid, @Nullable GridBiTuple<Set<UUID>, A> arg) throws GridException {
    assert arg != null;
    assert arg.get1() != null;

    start = U.currentTimeMillis();

    boolean debug = debugState(g);

    if (debug) logStart(g.log(), getClass(), start);

    Set<UUID> nodeIds = arg.get1();

    Map<GridComputeJob, GridNode> map = U.newHashMap(nodeIds.size());

    try {
      taskArg = arg.get2();

      for (GridNode node : subgrid) if (nodeIds.contains(node.id())) map.put(job(taskArg), node);

      return map;
    } finally {
      if (debug) logMapped(g.log(), getClass(), map.values());
    }
  }
示例#2
0
  /** {@inheritDoc} */
  @Override
  public int hashCode() {
    // Allow for multiple hash calculations to avoid
    // synchronization cost. Note that array of IDs don't change.
    if (hash == Integer.MIN_VALUE) hash = ids.hashCode();

    return hash;
  }
示例#3
0
  /**
   * Creates node predicate that evaluates to {@code true} for all provided nodes. Implementation
   * will make a defensive copy.
   *
   * @param nodes Optional grid nodes. If none provided - predicate will always return {@code
   *     false}.
   */
  public GridNodePredicate(@Nullable GridNode... nodes) {
    if (F.isEmpty(nodes)) ids = Collections.emptySet();
    else if (nodes.length == 1) ids = Collections.singleton(nodes[0].id());
    else {
      ids = new HashSet<>(nodes.length);

      for (GridNode n : nodes) ids.add(n.id());
    }
  }
示例#4
0
  /** {@inheritDoc} */
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;

    if (!(o instanceof GridNodePredicate)) return false;

    GridNodePredicate it = (GridNodePredicate) o;

    return ids.equals(it.ids);
  }
示例#5
0
  /** {@inheritDoc} */
  @Override
  public boolean apply(GridNode n) {
    assert n != null;

    return ids.contains(n.id());
  }
示例#6
0
 /** {@inheritDoc} */
 @Override
 public Iterator<UUID> iterator() {
   return ids.iterator();
 }