Example usage for java.util.concurrent ConcurrentHashMap entrySet

List of usage examples for java.util.concurrent ConcurrentHashMap entrySet

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap entrySet.

Prototype

EntrySetView entrySet

To view the source code for java.util.concurrent ConcurrentHashMap entrySet.

Click Source Link

Usage

From source file:com.starit.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * ?DataID/*  ww  w  . java2s  .  co  m*/
 * 
 * @param localModifySet
 * @return
 */
private String getProbeUpdateString() {
    // ?checkDataID:Group:MD5
    StringBuilder probeModifyBuilder = new StringBuilder();
    for (Entry<String, ConcurrentHashMap<String, CacheData>> cacheDatasEntry : this.cache.entrySet()) {
        String dataId = cacheDatasEntry.getKey();
        ConcurrentHashMap<String, CacheData> cacheDatas = cacheDatasEntry.getValue();
        if (null == cacheDatas) {
            continue;
        }
        for (Entry<String, CacheData> cacheDataEntry : cacheDatas.entrySet()) {
            final CacheData data = cacheDataEntry.getValue();
            // ???diamond server
            if (!data.isUseLocalConfigInfo()) {
                probeModifyBuilder.append(dataId).append(WORD_SEPARATOR);

                if (null != cacheDataEntry.getValue().getGroup()
                        && Constants.NULL != cacheDataEntry.getValue().getGroup()) {
                    probeModifyBuilder.append(cacheDataEntry.getValue().getGroup()).append(WORD_SEPARATOR);
                } else {
                    probeModifyBuilder.append(WORD_SEPARATOR);
                }

                if (null != cacheDataEntry.getValue().getMd5()
                        && Constants.NULL != cacheDataEntry.getValue().getMd5()) {
                    probeModifyBuilder.append(cacheDataEntry.getValue().getMd5()).append(LINE_SEPARATOR);
                } else {
                    probeModifyBuilder.append(LINE_SEPARATOR);
                }
            }
        }
    }
    String probeModifyString = probeModifyBuilder.toString();
    return probeModifyString;
}

From source file:net.di2e.ecdr.describe.generator.DescribeGeneratorImpl.java

protected Describe createDescribeRecord(String sourceId, Map<String, String> resultProperties) {
    Describe describe = new Describe();
    boolean hasMoreRecords = true;
    Date startDate = StringUtils.isBlank(generatorConfig.getStartDate()) ? null
            : formatter.parseDateTime(generatorConfig.getStartDate()).toDate();
    Date endDate = new Date();
    String queryKeywords = generatorConfig.getKeywords();
    Collection collection = new Collection();
    describe.getCollection().add(collection);

    ContentCollectionType contentCollection = new ContentCollectionType();
    collection.setContentCollection(contentCollection);
    contentCollection.setOriginator(this.generatorConfig.getCollectionOriginator());
    contentCollection// w  w w  . ja va2s  . co  m
            .setClassification(CVEnumISMClassificationAll.fromValue(this.generatorConfig.getClassification()));
    contentCollection.setOwnerProducer(this.generatorConfig.getOwnerProducer());

    ResourceType resource = new ResourceType();
    collection.setResource(resource);

    CompoundResourceIdentifierType identifier = new CompoundResourceIdentifierType();
    identifier.setQualifier("GUIDE");
    identifier.setValue("guide://999715/" + UUID.randomUUID());
    resource.getIdentifier().add(identifier);

    TitleType title = new TitleType();
    title.setValue("Describe Record: " + sourceId);
    resource.setTitle(Arrays.asList(new TitleType[] { title }));

    DescriptionType descType = new DescriptionType();
    descType.setValue("Generated CDR Describe record for site \'" + sourceId + "\' - generated by "
            + this.generatorConfig.getCollectionOriginator());
    resource.setDescription(descType);

    LOGGER.debug("Generating Content Colleciton details for site {}", sourceId);
    HashMap<String, TemporalCoverageHolder> timeMap = new HashMap<>();

    Envelope geoEnvelope = new Envelope();

    int maxRecordCount = this.generatorConfig.getMaxRecordsPerPoll();

    ConcurrentHashMap<String, Long> keywordCounter = new ConcurrentHashMap<>();
    ConcurrentHashMap<QualifierValueHolder, Long> sourceCounter = new ConcurrentHashMap<>();
    ConcurrentHashMap<SecurityType, Long> secCounter = new ConcurrentHashMap<>();
    ConcurrentHashMap<CompoundCategoryIdentifierType, Long> categoryCounter = new ConcurrentHashMap<>();
    ConcurrentHashMap<CompoundTypeIdentifierType, Long> typeCounter = new ConcurrentHashMap<>();
    ConcurrentHashMap<String, Long> mimeCounter = new ConcurrentHashMap<>();
    ConcurrentHashMap<String, Long> contentTypeCounter = new ConcurrentHashMap<>();

    try {
        while (hasMoreRecords) {
            QueryImpl query = new QueryImpl(this.getFilter(startDate, endDate, queryKeywords), 1,
                    maxRecordCount, this.getSortBy(), true, 300000L);
            QueryRequestImpl queryRequest = new QueryRequestImpl(query,
                    Arrays.asList(new String[] { sourceId }));
            queryRequest.setProperties(this.requestProperties);
            QueryResponse response = this.framework.query(queryRequest);
            contentCollection.setUpdated(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
            MetricsType metrics = new MetricsType();
            contentCollection.setMetrics(metrics);
            if (metrics.getCount() == 0) {
                metrics.setCount(response.getHits());
            }
            List<Result> results = response.getResults();
            hasMoreRecords = (results.size() == maxRecordCount) && startDate != null;
            LOGGER.debug(
                    "Adding details from query results for {} records from site {} in the Content Collection date range [{} - {}] and keywords[{}]",
                    Integer.valueOf(results.size()), sourceId, startDate, endDate, queryKeywords);

            for (Result result : results) {
                try {
                    Metacard metacard = result.getMetacard();
                    populateTemporalCoverage(timeMap, metacard);

                    populateGeoCoverage(geoEnvelope, metacard);

                    populateContentType(contentTypeCounter, metacard);

                    String metadata = metacard.getMetadata();
                    if (StringUtils.isNotBlank(metadata)) {
                        // Populate MIME Types
                        XPathHelper xpathHelper = new XPathHelper(metadata);
                        populateMIMEType(sourceId, mimeCounter, result, metacard, xpathHelper);
                        // populate source
                        populateSource(sourceId, sourceCounter, result, metacard, xpathHelper);
                        // Populate Keywords
                        populateKeywords(sourceId, keywordCounter, metacard, xpathHelper);
                        // Populate Category
                        populateCategory(sourceId, categoryCounter, metacard, xpathHelper);
                        // Populate Type
                        populateType(sourceId, typeCounter, metacard, xpathHelper);
                        // Populate Security
                        populateSecurityCoverage(sourceId, secCounter, metacard, xpathHelper);
                    }

                    TemporalCoverageHolder tch = (TemporalCoverageHolder) timeMap
                            .get(generatorConfig.getDateType());
                    if (tch != null) {
                        startDate = tch.getEndDate();
                    }
                } catch (Exception e) {
                    LOGGER.error("Error handling result {} ", result.getMetacard().getId(), e);
                }
            }
        }

        if (!geoEnvelope.isNull()) {
            resultProperties.put(RESULT_WKT,
                    (new WKTWriter()).write((new GeometryFactory()).toGeometry(geoEnvelope)));
        }

        List<Entry<String, Long>> keywords = keywordCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxKeywords()).collect(Collectors.toList());

        this.setKeywords(keywords, resource.getSubjectCoverage());
        this.setGeospatialCoverage(resource.getGeospatialCoverage(), geoEnvelope);
        this.setTemporalCoverage(resource.getTemporalCoverage(), timeMap);
        this.setRecordRate(contentCollection.getMetrics(), timeMap);

        List<Entry<String, Long>> contentTypeDetails = contentTypeCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxContentTypes()).collect(Collectors.toList());
        this.setContentTypes(resource, contentTypeDetails);

        List<Entry<String, Long>> mimeTypeDetails = mimeCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxMimeTypes()).collect(Collectors.toList());
        this.setMimeTypes(contentCollection, mimeTypeDetails);

        List<Entry<CompoundCategoryIdentifierType, Long>> categoryDetails = categoryCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxCategories()).collect(Collectors.toList());
        this.setCategoryDetails(resource, categoryDetails);

        List<Entry<CompoundTypeIdentifierType, Long>> typeDetails = typeCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxTypes()).collect(Collectors.toList());
        this.setTypeDetails(resource, typeDetails);

        List<Entry<QualifierValueHolder, Long>> sources = sourceCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxSources()).collect(Collectors.toList());
        this.setSourceTypes(resource, sources);

        List<Entry<SecurityType, Long>> securityDetails = secCounter.entrySet().stream()
                .sorted(Entry.comparingByValue(Comparator.reverseOrder()))
                .limit((long) this.generatorConfig.getMaxSecurity()).collect(Collectors.toList());
        this.setSecurityDetails(contentCollection, securityDetails);
    } catch (Exception arg34) {
        LOGGER.warn("Query failed against source {}", sourceId, arg34);
    }

    return describe;
}