/** {@inheritDoc} */ @Override public final GridProjection forNodeIds(Collection<UUID> ids) { A.notEmpty(ids, "ids"); guard(); try { Set<UUID> nodeIds = U.newHashSet(ids.size()); for (UUID id : ids) { if (contains(id)) nodeIds.add(id); } return new GridProjectionAdapter(this, ctx, subjId, nodeIds); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public final GridProjection forRemotes() { return forOthers(Collections.singleton(ctx.localNodeId())); }
/** {@inheritDoc} */ @Override public GridProjectionEx forSubjectId(UUID subjId) { if (subjId == null) return this; guard(); try { return ids != null ? new GridProjectionAdapter(this, ctx, subjId, ids) : new GridProjectionAdapter(this, ctx, subjId, p); } finally { unguard(); } }
/** * @param excludeIds Node IDs. * @return New projection. */ private GridProjection forOthers(Collection<UUID> excludeIds) { assert excludeIds != null; if (ids != null) { guard(); try { Set<UUID> nodeIds = U.newHashSet(ids.size()); for (UUID id : ids) { if (!excludeIds.contains(id)) nodeIds.add(id); } return new GridProjectionAdapter(this, ctx, subjId, nodeIds); } finally { unguard(); } } else return forPredicate(new OthersFilter(excludeIds)); }
/** {@inheritDoc} */ @Override public final GridProjection forCache(@Nullable String cacheName, @Nullable String... cacheNames) { return forPredicate(new CachesFilter(cacheName, cacheNames)); }
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ protected Object readResolve() throws ObjectStreamException { try { GridKernal g = GridGainEx.gridx(gridName); return ids != null ? new GridProjectionAdapter(g, g.context(), subjId, ids) : p != null ? new GridProjectionAdapter(g, g.context(), subjId, p) : g; } catch (IllegalStateException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } }
/** {@inheritDoc} */ @Override public GridNode node() { return F.first(nodes()); }
/** {@inheritDoc} */ @Override public final GridProjection forHost(GridNode node) { A.notNull(node, "node"); String macs = node.attribute(ATTR_MACS); assert macs != null; return forAttribute(ATTR_MACS, macs); }
/** {@inheritDoc} */ @Override public GridProjection forOthers(GridProjection prj) { A.notNull(prj, "prj"); if (ids != null) { guard(); try { Set<UUID> nodeIds = U.newHashSet(ids.size()); for (UUID id : ids) { GridNode n = node(id); if (n != null && !prj.predicate().apply(n)) nodeIds.add(id); } return new GridProjectionAdapter(this, ctx, subjId, nodeIds); } finally { unguard(); } } else return forPredicate(F.not(prj.predicate())); }
/** {@inheritDoc} */ @Override public final GridProjection forPredicate(GridPredicate<GridNode> p) { A.notNull(p, "p"); guard(); try { return new GridProjectionAdapter(this, ctx, subjId, this.p != null ? F.and(p, this.p) : p); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public final GridNode node(UUID id) { A.notNull(id, "id"); guard(); try { if (ids != null) return ids.contains(id) ? ctx.discovery().node(id) : null; else { GridNode node = ctx.discovery().node(id); return node != null && (p == null || p.apply(node)) ? node : null; } } finally { unguard(); } }
/** {@inheritDoc} */ @Override public final GridProjection forStreamer(@Nullable String streamerName, @Nullable String... streamerNames) { return forPredicate(new StreamersFilter(streamerName, streamerNames)); }
/** {@inheritDoc} */ @Override public GridProjection forLocal() { ctx.gateway().readLock(); try { return new GridProjectionAdapter(this, ctx, null, Collections.singleton(cfg.getNodeId())); } finally { ctx.gateway().readUnlock(); } }
/** {@inheritDoc} */ @Override public final GridProjection forNodes(Collection<? extends GridNode> nodes) { A.notEmpty(nodes, "nodes"); guard(); try { Set<UUID> nodeIds = U.newHashSet(nodes.size()); for (GridNode n : nodes) if (contains(n)) nodeIds.add(n.id()); return new GridProjectionAdapter(this, ctx, subjId, nodeIds); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public Collection<GridNode> nodes() { guard(); try { if (ids != null) { if (ids.isEmpty()) return Collections.emptyList(); else if (ids.size() == 1) { GridNode node = ctx.discovery().node(F.first(ids)); return node != null ? Collections.singleton(node) : Collections.<GridNode>emptyList(); } else { Collection<GridNode> nodes = new ArrayList<>(ids.size()); for (UUID id : ids) { GridNode node = ctx.discovery().node(id); if (node != null) nodes.add(node); } return nodes; } } else { Collection<GridNode> all = ctx.discovery().allNodes(); return p != null ? F.view(all, p) : all; } } finally { unguard(); } }
/** {@inheritDoc} */ @Override public final GridProjection forDaemons() { return forPredicate(new DaemonFilter()); }