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:org.si4t.solr.SolrIndexDispatcher.java

public String addBinaries(ConcurrentHashMap<String, BinaryIndexData> binaryAdds,
        SolrClientRequest clientRequest)
        throws IOException, SolrServerException, ParserConfigurationException, SAXException {

    SolrServer server = null;/*from   w  w  w  .  j  a v  a2 s  .  co  m*/

    server = this.getSolrServer(clientRequest);

    if (server == null) {
        throw new SolrServerException("Solr server not instantiated.");
    }
    StringBuilder rsp = new StringBuilder();
    String rspResponse = " path not found";

    for (Map.Entry<String, BinaryIndexData> entry : binaryAdds.entrySet()) {
        BinaryIndexData data = entry.getValue();

        log.debug("Dispatching binary content to Solr.");

        FileStream fs = this.getBinaryInputStream(data);

        if (fs != null) {

            String id = data.getUniqueIndexId();
            log.info("Indexing binary with Id: " + id + ", and URL Path:" + data.getIndexUrl());
            ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");

            up.addContentStream(fs);

            up.setParam("literal.id", id);
            up.setParam("literal.publicationid", data.getPublicationItemId());
            up.setParam("literal.pubdate", "NOW");
            up.setParam("literal.url", data.getIndexUrl().replace(" ", "%20"));

            if (!Utils.StringIsNullOrEmpty(data.getFileSize())) {
                up.setParam("literal.fileSize", data.getFileSize());
            }
            if (!Utils.StringIsNullOrEmpty(data.getFileType())) {
                up.setParam("literal.fileType", data.getFileType());
            }
            up.setParam("defaultField", "binary_content");

            UpdateResponse serverrsp;

            serverrsp = up.process(server);
            rsp.append(serverrsp.getResponse());

            log.info("Committing adding binaries.");
            rsp.append("\n");

            serverrsp = server.commit();
            rsp.append(serverrsp.getResponse());

            rspResponse = rsp.toString();
        } else {
            log.error("Could not process binary: " + data.getIndexUrl());
        }
    }
    return ("Adding binaries had the following response: " + rspResponse);
}

From source file:ddf.catalog.source.opensearch.TestOpenSearchSource.java

/**
 * Verifies that the rest of the entries don't have a corresponding value
 *
 * @param nvpMap//from   ww w  .  j a  va  2 s.  co  m
 */
private void verifyAllEntriesBlank(ConcurrentHashMap<String, String> nvpMap) {
    for (Entry<String, String> entry : nvpMap.entrySet()) {

        String errorMessage = "[" + entry.getKey() + "]" + " should not have a corresponding value.";

        assertThat(errorMessage, entry.getValue(), is(""));
    }
}

From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java

@Override
public void run() {
    Calendar calendar_int = Calendar.getInstance();

    //0-365/*from www  .  j  ava 2  s  .  c om*/
    today_ = calendar_int.get(Calendar.DAY_OF_YEAR);

    ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeTime;

    localVolumeTime = awsAccount_.getVolumeTime_Copy();

    for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) {
        Region region = entry.getKey();
        splitFactorDay_.put(region, 10);
        HashSet<Date> newHashSet = new HashSet<>();
        didMySnapshotDay_.put(entry.getKey(), newHashSet);
    }

    addAlreadyDoneTodaySnapshots(localVolumeTime);

    while (true) {
        try {
            //Reset my stuff
            if (isItTomorrow(today_)) {
                calendar_int = Calendar.getInstance();

                today_ = calendar_int.get(Calendar.DAY_OF_YEAR);
                resetDidMySnapshotDay();

            }

            localVolumeTime = awsAccount_.getVolumeTime_Copy();
            for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) {
                Region region = entry.getKey();

                if (localVolumeTime.get(region).isEmpty()) {
                    continue;
                }

                timeDay_.put(region, extractRunAt(localVolumeTime.get(region)));

            }

            for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) {
                Region region = entry.getKey();

                if (localVolumeTime.get(region).isEmpty()) {
                    continue;
                }

                timeDay_.get(region).keySet().removeAll(didMySnapshotDay_.get(region));
                Calendar calendar = Calendar.getInstance();
                Date now = calendar.getTime();
                now = dayFormat_.parse(dayFormat_.format(now));

                List<Date> lessThanNow = findLessThanNow(timeDay_.get(region).keySet(), now);

                if (!lessThanNow.isEmpty()) {
                    for (Date date : lessThanNow) {
                        ArrayList<Volume> volumes = timeDay_.get(region).get(date);
                        List<List<Volume>> listOfLists = Lists.partition(volumes, splitFactorDay_.get(region));

                        if (localVolumeTimeListDay_.get(region) == null
                                || localVolumeTimeListDay_.get(region).isEmpty()) {
                            localVolumeTimeListDay_.put(region, listsToArrayLists(listOfLists));
                        } else {
                            try {
                                localVolumeTimeListDay_.get(region).add(listsToArrayLists(listOfLists).get(0));
                            } catch (Exception e) {
                            }
                        }

                        ArrayList<SnapshotVolumeTime> threads = new ArrayList<>();

                        for (ArrayList<Volume> vols : listsToArrayLists(listOfLists)) {
                            threads.add(new SnapshotVolumeTime(awsAccount_.getAwsAccessKeyId(),
                                    awsAccount_.getAwsSecretKey(), awsAccount_.getUniqueAwsAccountIdentifier(),
                                    awsAccount_.getMaxApiRequestsPerSecond(),
                                    ApplicationConfiguration.getAwsCallRetryAttempts(), region, vols));

                        }

                        didMySnapshotDay_.get(region).add(date);

                        EideticSubThreads_.put(region, threads);

                    }

                }
            }
            //localVolumeTimeListDay now has hashmaps of regions with keys of arrays of arrays of volumes to take snapshots of.

            HashMap<Region, Integer> secsSlept = new HashMap<>();
            HashMap<Region, Boolean> allDead = new HashMap<>();

            for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) {
                Region region = entry.getKey();

                if (localVolumeTimeListDay_.get(region) == null
                        || localVolumeTimeListDay_.get(region).isEmpty()) {
                    continue;
                }

                //Initializing content
                secsSlept.put(region, 0);

                //Initializing content
                allDead.put(region, false);

                Threads.threadExecutorFixedPool(EideticSubThreads_.get(region), splitFactorDay_.get(region),
                        300, TimeUnit.MINUTES);
            }

            //LETS SEE IF THEY'RE DEAD
            Boolean ejection = false;
            Boolean theyreDead;
            while (true) {
                for (Map.Entry<Region, ArrayList<SnapshotVolumeTime>> entry : EideticSubThreads_.entrySet()) {
                    Region region = entry.getKey();

                    if (areAllThreadsDead(EideticSubThreads_.get(region))) {
                        allDead.put(region, true);
                    } else {
                        secsSlept.replace(region, secsSlept.get(region), secsSlept.get(region) + 1);
                        if (secsSlept.get(region) > 1800) {
                            splitFactorDay_.replace(region, splitFactorDay_.get(region),
                                    splitFactorDay_.get(region) + 1);
                            logger.info(
                                    "Event=\"increasing_splitFactor\", Monitor=\"SnapshotVolumeTime\", splitFactor=\""
                                            + Integer.toString(splitFactorDay_.get(region))
                                            + "\", VolumeTimeSize=\""
                                            + Integer.toString(localVolumeTime.get(region).size()) + "\"");
                            ejection = true;
                            break;
                        }

                    }

                }

                //I dont like this
                theyreDead = true;
                for (Map.Entry<Region, ArrayList<SnapshotVolumeTime>> entry : EideticSubThreads_.entrySet()) {
                    Region region = entry.getKey();

                    //If any of them have false
                    if (!allDead.get(region)) {
                        theyreDead = false;
                    }
                }

                if (ejection || theyreDead) {
                    break;
                }

                Threads.sleepSeconds(1);
            }

            //See if decrease splitfactor
            for (Map.Entry<Region, ArrayList<SnapshotVolumeTime>> entry : EideticSubThreads_.entrySet()) {
                Region region = entry.getKey();

                int timeRemaining = 1800 - secsSlept.get(region);

                if ((splitFactorDay_.get(region) > 5) & (timeRemaining > 60)) {
                    splitFactorDay_.replace(region, splitFactorDay_.get(region),
                            splitFactorDay_.get(region) - 1);
                    logger.info("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier()
                            + "\",Event=\"decreasing_splitFactor\", Monitor=\"SnapshotVolumeNoTime\", splitFactor=\""
                            + Integer.toString(splitFactorDay_.get(region)) + "\", VolumeNoTimeSize=\""
                            + Integer.toString(localVolumeTime.get(region).size()) + "\"");
                }
            }

            localVolumeTimeListDay_.clear();
            EideticSubThreads_.clear();

            Threads.sleepSeconds(30);

        } catch (Exception e) {
            logger.error("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier()
                    + "\",Error=\"MonitorSnapshotVolumeTimeFailure\", stacktrace=\"" + e.toString()
                    + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

}

From source file:com.pearson.eidetic.driver.threads.RefreshAwsAccountVolumes.java

@Override
public void run() {

    ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeNoTime;

    localVolumeNoTime = awsAccount_.getVolumeNoTime_Copy();

    ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeTime;

    localVolumeTime = awsAccount_.getVolumeTime_Copy();

    ConcurrentHashMap<Region, ArrayList<Volume>> localCopyVolumeSnapshots;

    localCopyVolumeSnapshots = awsAccount_.getCopyVolumeSnapshots_Copy();

    JSONParser parser = new JSONParser();

    for (Map.Entry<com.amazonaws.regions.Region, ArrayList<Volume>> entry : localVolumeNoTime.entrySet()) {
        com.amazonaws.regions.Region region = entry.getKey();
        AmazonEC2Client ec2Client = connect(region, awsAccount_.getAwsAccessKeyId(),
                awsAccount_.getAwsSecretKey());

        List<Volume> volumes = initialization(ec2Client, localVolumeNoTime, localVolumeTime,
                localCopyVolumeSnapshots, region);

        for (Volume volume : volumes) {

            JSONObject eideticParameters;
            eideticParameters = getEideticParameters(volume, parser);
            if (eideticParameters == null) {
                continue;
            }//from ww  w . j a  v  a 2  s  .  co  m

            JSONObject createSnapshot;
            createSnapshot = getCreateSnapshot(volume, eideticParameters);
            if (createSnapshot == null) {
                continue;
            }

            HashMap<Integer, ConcurrentHashMap<Region, ArrayList<Volume>>> resultSet;
            resultSet = refreshCreateSnapshotVolumes(volume, createSnapshot, localVolumeTime, localVolumeNoTime,
                    region);
            if (resultSet == null) {
                continue;
            }
            if (resultSet.isEmpty()) {
                continue;
            }

            try {
                localVolumeTime = resultSet.get(0);
                localVolumeNoTime = resultSet.get(1);
            } catch (Exception e) {
                logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                        + "\",Event=\"Error\", Error=\"error getting from resultSet\", Volume_id=\""
                        + volume.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                        + StackTrace.getStringFromStackTrace(e) + "\"");
            }

            //Time for CopyVolumeSnapshots
            //If this volume does not have copysnapshot
            localCopyVolumeSnapshots = refreshCopyVolumeSnapshots(volume, eideticParameters,
                    localCopyVolumeSnapshots, region);

        }

        localVolumeTime = processLocalVolumeTime(localVolumeTime, region);

        localVolumeNoTime = processLocalVolumeNoTime(localVolumeNoTime, region);

        localCopyVolumeSnapshots = processLocalCopyVolumeSnapshots(localCopyVolumeSnapshots, region);

        ec2Client.shutdown();

    }

    awsAccount_.replaceVolumeNoTime(localVolumeNoTime);

    awsAccount_.replaceVolumeTime(localVolumeTime);

    awsAccount_.replaceCopyVolumeSnapshots(localCopyVolumeSnapshots);

}

From source file:com.comcast.cqs.test.stress.CqsStressTester.java

private byte[] generateChart(String title, ConcurrentHashMap<Integer, AtomicInteger> metric, String id,
        Date startTime, Date endTime) throws IOException {

    XYSeries series = new XYSeries(title);

    for (Entry<Integer, AtomicInteger> entry : metric.entrySet()) {
        series.add(entry.getKey().intValue(), entry.getValue().intValue());
    }/*from  w w  w  . j  a v a 2s  .c o m*/

    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart chart = ChartFactory.createXYBarChart(
            "Start: " + startTime + " End: " + endTime + " Message Count: " + messageCount, "Test Second",
            false, "Number of Messages", dataset, PlotOrientation.VERTICAL, true, true, false);

    File file = new File("/tmp/" + id + ".jpeg");
    //File file = new File(getServletContext().getRealPath("WEB-INF" + "/" + id + ".jpeg"));
    ChartUtilities.saveChartAsJPEG(file, chart, 1600, 400);
    //byte b[] = Files.toByteArray(file);
    //return b;

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsJPEG(bos, chart, 2400, 400);
    return bos.toByteArray();
}

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

private void checkSnapshot() {
    for (Entry<String, ConcurrentHashMap<String, CacheData>> cacheDatasEntry : cache.entrySet()) {
        ConcurrentHashMap<String, CacheData> cacheDatas = cacheDatasEntry.getValue();
        if (null == cacheDatas) {
            continue;
        }//from w  w w  .  j  a v  a2s .c om
        for (Entry<String, CacheData> cacheDataEntry : cacheDatas.entrySet()) {
            final CacheData cacheData = cacheDataEntry.getValue();
            // diamond server,snapshot
            if (!cacheData.isUseLocalConfigInfo() && cacheData.getFetchCount() == 0) {
                String configInfo = getSnapshotConfiginfomation(cacheData.getDataId(), cacheData.getGroup());
                if (configInfo != null) {
                    popConfigInfo(cacheData, configInfo);
                }
            }
        }
    }
}

From source file:cn.leancloud.diamond.client.impl.DefaultDiamondSubscriber.java

private void checkSnapshot() {
    for (Entry<String, ConcurrentHashMap<String, CacheData>> cacheDatasEntry : cache.entrySet()) {
        ConcurrentHashMap<String, CacheData> cacheDatas = cacheDatasEntry.getValue();
        if (null == cacheDatas) {
            continue;
        }/*from   w w  w. j  av a 2 s  .  co m*/
        for (Entry<String, CacheData> cacheDataEntry : cacheDatas.entrySet()) {
            final CacheData cacheData = cacheDataEntry.getValue();
            // ??diamond server???,snapshot
            if (!cacheData.isUseLocalConfigInfo() && cacheData.getFetchCount() == 0) {
                String configInfo = getSnapshotConfiginfomation(cacheData.getDataId(), cacheData.getGroup());
                if (configInfo != null) {
                    popConfigInfo(cacheData, configInfo);
                }
            }
        }
    }
}

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

private void checkLocalConfigInfo() {
    for (Entry<String/* dataId */, ConcurrentHashMap<String/* group */, CacheData>> cacheDatasEntry : cache
            .entrySet()) {/*  w  ww.  jav  a  2s .co  m*/
        ConcurrentHashMap<String, CacheData> cacheDatas = cacheDatasEntry.getValue();
        if (null == cacheDatas) {
            continue;
        }
        for (Entry<String, CacheData> cacheDataEntry : cacheDatas.entrySet()) {
            final CacheData cacheData = cacheDataEntry.getValue();
            try {
                String configInfo = getLocalConfigureInfomation(cacheData);
                if (null != configInfo) {
                    if (log.isInfoEnabled()) {
                        log.info(", dataId:" + cacheData.getDataId() + ", group:"
                                + cacheData.getGroup());
                    }
                    popConfigInfo(cacheData, configInfo);
                    continue;
                }
                if (cacheData.isUseLocalConfigInfo()) {
                    continue;
                }
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
}

From source file:cn.leancloud.diamond.client.impl.DefaultDiamondSubscriber.java

private void checkLocalConfigInfo() {
    for (Entry<String/* dataId */, ConcurrentHashMap<String/* group */, CacheData>> cacheDatasEntry : cache
            .entrySet()) {//from  w w  w.j av a 2s . c  o  m
        ConcurrentHashMap<String, CacheData> cacheDatas = cacheDatasEntry.getValue();
        if (null == cacheDatas) {
            continue;
        }
        for (Entry<String, CacheData> cacheDataEntry : cacheDatas.entrySet()) {
            final CacheData cacheData = cacheDataEntry.getValue();
            try {
                String configInfo = getLocalConfigureInfomation(cacheData);
                if (null != configInfo) {
                    if (log.isInfoEnabled()) {
                        log.info("???, dataId:" + cacheData.getDataId() + ", group:"
                                + cacheData.getGroup());
                    }
                    popConfigInfo(cacheData, configInfo);
                    continue;
                }
                if (cacheData.isUseLocalConfigInfo()) {
                    continue;
                }
            } catch (Exception e) {
                log.error("????", e);
            }
        }
    }
}

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

/**
 * DataID//from  w  w  w.  j a  v  a  2 s  .  c  o  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;
}