Example usage for com.mongodb.client MongoCursor hasNext

List of usage examples for com.mongodb.client MongoCursor hasNext

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor hasNext.

Prototype

@Override
    boolean hasNext();

Source Link

Usage

From source file:org.restcom.stats.core.service.CounterService.java

License:Open Source License

public List<CounterDTO> retrieveSumMetrics(long fromTime, long toTime, String key) {
    List<CounterDTO> counters = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "null").append("totalCount", new Document("$sum", "$count"))));

    //exec query/* w  w  w .j  a  v a 2 s  . c o m*/
    MongoCursor<Document> result = dbm.getCollection(MetricType.COUNTER.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        counters.add(new CounterDTO(toTime, statsDoc.getInteger("totalCount")));
    }

    return counters;
}

From source file:org.restcom.stats.core.service.GaugeService.java

License:Open Source License

public List<GaugeDTO> retrieveMetrics(long fromTime, long toTime, String key) {
    List<GaugeDTO> gauges = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "$timestamp").append("totalCount", new Document("$sum", "$count"))));
    //define order criteria
    params.add(new Document("$sort", new Document("_id", 1)));

    //exec query/*  w ww.  jav  a2s.c  om*/
    MongoCursor<Document> result = dbm.getCollection(MetricType.GAUGE.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        gauges.add(new GaugeDTO(statsDoc.getLong("_id"), statsDoc.getInteger("totalCount")));
    }

    return gauges;
}

From source file:org.restcom.stats.core.service.GaugeService.java

License:Open Source License

public List<GaugeDTO> retrieveSumMetrics(long fromTime, long toTime, String key) {
    List<GaugeDTO> gauges = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "null").append("totalCount", new Document("$sum", "$count"))));

    //exec query/*  w ww  .j a  v a  2s .  c  o m*/
    MongoCursor<Document> result = dbm.getCollection(MetricType.GAUGE.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        gauges.add(new GaugeDTO(toTime, statsDoc.getInteger("totalCount")));
    }

    return gauges;
}

From source file:org.restcom.stats.core.service.HistogramService.java

License:Open Source License

public List<HistogramDTO> retrieveMetrics(long fromTime, long toTime, String key) {
    List<HistogramDTO> histograms = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "$timestamp").append("totalCount", new Document("$sum", "$count"))));
    //define order criteria
    params.add(new Document("$sort", new Document("_id", 1)));

    //exec query/*from  w  w  w . j av a 2  s .com*/
    MongoCursor<Document> result = dbm.getCollection(MetricType.HISTOGRAM.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        histograms.add(new HistogramDTO(statsDoc.getLong("_id"), statsDoc.getInteger("totalCount")));
    }

    return histograms;
}

From source file:org.restcom.stats.core.service.HistogramService.java

License:Open Source License

public List<HistogramDTO> retrieveSumMetrics(long fromTime, long toTime, String key) {
    List<HistogramDTO> histograms = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "null").append("totalCount", new Document("$sum", "$count"))));

    //exec query/* www .ja  va2s  . com*/
    MongoCursor<Document> result = dbm.getCollection(MetricType.HISTOGRAM.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        histograms.add(new HistogramDTO(toTime, statsDoc.getInteger("totalCount")));
    }

    return histograms;
}

From source file:org.restcom.stats.core.service.MeterService.java

License:Open Source License

public List<MeterDTO> retrieveMetrics(long fromTime, long toTime, String key) {
    List<MeterDTO> meters = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "$timestamp").append("totalCount", new Document("$sum", "$count"))));
    //define order criteria
    params.add(new Document("$sort", new Document("_id", 1)));

    //exec query//from  ww  w . j a v  a  2 s.c om
    MongoCursor<Document> result = dbm.getCollection(MetricType.METER.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        meters.add(new MeterDTO(statsDoc.getLong("_id"), statsDoc.getInteger("totalCount")));
    }

    return meters;
}

From source file:org.restcom.stats.core.service.MeterService.java

License:Open Source License

public List<MeterDTO> retrieveSumMetrics(long fromTime, long toTime, String key) {
    List<MeterDTO> meters = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "null").append("totalCount", new Document("$sum", "$count"))));

    //exec query/*w ww .  ja va 2  s.  c  o  m*/
    MongoCursor<Document> result = dbm.getCollection(MetricType.METER.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        meters.add(new MeterDTO(toTime, statsDoc.getInteger("totalCount")));
    }

    return meters;
}

From source file:org.restcom.stats.core.service.MetricEventService.java

License:Open Source License

/**
 * Retrieve metric status from interval timestamps.
 * @param fromTime timestamp from.//  w w w.j  av  a2 s.  co  m
 * @param toTime timestemp to.
 * @param metricType Metric type.
 * @return metric status.
 */
public MetricStatusDTO restrieveStatus(long fromTime, long toTime, MetricType metricType) {
    MetricStatusDTO status = new MetricStatusDTO();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));

    //define grouping criteria
    params.add(
            new Document("$group", new Document("_id", "status").append("totalEvents", new Document("$sum", 1))
                    .append("lastEvent", new Document("$max", "$timestamp"))));
    //exec query
    MongoCursor<Document> result = dbm.getCollection(metricType.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    if (result.hasNext()) {
        Document statsDoc = result.next();
        status.setTotalEvents(statsDoc.getInteger("totalEvents"));
        status.setTimestamp(new Date(statsDoc.getLong("lastEvent")));
    }

    return status;
}

From source file:org.restcom.stats.core.service.MetricEventService.java

License:Open Source License

/**
 * Retrieve metric keys.//from   ww  w  .j  a v  a2  s  . c o m
 * @param metricType Metric type.
 * @return metric keys.
 */
public List<String> retrieveMetricKeys(MetricType metricType) {
    List<String> keys = new ArrayList<>();

    //retrieve disctinct key values
    MongoCursor<String> result = dbm.getCollection(metricType.getCollectionName()).distinct("key", String.class)
            .iterator();

    while (result.hasNext()) {
        keys.add(result.next());
    }

    return keys;
}

From source file:org.restcom.stats.core.service.TimerService.java

License:Open Source License

public List<TimerDTO> retrieveMetrics(long fromTime, long toTime, String key) {
    List<TimerDTO> timers = new ArrayList<>();

    //create params list
    List<Bson> params = new ArrayList<>();

    //define match criteria
    params.add(new Document("$match", new Document("timestamp", new Document("$gte", fromTime))));
    params.add(new Document("$match", new Document("timestamp", new Document("$lte", toTime))));
    params.add(new Document("$match", new Document("key", key)));

    //define grouping criteria
    params.add(new Document("$group",
            new Document("_id", "$timestamp").append("totalCount", new Document("$sum", "$count"))));
    //define order criteria
    params.add(new Document("$sort", new Document("_id", 1)));

    //exec query// ww  w.  j  a  v a  2s .  c  om
    MongoCursor<Document> result = dbm.getCollection(MetricType.TIMER.getCollectionName()).aggregate(params)
            .iterator();

    //convert document result into dto
    while (result.hasNext()) {
        Document statsDoc = result.next();
        timers.add(new TimerDTO(statsDoc.getLong("_id"), statsDoc.getInteger("totalCount")));
    }

    return timers;
}