/** * * @param nodes Set of nodes. * @return Primary node. */ public static GridNode primary(Iterable<? extends GridNode> nodes) { GridNode n = F.first(nodes); assert n != null; return n; }
/** * @param iters Iterators. */ private CompoundIterator(List<GridIterator<T>> iters) { if (iters.isEmpty()) throw new IllegalArgumentException(); this.iters = iters; iter = F.first(iters); }
/** {@inheritDoc} */ @Override public Boolean reduce(List<GridComputeJobResult> results) throws GridException { return F.first(results).getData(); } }
/** {@inheritDoc} */ @Nullable @Override public String fileName() { FileAppender fapp = F.first(fileAppenders); return fapp != null ? fapp.getFile() : null; }
/** * Creates node predicate that evaluates to {@code true} for all * provided node IDs. Implementation will make a defensive copy. * * @param ids Optional node IDs. If none provided - predicate will always return {@code false}. */ public GridNodePredicate(@Nullable Collection<UUID> ids) { this.ids = F.isEmpty(ids) ? Collections.<UUID>emptySet() : ids.size() == 1 ? Collections.singleton(F.first(ids)) : new HashSet<>(ids); }
/** {@inheritDoc} */ @Override public E pollEvicted() throws GridException { return F.first(pollEvicted(1)); }
/** {@inheritDoc} */ @Override public byte[] reduce(List<GridComputeJobResult> results) throws GridException { return F.first(results).getData(); }
/** {@inheritDoc} */ @Override public GridNode node() { return F.first(nodes()); }
/** * Maps single key to a node. * * @param cacheName Cache name. * @param key Key to map. * @return Picked node. * @throws GridException If failed. */ @Nullable public <K> GridNode mapKeyToNode(@Nullable String cacheName, K key, long topVer) throws GridException { Map<GridNode, Collection<K>> map = keysToNodes(cacheName, F.asList(key), topVer); return map != null ? F.first(map.keySet()) : null; }
/** * Maps single key to a node. * * @param cacheName Cache name. * @param key Key to map. * @return Picked node. * @throws GridException If failed. */ @Nullable public <K> GridNode mapKeyToNode(@Nullable String cacheName, K key) throws GridException { Map<GridNode, Collection<K>> map = keysToNodes(cacheName, F.asList(key)); return map != null ? F.first(map.keySet()) : null; }
/** * @param nodes Nodes. * @return Backup nodes. */ public static Collection<GridNode> backups(Collection<GridNode> nodes) { if (nodes == null || nodes.size() <= 1) return Collections.emptyList(); return F.view(nodes, F.notEqualTo(F.first(nodes))); }
/** * @param nodes Nodes. * @param locId Local node ID. * @return Local node if it is in the list of nodes, or primary node. */ public static GridNode localOrPrimary(Iterable<GridNode> nodes, UUID locId) { assert !F.isEmpty(nodes); for (GridNode n : nodes) if (n.id().equals(locId)) return n; return F.first(nodes); }
private static int cpus(Map<String, Collection<GridNode>> neighborhood) { int cpus = 0; for (Collection<GridNode> nodes : neighborhood.values()) { GridNode first = F.first(nodes); // Projection can be empty if all nodes in it failed. if (first != null) cpus += first.metrics().getTotalCpus(); } return cpus; }
/** {@inheritDoc} */ @Override @Nullable public GridNode mapKeyToNode(K key) { A.notNull(key, "key"); return F.first(mapKeysToNodes(F.asList(key)).keySet()); }
/** {@inheritDoc} */ @Nullable @Override protected R reduce0(List<GridComputeJobResult> results) throws GridException { assert results.size() == 1; GridComputeJobResult res = F.first(results); if (res.getException() == null) return res.getData(); throw res.getException(); } }
/** {@inheritDoc} */ @Override protected GridCacheSqlMetadata run(String cacheName) throws GridException { GridCache<Object, Object> cache = g.cachex(cacheName); if (cache != null) { GridCacheQueriesEx<Object, Object> queries = (GridCacheQueriesEx<Object, Object>) cache.queries(); return F.first(queries.sqlMetadata()); } throw new GridException("Cache not found: " + cacheName); }
/** {@inheritDoc} */ @Override public String shortDisplay() { return name() + ": id8=" + U.id8(evtNode.id()) + ", ip=" + F.first(evtNode.addresses()); }
/** {@inheritDoc} */ @Override public GridSecurityContext authenticateNode(GridNode node, GridSecurityCredentials cred) throws GridException { GridSecuritySubjectAdapter s = new GridSecuritySubjectAdapter(GridSecuritySubjectType.REMOTE_NODE, node.id()); s.address(new InetSocketAddress(F.first(node.addresses()), 0)); s.permissions(ALLOW_ALL); return new GridSecurityContext(s); }
/** {@inheritDoc} */ @Override public GridNode mapPartitionToNode(int part) { A.ensure(part >= 0 && part < partitions(), "part >= 0 && part < total partitions"); return F.first(cctx.affinity().nodes(part, topologyVersion())); }
/** {@inheritDoc} */ @Override public void isolated(boolean isolated) throws GridException { if (isolated()) return; GridNode node = F.first(ctx.grid().forCache(cacheName).nodes()); if (node == null) throw new GridException("Failed to get node for cache: " + cacheName); GridCacheAttributes a = U.cacheAttributes(node, cacheName); assert a != null; updater = a.atomicityMode() == GridCacheAtomicityMode.ATOMIC ? GridDataLoadCacheUpdaters.<K, V>batched() : GridDataLoadCacheUpdaters.<K, V>groupLocked(); }