/** {@inheritDoc} */ @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof GridBiTuple)) return false; GridBiTuple<?, ?> t = (GridBiTuple<?, ?>)o; // Both nulls or equals. return F.eq(val1, t.val1) && F.eq(val2, t.val2); }
/** * Default constructor. * * @param name - Name of cache data structure. */ public GridCacheInternalKeyImpl(String name) { assert !F.isEmpty(name); this.name = name; }
@Override public GridBiTuple<V, GridCacheVersion> apply(V v) { return F.t(v, ver); } }));
/** * Returns only directly available nodes from given collection. * * @param nodes Nodes. * @return Directly available subset. */ protected static Collection<GridClientNode> selectDirectNodes(Collection<? extends GridClientNode> nodes) { return F.viewReadOnly(nodes, F.<GridClientNode>identity(), CONNECTABLE); } }
/** * @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))); }
/** * Caches list of fields with given annotation from given class. * * @param cls Class the fields belong to. * @param annCls Annotation class for the fields. * @param fields Fields to cache. */ private void cacheFields(Class<?> cls, Class<? extends Annotation> annCls, Collection<Field> fields) { assert cls != null; assert annCls != null; assert fields != null; Map<Class<? extends Annotation>, Collection<Field>> annFields = F.addIfAbsent(fieldCache, cls, F.<Class<? extends Annotation>, Collection<Field>>newCMap()); assert annFields != null; annFields.put(annCls, fields); }
/** {@inheritDoc} */ @Override public Set<GridCacheFlag> flags() { GridCacheFlag[] forced = cctx.forcedFlags(); if (F.isEmpty(forced)) return flags; // We don't expect too many flags, so default size is fine. Set<GridCacheFlag> ret = new HashSet<>(); ret.addAll(flags); ret.addAll(F.asList(forced)); return Collections.unmodifiableSet(ret); }
/** * Resolves coordinator. Nodes that are leaving or failed (but are still in * topology) are removed from search as well as provided filter. * * @param filter Nodes to exclude when resolving coordinator (optional). * @return Coordinator node or {@code null} if there are no coordinator * (i.e. local node is the last one and is currently stopping). */ @Nullable private GridTcpDiscoveryNode resolveCoordinator( @Nullable Collection<GridTcpDiscoveryNode> filter) { synchronized (mux) { Collection<GridTcpDiscoveryNode> excluded = F.concat(false, failedNodes, leavingNodes); if (!F.isEmpty(filter)) excluded = F.concat(false, excluded, filter); return ring.coordinator(excluded); } }
/** * Gets metrics map. * * @return Metrics map. */ public Map<UUID, GridNodeMetrics> metrics() { return F.viewReadOnly(metrics, new C1<byte[], GridNodeMetrics>() { @Override public GridNodeMetrics apply(byte[] metricsBytes) { return GridDiscoveryMetricsHelper.deserialize(metricsBytes, 0); } }); }
/** * 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 Collection<? extends GridNode> nodes() { return F.view(F.viewReadOnly(mappings.keySet(), U.id2Node(cctx.kernalContext())), F.notNull()); }
/** {@inheritDoc} */ @Override public Collection<String> getCacheNames() { Collection<String> names = F.view(super.getCacheNames(), new GridPredicate<String>() { @Override public boolean apply(String name) { return !F.eq(name, dataCacheName); } }); return F.concat(false, names, F.transform(metaCache.entrySetx(), new GridClosure<Map.Entry<MetaKey, Cache>, String>() { @Override public String apply(Map.Entry<MetaKey, Cache> e) { return e.getKey().name; } })); }
/** * 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; }
/** {@inheritDoc} */ @Override public V addIfAbsent(K key, V val) { return F.addIfAbsent(this, key, val); }
/** * Stop watching execution started previously in the same thread. */ public void stopWatching() { String name = startTime.get().get1(); long time = startTime.get().get2(); AtomicInteger cnt = F.addIfAbsent(cntMap, name, F.newAtomicInt()); assert cnt != null; cnt.incrementAndGet(); AtomicLong d = F.addIfAbsent(durationMap, name, F.newAtomicLong()); assert d != null; d.addAndGet(U.currentTimeMillis() - time); }
/** * Register local classes. * * @param objs Objects to register. * @throws GridException If registration failed. */ public void registerClasses(Object... objs) throws GridException { registerClasses(F.asList(objs)); }
/** * * @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; }
/** * @return Iterator over all entries. */ public Iterator<Map.Entry<GridSwapKey, byte[]>> entriesIterator() { final Iterator<ConcurrentMap<GridSwapKey, SwapValue>> iter = parts.values().iterator(); return transform(F.concat(new Iterator<Iterator<Map.Entry<GridSwapKey, SwapValue>>>() { @Override public boolean hasNext() { return iter.hasNext(); } @Override public Iterator<Map.Entry<GridSwapKey, SwapValue>> next() { return iter.next().entrySet().iterator(); } @Override public void remove() { throw new UnsupportedOperationException(); } })); }