org.apache.ignite.internal.util.typedef.F.addIfAbsent()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.apache.ignite.internal.util.typedef.F.addIfAbsent()方法的一些代码示例,展示了F.addIfAbsent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。F.addIfAbsent()方法的具体详情如下:
包路径:org.apache.ignite.internal.util.typedef.F
类名称:F
方法名:addIfAbsent

F.addIfAbsent介绍

暂无

代码示例

代码示例来源:origin: apache/ignite

/**
 * @param msgCls Message class.
 * @param lsnr Custom event listener.
 */
public <T extends DiscoveryCustomMessage> void setCustomEventListener(Class<T> msgCls, CustomEventListener<T> lsnr) {
  List<CustomEventListener<DiscoveryCustomMessage>> list = customEvtLsnrs.get(msgCls);
  if (list == null) {
    list = F.addIfAbsent(customEvtLsnrs, msgCls,
      new CopyOnWriteArrayList<CustomEventListener<DiscoveryCustomMessage>>());
  }
  list.add((CustomEventListener<DiscoveryCustomMessage>)lsnr);
}

代码示例来源:origin: apache/ignite

/**
 * Collects statistics for message received by SPI.
 *
 * @param msg Received message.
 * @param nodeId Sender node id.
 */
private void onMessageReceived(Message msg, UUID nodeId) {
  rcvdMsgsCnt++;
  LongHolder cntByType = F.addIfAbsent(rcvdMsgsCntByType, msg.directType(), HOLDER_FACTORY);
  LongHolder cntByNode = F.addIfAbsent(rcvdMsgsCntByNode, nodeId, HOLDER_FACTORY);
  assert cntByType != null;
  assert cntByNode != null;
  cntByType.increment();
  cntByNode.increment();
}

代码示例来源:origin: apache/ignite

/**
 * Collects statistics for message sent by SPI.
 *
 * @param msg Sent message.
 * @param nodeId Receiver node id.
 */
private void onMessageSent(Message msg, UUID nodeId) {
  sentMsgsCnt++;
  LongHolder cntByType = F.addIfAbsent(sentMsgsCntByType, msg.directType(), HOLDER_FACTORY);
  LongHolder cntByNode = F.addIfAbsent(sentMsgsCntByNode, nodeId, HOLDER_FACTORY);
  assert cntByType != null;
  assert cntByNode != null;
  cntByType.increment();
  cntByNode.increment();
}

代码示例来源:origin: apache/ignite

/**
 * Initializes local state for given job metadata.
 *
 * @param jobId Job ID.
 * @return Local state.
 */
private JobLocalState initState(HadoopJobId jobId) {
  return F.addIfAbsent(activeJobs, jobId, new JobLocalState());
}

代码示例来源:origin: apache/ignite

/**
 * 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);
}

代码示例来源:origin: apache/ignite

/**
 * @param avgTimes Average times.
 * @param maxTimes Max times.
 * @param msg Message.
 * @param cnt Total message count.
 * @param time Time.
 */
private void addTimeInfo(Map<String, Long> avgTimes,
  Map<String, Long> maxTimes,
  TcpDiscoveryAbstractMessage msg,
  int cnt,
  long time) {
  Long avgTime = F.addIfAbsent(avgTimes, msg.getClass().getSimpleName(), new Callable<Long>() {
    @Override public Long call() {
      return 0L;
    }
  });
  assert avgTime != null;
  avgTime = (avgTime * (cnt - 1) + time) / cnt;
  avgTimes.put(msg.getClass().getSimpleName(), avgTime);
  Long maxTime = F.addIfAbsent(maxTimes, msg.getClass().getSimpleName(), new Callable<Long>() {
    @Override public Long call() {
      return 0L;
    }
  });
  assert maxTime != null;
  if (time > maxTime)
    maxTimes.put(msg.getClass().getSimpleName(), time);
}

代码示例来源:origin: apache/ignite

/**
 * 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);
}

代码示例来源:origin: apache/ignite

/**
 * 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);
}

代码示例来源:origin: apache/ignite

/**
 * Collects necessary stats for message received by SPI.
 *
 * @param msg Received message.
 */
public synchronized void onMessageReceived(TcpDiscoveryAbstractMessage 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());
}

代码示例来源:origin: apache/ignite

/**
 * @param dep Deployment.
 * @param cls Class.
 * @return Descriptor.
 */
ClassDescriptor descriptor(@Nullable GridDeployment dep, Class<?> cls) {
  Map<Class<?>, ClassDescriptor> newMap, oldMap;
  ClassDescriptor res, newDesc = null;
  do {
    oldMap = clsDescs.get();
    if (oldMap != null && (res = oldMap.get(cls)) != null)
      break;
    if (dep != null) {
      Set<Class<?>> classes = F.addIfAbsent(taskMap, dep.classLoader(), F.<Class<?>>newCSet());
      classes.add(cls);
      dep = null;
    }
    if (oldMap == null)
      newMap = new HashMap<>();
    else
      (newMap = new HashMap<>(oldMap.size() + 1)).putAll(oldMap);
    newMap.put(cls, res = newDesc == null ? (newDesc = new ClassDescriptor(cls)) : newDesc);
  }
  while (!clsDescs.compareAndSet(oldMap, newMap));
  return res;
}

代码示例来源:origin: apache/ignite

/**
 * Called by coordinator when ring message is sent.
 *  @param msg Sent message.
 * @param time Time taken to serialize message.
 */
public synchronized void onMessageSent(TcpDiscoveryAbstractMessage msg, long time) {
  assert msg != null;
  assert time >= 0 : time;
  if (crdSinceTs.get() > 0 &&
    (msg instanceof TcpDiscoveryCustomEventMessage) ||
    (msg instanceof TcpDiscoveryNodeAddedMessage) ||
    (msg instanceof TcpDiscoveryNodeAddFinishedMessage) ||
    (msg instanceof TcpDiscoveryNodeLeftMessage) ||
    (msg instanceof TcpDiscoveryNodeFailedMessage)) {
    ringMsgsSndTs.put(msg.id(), U.currentTimeMillis());
    ringMsgsSent++;
  }
  Integer cnt = F.addIfAbsent(sentMsgs, msg.getClass().getSimpleName(), new Callable<Integer>() {
    @Override public Integer call() {
      return 0;
    }
  });
  assert cnt != null;
  sentMsgs.put(msg.getClass().getSimpleName(), ++cnt);
  addTimeInfo(avgMsgsSndTimes, maxMsgsSndTimes, msg, cnt, time);
  addTimeInfo(avgMsgsAckTimes, maxMsgsAckTimes, msg, cnt, time);
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public void addLocalEventListener(GridLocalEventListener lsnr, int... types) {
  Set<Integer> typeSet = F.addIfAbsent(evtLsnrs, lsnr, F.<Integer>newSet());
  assert typeSet != null;
  if (types != null) {
    for (int type : types)
      typeSet.add(type);
  }
}

代码示例来源:origin: apache/ignite

/**
 * Collects necessary stats for message processed by SPI.
 *
 * @param msg Processed message.
 */
public synchronized void onMessageProcessingStarted(TcpDiscoveryAbstractMessage 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;
    int totalProcMsgs = totalProcessedMessages();
    if (totalProcMsgs != 0)
      avgMsgQueueTime = (avgMsgQueueTime * (totalProcMsgs - 1)) / totalProcMsgs;
  }
  msgsProcStartTs.put(msg.id(), U.currentTimeMillis());
}

代码示例来源:origin: apache/ignite

/**
 * Makes specifications.
 *
 * @param hosts Host configurations.
 * @param dflts Default values.
 * @return Specification grouped by hosts.
 * @throws IgniteCheckedException In case of error.
 */
@SuppressWarnings("ConstantConditions")
public static Map<String, Collection<IgniteRemoteStartSpecification>> specifications(
  Collection<Map<String, Object>> hosts, @Nullable Map<String, Object> dflts)
  throws IgniteCheckedException {
  Map<String, Collection<IgniteRemoteStartSpecification>> specsMap = U.newHashMap(hosts.size());
  IgniteRemoteStartSpecification dfltSpec = processDefaults(dflts);
  for (Map<String, Object> host : hosts) {
    Collection<IgniteRemoteStartSpecification> specs = processHost(host, dfltSpec);
    for (IgniteRemoteStartSpecification spec : specs)
      F.addIfAbsent(specsMap, spec.host(), new Callable<Collection<IgniteRemoteStartSpecification>>() {
        @Override public Collection<IgniteRemoteStartSpecification> call() throws Exception {
          return new HashSet<>();
        }
      }).add(spec);
  }
  return specsMap;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public int pages(int grpId, int partId) throws IgniteCheckedException {
  long root = PageIdUtils.pageId(partId, (byte)0, 0);
  FullPageId fullId = new FullPageId(root, grpId);
  AtomicInteger allocator = allocators.get(fullId);
  if (allocator == null)
    allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(2));
  return allocator.get();
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure)
    throws IgniteSpiException {
    if (msg instanceof GridIoMessage) {
      GridIoMessage ioMsg = (GridIoMessage)msg;
      Class<?> cls = ioMsg.message().getClass();
      AtomicInteger cntr = msgCntMap.get(cls);
      if (cntr == null)
        cntr = F.addIfAbsent(msgCntMap, cls, new AtomicInteger());
      cntr.incrementAndGet();
    }
    super.sendMessage(node, msg, ackClosure);
  }
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public long allocatePage(int grpId, int partId, byte flags) throws IgniteCheckedException {
  long root = PageIdUtils.pageId(partId, flags, 0);
  FullPageId fullId = new FullPageId(root, grpId);
  AtomicInteger allocator = allocators.get(fullId);
  if (allocator == null)
    allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(1));
  return PageIdUtils.pageId(partId, flags, allocator.getAndIncrement());
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public boolean apply(Event evt) {
  DiscoveryEvent discoEvt = (DiscoveryEvent)evt;
  Integer cnt = F.addIfAbsent(metricsRcvdCnt, discoEvt.eventNode().id(), 0);
  assert cnt != null;
  if (cnt < 2) {
    latch.countDown();
    metricsRcvdCnt.put(discoEvt.eventNode().id(), ++cnt);
  }
  return true;
}

代码示例来源:origin: apache/ignite

/**
 * 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.
 */
@Nullable public IgniteInternalFuture<AffinityTopologyVersion> readyFuture(AffinityTopologyVersion topVer) {
  GridAffinityAssignmentV2 aff = head.get();
  if (aff.topologyVersion().compareTo(topVer) >= 0) {
    if (log.isDebugEnabled())
      log.debug("Returning finished future for readyFuture [head=" + aff.topologyVersion() +
        ", topVer=" + topVer + ']');
    return null;
  }
  GridFutureAdapter<AffinityTopologyVersion> fut = F.addIfAbsent(readyFuts, topVer,
    new AffinityReadyFuture(topVer));
  aff = head.get();
  if (aff.topologyVersion().compareTo(topVer) >= 0) {
    if (log.isDebugEnabled())
      log.debug("Completing topology ready future right away [head=" + aff.topologyVersion() +
        ", topVer=" + topVer + ']');
    fut.onDone(aff.topologyVersion());
  }
  else if (stopErr != null)
    fut.onDone(stopErr);
  return fut;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public boolean apply(Event evt) {
  assert evt instanceof CacheEvent;
  if (!listen)
    return true;
  if (TEST_INFO)
    X.println("Cache event: " + evt.shortDisplay());
  AtomicInteger cntr = F.addIfAbsent(cntrs, evt.type(), F.newAtomicInt());
  assert cntr != null;
  int cnt = cntr.incrementAndGet();
  for (EventTypeFuture f : futs)
    f.onEvent(evt.type(), cnt);
  return true;
}

相关文章