Search in sources :

Example 46 with SortedMap

use of java.util.SortedMap in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandler method getMetricsInternal.

private Map<String, Long> getMetricsInternal() {
    MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
    // Get all counters.
    Map<String, Counter> counters = metricRegistry.getCounters();
    // Only the gauge for pinned files is retrieved here, other gauges are statistics of
    // free/used
    // spaces, those statistics can be gotten via other REST apis.
    String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
    @SuppressWarnings("unchecked") Gauge<Integer> filesPinned = (Gauge<Integer>) MetricsSystem.METRIC_REGISTRY.getGauges().get(filesPinnedProperty);
    // Get values of the counters and gauges and put them into a metrics map.
    SortedMap<String, Long> metrics = new TreeMap<>();
    for (Map.Entry<String, Counter> counter : counters.entrySet()) {
        metrics.put(counter.getKey(), counter.getValue().getCount());
    }
    metrics.put(filesPinnedProperty, filesPinned.getValue().longValue());
    return metrics;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) TreeMap(java.util.TreeMap) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 47 with SortedMap

use of java.util.SortedMap in project alluxio by Alluxio.

the class AlluxioWorkerRestServiceHandler method getMetricsInternal.

private Map<String, Long> getMetricsInternal() {
    MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
    // Get all counters.
    Map<String, Counter> counters = metricRegistry.getCounters();
    // Only the gauge for cached blocks is retrieved here, other gauges are statistics of
    // free/used spaces, those statistics can be gotten via other REST apis.
    String blocksCachedProperty = MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.BLOCKS_CACHED);
    @SuppressWarnings("unchecked") Gauge<Integer> blocksCached = (Gauge<Integer>) metricRegistry.getGauges().get(blocksCachedProperty);
    // Get values of the counters and gauges and put them into a metrics map.
    SortedMap<String, Long> metrics = new TreeMap<>();
    for (Map.Entry<String, Counter> counter : counters.entrySet()) {
        metrics.put(counter.getKey(), counter.getValue().getCount());
    }
    metrics.put(blocksCachedProperty, blocksCached.getValue().longValue());
    return metrics;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) TreeMap(java.util.TreeMap) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 48 with SortedMap

use of java.util.SortedMap in project OpenClinica by OpenClinica.

the class FormBeanUtil method createGroupBeansForNongroupedItems.

/**
     * This method is designed to make it easier to order grouped and nongrouped
     * items on a CRF. This method generates a List of DisplayItemGroupBeans
     * representing the items that are not formally part of a group-type
     * horizontal table (they have a name in the database of 'Ungrouped' ). The
     * DisplayItemGroupBeans are ordered according to the position of the items
     * on the CRF, compared with the CRF items that are in groups. When this
     * List is combined with a List of DisplayItemGroupBeans representing
     * *grouped* items, the combined List can be sorted and displayed in the
     * proper order on a CRF.
     * 
     * @param allItems
     *            A List of the ItemFormMetadataBeans associated with the CRF.
     * @param displayFormBeans
     *            The List of DisplayItemGroupBeans
     * @param sectionId
     *            The section ID associated with the items
     * @param dataSource
     *            The DataSource used to acquire the DAO-related connections
     * @param nullValuesList
     *            The list of any "null values" associated with the items (like
     *            "not applicable")
     * @return An ArrayList of DisplayItemGroupBeans for 'Ungrouped' items.
     */
private List<DisplayItemGroupBean> createGroupBeansForNongroupedItems(List<ItemFormMetadataBean> allItems, List<DisplayItemGroupBean> displayFormBeans, int sectionId, DataSource dataSource, List<String> nullValuesList, EventCRFBean eventCrfBean, ServletContext context) {
    // This will hold the List of placeholder groupBeans for orphaned items
    List<DisplayItemGroupBean> groupBeans = new ArrayList<DisplayItemGroupBean>();
    // Now create a Map that maps the item to the group ordinal
    // (e.g., 1) or 0 (non-group),
    // as a convenient way to position an item on a CRF
    // and associate an item with the ordinal of its group.
    // The inner Map maps the ItemFormMetadataBean to its group ordinal;
    // The Integer index to this Map represents the order of the item on the
    // CRF.
    SortedMap<Integer, Map<ItemFormMetadataBean, Integer>> groupMapping = new TreeMap<Integer, Map<ItemFormMetadataBean, Integer>>();
    Map<ItemFormMetadataBean, Integer> innerMap;
    int counter = 0;
    int tmpOrdinal;
    for (ItemFormMetadataBean imetaBean : allItems) {
        innerMap = new HashMap<ItemFormMetadataBean, Integer>();
        if (isGrouped(imetaBean, displayFormBeans)) {
            tmpOrdinal = getGroupOrdinal(imetaBean, displayFormBeans);
            innerMap.put(imetaBean, tmpOrdinal);
        } else {
            innerMap.put(imetaBean, 0);
        }
        groupMapping.put(++counter, innerMap);
    }
    // The groupMapping Map maps the index position of the item on the CRF
    // form (1,2,3...) to
    // the ItemFormMetadataBean and its associated group ordinal, if it has
    // one
    // If the ordinal is 0, then the associated ItemFormMetadataBean
    // represents an
    // ungrouped or orphaned item
    DisplayItemGroupBean nongroupedBean;
    ItemGroupBean itemGroup = new ItemGroupBean();
    ItemGroupMetadataBean metaBean = new ItemGroupMetadataBean();
    metaBean.setName(UNGROUPED);
    List<DisplayItemBean> items;
    // Now cycle through the groupMapping and create default groups or
    // DisplayItemGroupBeans, in order, for
    // the orphaned items.
    // A DisplayItemGroupBean is only created and stored in the returned
    // List
    // if its contents or associated items are nongrouped.
    // This int tracks the ordinal associated with each grouped item's
    // associated
    // DisplayItemGroupBean
    // as that item is incremented
    int ordinalTracker = 0;
    // This int is set to the latest DisplayItemGroupBean ordinal containing
    // nongrouped beans, so that it can be incremented and used to change
    // the ordinal of any DisplayItemGroupBeans (containing *grouped* items)
    // that follow this bean on the CRF
    // int nonGroupOrdinal=0;
    Map.Entry<Integer, Map<ItemFormMetadataBean, Integer>> entry;
    Map<ItemFormMetadataBean, Integer> beanMap;
    nongroupedBean = new DisplayItemGroupBean();
    ItemFormMetadataBean tempItemMeta;
    int tempOrdinal;
    // a flag indicating that the last item handled was an orphaned one
    // so that if the next item is grouped, that's a signal to store the
    // new itemgroupbean just created for orphaned items in in the
    // itemgroupbean List.
    boolean isOrphaned = false;
    // any of the orphaned items
    for (Iterator<Map.Entry<Integer, Map<ItemFormMetadataBean, Integer>>> iter = groupMapping.entrySet().iterator(); iter.hasNext(); ) {
        entry = iter.next();
        // the ItemFormMetadataBean and any
        beanMap = entry.getValue();
        // group ordinal
        // the
        tempItemMeta = beanMap.keySet().iterator().next();
        // ItemFormMetadataBean
        // If this value is 0, the item is orphaned; if > 0 the item is
        // grouped
        // and doesn't need a new itemgroupbean
        tempOrdinal = beanMap.get(tempItemMeta);
        // ordinalTracker != 0
        if (tempOrdinal == 0) {
            if (ordinalTracker == 0 || !isOrphaned) {
                // initialize a new group for the item
                nongroupedBean = new DisplayItemGroupBean();
                itemGroup = new ItemGroupBean();
                itemGroup.setName(UNGROUPED);
                nongroupedBean.setItemGroupBean(itemGroup);
                // set this flag, so that if the next item is orphaned, then
                // the code can place it in the existing itemgroupbean
                isOrphaned = true;
                ordinalTracker++;
                nongroupedBean.setOrdinal(ordinalTracker);
            // nonGroupOrdinal=nongroupedBean.getOrdinal();
            // nonGroupOrdinal= ordinalTracker;
            }
            // Add the item as a displayitem to the itemgroupbean
            nongroupedBean.getItems().add(getDisplayBeanFromSingleItem(tempItemMeta, sectionId, dataSource, eventCrfBean, nullValuesList, context));
        } else {
            // been created; therefore, store it in the List.
            if (isOrphaned) {
                groupBeans.add(nongroupedBean);
                // We also know that the ordinal has changed, because a
                // nongroupedBean
                // has been created
                ordinalTracker++;
                incrementOrdinal(tempItemMeta, displayFormBeans, ordinalTracker);
            } else {
                ordinalTracker = getGroupOrdinal(tempItemMeta, displayFormBeans);
            }
            isOrphaned = false;
        }
    }
    // is leftover and must be added to the List
    if (isOrphaned) {
        groupBeans.add(nongroupedBean);
    }
    return groupBeans;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 49 with SortedMap

use of java.util.SortedMap in project opennms by OpenNMS.

the class NewtsConverter method injectSamplesToNewts.

private void injectSamplesToNewts(final ResourcePath resourcePath, final String group, final List<? extends AbstractDS> dataSources, final SortedMap<Long, List<Double>> samples) {
    final ResourcePath groupPath = ResourcePath.get(resourcePath, group);
    // Create a resource ID from the resource path
    final String groupId = NewtsUtils.toResourceId(groupPath);
    // Build indexing attributes
    final Map<String, String> attributes = Maps.newHashMap();
    NewtsUtils.addIndicesToAttributes(groupPath, attributes);
    // Create the NewTS resource to insert
    final Resource resource = new Resource(groupId, Optional.of(attributes));
    // Transform the RRD samples into NewTS samples
    List<Sample> batch = new ArrayList<>(this.batchSize);
    for (final Map.Entry<Long, List<Double>> s : samples.entrySet()) {
        for (int i = 0; i < dataSources.size(); i++) {
            final double value = s.getValue().get(i);
            if (Double.isNaN(value)) {
                continue;
            }
            final AbstractDS ds = dataSources.get(i);
            final Timestamp timestamp = Timestamp.fromEpochSeconds(s.getKey());
            try {
                batch.add(toSample(ds, resource, timestamp, value));
            } catch (IllegalArgumentException e) {
                // type i.e. negative for a counter, so we silently skip these
                continue;
            }
            if (batch.size() >= this.batchSize) {
                this.repository.insert(batch, true);
                this.processedSamples.getAndAdd(batch.size());
                batch = new ArrayList<>(this.batchSize);
            }
        }
    }
    if (!batch.isEmpty()) {
        this.repository.insert(batch, true);
        this.processedSamples.getAndAdd(batch.size());
    }
    this.processedMetrics.getAndAdd(dataSources.size());
    LOG.trace("Stats: {} / {}", this.processedMetrics, this.processedSamples);
}
Also used : Sample(org.opennms.newts.api.Sample) Resource(org.opennms.newts.api.Resource) ArrayList(java.util.ArrayList) Timestamp(org.opennms.newts.api.Timestamp) AbstractDS(org.opennms.netmgt.rrd.model.AbstractDS) ResourcePath(org.opennms.netmgt.model.ResourcePath) UnsignedLong(com.google.common.primitives.UnsignedLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 50 with SortedMap

use of java.util.SortedMap in project intellij-plugins by JetBrains.

the class DartCoverageRunner method doLoadCoverageData.

@Nullable
private static ProjectData doLoadCoverageData(@NotNull final File sessionDataFile, @NotNull final DartCoverageSuite coverageSuite) {
    final ProcessHandler coverageProcess = coverageSuite.getCoverageProcess();
    // coverageProcess == null means that we are switching to data gathered earlier
    if (coverageProcess != null) {
        for (int i = 0; i < 100; ++i) {
            ProgressManager.checkCanceled();
            if (coverageProcess.waitFor(100)) {
                break;
            }
        }
        if (!coverageProcess.isProcessTerminated()) {
            coverageProcess.destroyProcess();
            return null;
        }
    }
    final Project project = coverageSuite.getProject();
    final String contextFilePath = coverageSuite.getContextFilePath();
    if (project == null || contextFilePath == null) {
        return null;
    }
    final String contextId = DartAnalysisServerService.getInstance(project).execution_createContext(contextFilePath);
    if (contextId == null) {
        return null;
    }
    final ProjectData projectData = new ProjectData();
    try {
        DartCoverageData data = new Gson().fromJson(new BufferedReader(new FileReader(sessionDataFile)), DartCoverageData.class);
        if (data == null) {
            LOG.warn("Coverage file does not contain valid data.");
            return null;
        }
        for (Map.Entry<String, SortedMap<Integer, Integer>> entry : data.getMergedDartFileCoverageData().entrySet()) {
            ProgressManager.checkCanceled();
            String filePath = getFileForUri(project, contextId, entry.getKey());
            if (filePath == null) {
                // File is not found.
                continue;
            }
            SortedMap<Integer, Integer> lineHits = entry.getValue();
            ClassData classData = projectData.getOrCreateClassData(filePath);
            if (lineHits.size() == 0) {
                classData.setLines(new LineData[1]);
                continue;
            }
            LineData[] lines = new LineData[lineHits.lastKey() + 1];
            for (Map.Entry<Integer, Integer> hit : lineHits.entrySet()) {
                LineData lineData = new LineData(hit.getKey(), null);
                lineData.setHits(hit.getValue());
                lines[hit.getKey()] = lineData;
            }
            classData.setLines(lines);
        }
    } catch (FileNotFoundException | JsonSyntaxException e) {
        LOG.warn(e);
    } finally {
        DartAnalysisServerService.getInstance(project).execution_deleteContext(contextId);
    }
    return projectData;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) Project(com.intellij.openapi.project.Project) LineData(com.intellij.rt.coverage.data.LineData) JsonSyntaxException(com.google.gson.JsonSyntaxException) ClassData(com.intellij.rt.coverage.data.ClassData) SortedMap(java.util.SortedMap) BufferedReader(java.io.BufferedReader) ProcessHandler(com.intellij.execution.process.ProcessHandler) FileReader(java.io.FileReader) Map(java.util.Map) SortedMap(java.util.SortedMap) ProjectData(com.intellij.rt.coverage.data.ProjectData) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SortedMap (java.util.SortedMap)228 Map (java.util.Map)174 TreeMap (java.util.TreeMap)115 HashMap (java.util.HashMap)66 NavigableMap (java.util.NavigableMap)33 ArrayList (java.util.ArrayList)31 Iterator (java.util.Iterator)31 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)21 IOException (java.io.IOException)20 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)14 File (java.io.File)14 Entry (java.util.Map.Entry)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 LinkedHashMap (java.util.LinkedHashMap)11