/** {@inheritDoc} */ @Override public V addIfAbsent(K key, V val) { return F.addIfAbsent(this, key, val); }
/** * Add information about key, tx result and version to response. * * @param key Key. * @param lock Lock. */ void addCandidate(K key, GridCacheDgcBadLock lock) { Collection<GridCacheDgcBadLock> col = F.addIfAbsent(map, key, new ArrayList<GridCacheDgcBadLock>()); assert col != null; col.add(lock); }
/** {@inheritDoc} */ @Nullable @Override public V addIfAbsent(K key, @Nullable Callable<V> dflt) { return F.addIfAbsent(this, key, dflt); }
/** * Add information about key and version to request. * <p> * Other version has to be provided if suspect lock is DHT local. * * @param key Key. * @param cand Candidate. */ @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) void addCandidate(K key, GridCacheDgcLockCandidate cand) { Collection<GridCacheDgcLockCandidate> col = F.addIfAbsent(map, key, new ArrayList<GridCacheDgcLockCandidate>()); assert col != null; col.add(cand); }
/** * 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); }
/** * Caches list of methods with given annotation from given class. * * @param cls Class the fields belong to. * @param annCls Annotation class for the fields. * @param mtds Methods to cache. */ private void cacheMethods(Class<?> cls, Class<? extends Annotation> annCls, Collection<Method> mtds) { assert cls != null; assert annCls != null; assert mtds != null; Map<Class<? extends Annotation>, Collection<Method>> annMtds = F.addIfAbsent(mtdCache, cls, F.<Class<? extends Annotation>, Collection<Method>>newCMap()); assert annMtds != null; annMtds.put(annCls, mtds); }
/** * Collects necessary stats for message received by SPI. * * @param msg Received message. */ public synchronized void onMessageReceived(GridTcpDiscoveryAbstractMessage msg) { assert msg != null; Integer cnt = F.addIfAbsent(rcvdMsgs, msg.getClass().getSimpleName(), new Callable<Integer>() { @Override public Integer call() { return 0; } }); assert cnt != null; rcvdMsgs.put(msg.getClass().getSimpleName(), ++cnt); msgsRcvTs.put(msg.id(), U.currentTimeMillis()); }
/** * Write request will be asynchronously executed on node with given ID. * * @param nodeId Node ID. * @param batchId Assigned batch ID. */ private void onWriteRequest(UUID nodeId, long batchId) { if (!isDone()) { Set<Long> reqIds = pendingAcks.get(nodeId); if (reqIds == null) reqIds = F.addIfAbsent(pendingAcks, nodeId, new GridConcurrentHashSet<Long>()); reqIds.add(batchId); } }
/** * Caches list of fields with given annotation from given class. * * @param cls Class the fields belong to. * @param dep Deployment. * @param annCls Annotation class for the fields. * @param fields Fields to cache. */ private void cacheFields(@Nullable GridDeployment dep, Class<?> cls, Class<? extends Annotation> annCls, List<GridResourceField> fields) { if (dep != null) { Set<Class<?>> classes = F.addIfAbsent(taskMap, dep.classLoader(), F.<Class<?>>newCSet()); assert classes != null; classes.add(cls); } Map<Class<? extends Annotation>, List<GridResourceField>> rsrcFields = F.addIfAbsent(fieldCache, cls, F.<Class<? extends Annotation>, List<GridResourceField>>newCMap()); assert rsrcFields != null; rsrcFields.put(annCls, fields); }
/** * Callback invoked before finish request is sent to remote node. * * @param nodeId Node ID request being sent to. * @param threadId Thread ID started transaction. */ public void onFinishSend(UUID nodeId, long threadId) { ThreadFinishSync threadSync = threadMap.get(threadId); if (threadSync == null) threadSync = F.addIfAbsent(threadMap, threadId, new ThreadFinishSync(threadId)); threadSync.onSend(nodeId); }
/** * Write request will be asynchronously executed on node with given ID. * * @param nodeId Node ID. * @param batchId Assigned batch ID. */ private void onWriteRequest(UUID nodeId, long batchId) { if (!isDone()) { Set<Long> reqIds = pendingAcks.get(nodeId); if (reqIds == null) reqIds = F.addIfAbsent(pendingAcks, nodeId, new GridConcurrentHashSet<Long>()); reqIds.add(batchId); } }
/** * 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); }
/** * Caches list of methods with given annotation from given class. * * @param rsrcCls Class the fields belong to. * @param dep Deployment. * @param annCls Annotation class for the fields. * @param mtds Methods to cache. */ private void cacheMethods(@Nullable GridDeployment dep, Class<?> rsrcCls, Class<? extends Annotation> annCls, List<GridResourceMethod> mtds) { if (dep != null) { Set<Class<?>> classes = F.addIfAbsent(taskMap, dep.classLoader(), F.<Class<?>>newCSet()); assert classes != null; classes.add(rsrcCls); } Map<Class<? extends Annotation>, List<GridResourceMethod>> rsrcMtds = F.addIfAbsent(mtdCache, rsrcCls, F.<Class<? extends Annotation>, List<GridResourceMethod>>newCMap()); assert rsrcMtds != null; rsrcMtds.put(annCls, mtds); }
/** * Checks if annotation is presented on a field or method of the specified object. * * @param target Target object. * @param annCls Annotation class to find on fields or methods of target object. * @param dep Deployment. * @return {@code true} if annotation is presented, {@code false} if it's not. */ boolean isAnnotationPresent(Object target, Class<? extends Annotation> annCls, @Nullable GridDeployment dep) { assert target != null; assert annCls != null; Class<?> targetCls = target.getClass(); Set<Class<?>> skipClss = skipCache.get(annCls); if (skipClss != null && skipClss.contains(targetCls)) return false; List<GridResourceField> fields = getFieldsWithAnnotation(dep, targetCls, annCls); if (!fields.isEmpty()) return true; List<GridResourceMethod> mtds = getMethodsWithAnnotation(dep, targetCls, annCls); if (mtds.isEmpty()) { if (skipClss == null) skipClss = F.addIfAbsent(skipCache, annCls, F.<Class<?>>newCSet()); skipClss.add(targetCls); return false; } return true; }
/** * Makes specifications. * * @param hosts Host configurations. * @param dflts Default values. * @return Specification grouped by hosts. * @throws GridException In case of error. */ public static Map<String, Collection<GridRemoteStartSpecification>> specifications( Collection<Map<String, Object>> hosts, @Nullable Map<String, Object> dflts) throws GridException { Map<String, Collection<GridRemoteStartSpecification>> specsMap = U.newHashMap(hosts.size()); GridRemoteStartSpecification dfltSpec = processDefaults(dflts); for (Map<String, Object> host : hosts) { Collection<GridRemoteStartSpecification> specs = processHost(host, dfltSpec); for (GridRemoteStartSpecification spec : specs) F.addIfAbsent(specsMap, spec.host(), new Callable<Collection<GridRemoteStartSpecification>>() { @Override public Collection<GridRemoteStartSpecification> call() throws Exception { return new HashSet<>(); } }).add(spec); } return specsMap; }
/** * Collects necessary stats for message processed by SPI. * * @param msg Processed message. */ public synchronized void onMessageProcessingStarted(GridTcpDiscoveryAbstractMessage msg) { assert msg != null; Integer cnt = F.addIfAbsent(procMsgs, msg.getClass().getSimpleName(), new Callable<Integer>() { @Override public Integer call() { return 0; } }); assert cnt != null; procMsgs.put(msg.getClass().getSimpleName(), ++cnt); Long rcvdTs = msgsRcvTs.remove(msg.id()); if (rcvdTs != null) { long duration = U.currentTimeMillis() - rcvdTs; if (maxMsgQueueTime < duration) maxMsgQueueTime = duration; avgMsgQueueTime = (avgMsgQueueTime * (totalReceivedMessages() -1)) / totalProcessedMessages(); } msgsProcStartTs.put(msg.id(), U.currentTimeMillis()); }
/** * Gets neighbors for a node. * * @param node Node. * @return Neighbors. */ private Collection<UUID> neighbors(final GridNode node) { Collection<UUID> ns = neighbors.get(node.id()); if (ns == null) { Collection<GridNode> nodes = grid.forHost(node).nodes(); ns = F.addIfAbsent(neighbors, node.id(), new ArrayList<>(F.nodeIds(nodes))); } return ns; }
/** * @param maps Mappings. */ void addEntryMapping(@Nullable Collection<GridDistributedTxMapping<K, V>> maps) { if (!F.isEmpty(maps)) { for (GridDistributedTxMapping<K, V> map : maps) { GridNode n = map.node(); GridDistributedTxMapping<K, V> m = mappings.get(n.id()); if (m == null) m = F.addIfAbsent(mappings, n.id(), new GridDistributedTxMapping<K, V>(n)); assert m != null; for (GridCacheTxEntry<K, V> entry : map.entries()) m.add(entry); } if (log.isDebugEnabled()) log.debug("Added mappings to transaction [locId=" + cctx.nodeId() + ", mappings=" + maps + ", tx=" + this + ']'); } }
/** * @param maps Mappings. */ void addEntryMapping(@Nullable Collection<GridDistributedTxMapping<K, V>> maps) { if (!F.isEmpty(maps)) { for (GridDistributedTxMapping<K, V> map : maps) { GridNode n = map.node(); GridDistributedTxMapping<K, V> m = mappings.get(n.id()); if (m == null) m = F.addIfAbsent(mappings, n.id(), new GridDistributedTxMapping<K, V>(n)); assert m != null; for (GridCacheTxEntry<K, V> entry : map.entries()) m.add(entry); } if (log.isDebugEnabled()) log.debug("Added mappings to transaction [locId=" + cctx.nodeId() + ", mappings=" + maps + ", tx=" + this + ']'); } }
/** * Gets future that will be completed after topology with version {@code topVer} is calculated. * * @param topVer Topology version to await for. * @return Future that will be completed after affinity for topology version {@code topVer} is calculated. */ public GridFuture<Long> readyFuture(long topVer) { GridAffinityAssignment aff = head.get(); if (aff.topologyVersion() >= topVer) { if (log.isDebugEnabled()) log.debug("Returning finished future for readyFuture [head=" + aff.topologyVersion() + ", topVer=" + topVer + ']'); return null; } GridFutureAdapter<Long> fut = F.addIfAbsent(readyFuts, topVer, new AffinityReadyFuture(ctx.kernalContext())); aff = head.get(); if (aff.topologyVersion() >= topVer) { if (log.isDebugEnabled()) log.debug("Completing topology ready future right away [head=" + aff.topologyVersion() + ", topVer=" + topVer + ']'); fut.onDone(topVer); } else if (stopping) fut.onDone(new GridException("Failed to wait for topology update, cache (or node) is stopping.")); return fut; }