/** {@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());
    }
  }
Esempio n. 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;
  }
Esempio n. 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());
    }
  }
Esempio n. 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);
  }
    /**
     * Marks key as unlocked.
     *
     * @param key Key.
     * @return {@code True} if last locked key was unlocked.
     */
    boolean unlocked(Object key) {
      locked.remove(key);

      return locked.isEmpty();
    }
 /**
  * Marks key as locked.
  *
  * @param key Key.
  */
 void locked(Object key) {
   locked.add(key);
 }
Esempio n. 7
0
  /** {@inheritDoc} */
  @Override
  public boolean apply(GridNode n) {
    assert n != null;

    return ids.contains(n.id());
  }
Esempio n. 8
0
 /** {@inheritDoc} */
 @Override
 public Iterator<UUID> iterator() {
   return ids.iterator();
 }