/** {@inheritDoc} */ @Override public final Grid grid() { assert ctx != null; guard(); try { return ctx.grid(); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public final GridProjectionMetrics metrics() throws GridException { guard(); try { if (nodes().isEmpty()) throw U.emptyTopologyException(); return new GridProjectionMetricsImpl(this); } finally { unguard(); } }
/** {@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 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 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 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 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 final GridProjection forNodeId(UUID id, UUID... ids) { A.notNull(id, "id"); guard(); try { Set<UUID> nodeIds; if (F.isEmpty(ids)) nodeIds = contains(id) ? Collections.singleton(id) : Collections.<UUID>emptySet(); else { nodeIds = U.newHashSet(ids.length + 1); for (UUID id0 : ids) { if (contains(id)) nodeIds.add(id0); } if (contains(id)) nodeIds.add(id); } return new GridProjectionAdapter(this, ctx, subjId, nodeIds); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public final GridProjection forNode(GridNode node, GridNode... nodes) { A.notNull(node, "node"); guard(); try { Set<UUID> nodeIds; if (F.isEmpty(nodes)) nodeIds = contains(node) ? Collections.singleton(node.id()) : Collections.<UUID>emptySet(); else { nodeIds = U.newHashSet(nodes.length + 1); for (GridNode n : nodes) if (contains(n)) nodeIds.add(n.id()); if (contains(node)) nodeIds.add(node.id()); } return new GridProjectionAdapter(this, ctx, subjId, nodeIds); } 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 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())); }