当前位置: 首页>>代码示例>>Java>>正文


Java CopyOnWriteArrayList.size方法代码示例

本文整理汇总了Java中java.util.concurrent.CopyOnWriteArrayList.size方法的典型用法代码示例。如果您正苦于以下问题:Java CopyOnWriteArrayList.size方法的具体用法?Java CopyOnWriteArrayList.size怎么用?Java CopyOnWriteArrayList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.CopyOnWriteArrayList的用法示例。


在下文中一共展示了CopyOnWriteArrayList.size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: finishAndNotifyListener

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
    logger.trace("{}: got all shard responses", actionName);
    int successfulShards = 0;
    int failedShards = 0;
    int totalNumCopies = 0;
    List<ShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.size(); i++) {
        ReplicationResponse shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // non active shard, ignore
        } else {
            failedShards += shardResponse.getShardInfo().getFailed();
            successfulShards += shardResponse.getShardInfo().getSuccessful();
            totalNumCopies += shardResponse.getShardInfo().getTotal();
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            for (ReplicationResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
                shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(failure.fullShardId(), failure.getCause())));
            }
        }
    }
    listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:TransportBroadcastReplicationAction.java

示例2: finishAndNotifyListener

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
    logger.trace("{}: got all shard responses", actionName);
    int successfulShards = 0;
    int failedShards = 0;
    int totalNumCopies = 0;
    List<ShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.size(); i++) {
        ActionWriteResponse shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // non active shard, ignore
        } else {
            failedShards += shardResponse.getShardInfo().getFailed();
            successfulShards += shardResponse.getShardInfo().getSuccessful();
            totalNumCopies += shardResponse.getShardInfo().getTotal();
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            for (ActionWriteResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
                shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(new ShardId(failure.index(), failure.shardId()), failure.getCause())));
            }
        }
    }
    listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:TransportBroadcastReplicationAction.java

示例3: getSuggestions

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
@Override
public ArrayList<SuggestedWordInfo> getSuggestions(final ComposedData composedData,
        final NgramContext ngramContext, final long proximityInfoHandle,
        final SettingsValuesForSuggestion settingsValuesForSuggestion,
        final int sessionId, final float weightForLocale,
        final float[] inOutWeightOfLangModelVsSpatialModel) {
    final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
    if (dictionaries.isEmpty()) return null;
    // To avoid creating unnecessary objects, we get the list out of the first
    // dictionary and add the rest to it if not null, hence the get(0)
    ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composedData,
            ngramContext, proximityInfoHandle, settingsValuesForSuggestion, sessionId,
            weightForLocale, inOutWeightOfLangModelVsSpatialModel);
    if (null == suggestions) suggestions = new ArrayList<>();
    final int length = dictionaries.size();
    for (int i = 1; i < length; ++ i) {
        final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(
                composedData, ngramContext, proximityInfoHandle, settingsValuesForSuggestion,
                sessionId, weightForLocale, inOutWeightOfLangModelVsSpatialModel);
        if (null != sugg) suggestions.addAll(sugg);
    }
    return suggestions;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:24,代码来源:DictionaryCollection.java

示例4: getCharacteristicsChangedListenerCount

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
@Override
public int getCharacteristicsChangedListenerCount(UUID characteristicsUUID) {
    synchronized (lock) {
        CopyOnWriteArrayList<CharacteristicsChangedListener> list = changeListeners.get(characteristicsUUID);
        return list == null ? 0 : list.size();

    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:9,代码来源:Device.java

示例5: removeMethodsFromMap

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
 * remove subscriber methods from map
 */
public void removeMethodsFromMap(Object subscriber) {
    Iterator<CopyOnWriteArrayList<XulSubscription>> iterator =
            _subscriberMap.values().iterator();
    while (iterator.hasNext()) {
        CopyOnWriteArrayList<XulSubscription> subscriptions = iterator.next();
        if (subscriptions != null) {
            List<XulSubscription> foundSubscriptions = new LinkedList<XulSubscription>();
            Iterator<XulSubscription> subIterator = subscriptions.iterator();
            while (subIterator.hasNext()) {
                XulSubscription xulSubscription = subIterator.next();
                // 获取引用
                Object cacheObject = xulSubscription.getSubscriber();
                if ((cacheObject == null)
                    || cacheObject.equals(subscriber)) {
                    xulSubscription.clearXulMessages();
                    foundSubscriptions.add(xulSubscription);
                }
            }

            // 移除该subscriber的相关的Subscription
            subscriptions.removeAll(foundSubscriptions);
        }

        // 如果针对某个Msg的订阅者数量为空了,那么需要从map中清除
        if (subscriptions == null || subscriptions.size() == 0) {
            iterator.remove();
        }
    }
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:33,代码来源:XulSubscriberMethodHunter.java

示例6: getContentByCourse

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
 * Method to get all contents of a given course.
 */
@SuppressWarnings("unchecked")
private Response getContentByCourse(String userId, Map<String, Object> request) {

  Response response = null;
  Util.DbInfo dbInfo = Util.dbInfoMap.get(JsonKey.LEARNER_CONTENT_DB);

  if (request.get(JsonKey.COURSE) != null) {
    Map<String, Object> courseMap = (Map<String, Object>) request.get(JsonKey.COURSE);
    String courseId = (String) courseMap.get(JsonKey.COURSE_ID);
    CopyOnWriteArrayList<String> contentIds =
        new CopyOnWriteArrayList<String>((List<String>) courseMap.get(JsonKey.CONTENT_IDS));
    LinkedHashMap<String, Object> queryMap = new LinkedHashMap<String, Object>();
    queryMap.put(JsonKey.USER_ID, userId);
    queryMap.put(JsonKey.COURSE_ID, courseId);
    response = cassandraOperation.getRecordsByProperties(dbInfo.getKeySpace(),
        dbInfo.getTableName(), queryMap);
    List<Map<String, Object>> modifiedContentList = new ArrayList<Map<String, Object>>();
    List<Map<String, Object>> resultedList =
        (List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE);

    if (null != contentIds && !(contentIds.isEmpty())) {

      for (Map<String, Object> map : resultedList) {
        boolean flag = true;
        for (int i = 0; i < contentIds.size() && flag; i++) {
          String contentId = contentIds.get(i);
          if (contentId.equals((String) map.get(JsonKey.CONTENT_ID))) {
            modifiedContentList.add(map);
            flag = false;
          }
        }
      }
      response.getResult().put(JsonKey.RESPONSE, modifiedContentList);
    }
  }
  return response;
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:41,代码来源:LearnerStateActor.java

示例7: ListAccumulator

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
public ListAccumulator(CopyOnWriteArrayList<Integer> value) {
	if (value.size() != 0) {
		accList = new CopyOnWriteArrayList<Integer>(value);
	}
}
 
开发者ID:PacktPublishing,项目名称:Apache-Spark-2x-for-Java-Developers,代码行数:6,代码来源:ListAccumulator.java

示例8: cronJob

import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
 * 每隔几个小时跑一次任务
 */
@Scheduled(cron="${cronJob.schedule}")
public void cronJob() {

    checkRunningStat();

    log.info("Job Start...");

    ProxyPool.proxyMap = proxyDao.getProxyMap();

    if(Preconditions.isBlank(ProxyPool.proxyMap)) {
        log.info("proxyDao.getProxyMap() is empty");
        ProxyPool.proxyMap = Constant.proxyMap;
    }

    // 每次跑job先清空缓存中的内容
    if (cacheManager.getCache("proxys")!=null) {

        cacheManager.getCache("proxys").clear();
    }

    JobLog jobLog = new JobLog();
    jobLog.setJobName("ScheduleJobs.cronJob");
    jobLog.setStartTime(JodaUtils.formatDateTime(new Date()));

    // 跑任务之前先清空proxyList中的数据
    ProxyPool.proxyList.clear();

    ProxyPool.addProxyList(proxyDao.takeRandomTenProxy());  // 从数据库中选取10个代理作为种子代理,遇到http 503时使用代理来抓数据

    proxyManager.start();

    CopyOnWriteArrayList<Proxy> list = ProxyPool.proxyList;

    if (Preconditions.isNotBlank(list)) {

        // list的数量<=15时,不删除原先的数据
        if (list.size()>15) {

            // 先删除旧的数据
            proxyDao.deleteAll();
            log.info("Job after deleteAll");
        }

        // 然后再进行插入新的proxy
        for (Proxy p:list) {
            proxyDao.saveProxy(p);
            log.info("Job saveProxy = "+p.getProxyStr());
        }

        jobLog.setResultDesc(String.format("成功保存了%s条代理IP数据", list.size()));
        jobLog.setEndTime(JodaUtils.formatDateTime(new Date()));
        commonDao.saveJobLog(jobLog);

    } else {
        log.info("proxyList is empty...");
    }

    stop();

    log.info("Job End...");
}
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:65,代码来源:ScheduleJobs.java


注:本文中的java.util.concurrent.CopyOnWriteArrayList.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。