Search in sources :

Example 6 with ComputationResult

use of org.graylog2.plugin.dashboards.widgets.ComputationResult in project graylog2-server by Graylog2.

the class WidgetResultCache method getComputationResultForDashboardWidget.

public ComputationResult getComputationResultForDashboardWidget(final DashboardWidget dashboardWidget) throws InvalidWidgetConfigurationException {
    final String widgetId = dashboardWidget.getId();
    if (!this.cache.containsKey(widgetId)) {
        final WidgetStrategy widgetStrategy = this.widgetStrategyFactory.getWidgetForType(dashboardWidget.getType(), dashboardWidget.getConfig(), dashboardWidget.getTimeRange(), widgetId);
        final Supplier<ComputationResult> supplier = this.cache.putIfAbsent(widgetId, Suppliers.memoizeWithExpiration(new ComputationResultSupplier(metricRegistry, dashboardWidget, widgetStrategy), dashboardWidget.getCacheTime(), TimeUnit.SECONDS));
        if (supplier == null) {
            // Only increment the counter if there has been no value for the widget ID before.
            counter.inc();
        }
    }
    return this.cache.get(widgetId).get();
}
Also used : ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult) WidgetStrategy(org.graylog2.plugin.dashboards.widgets.WidgetStrategy)

Aggregations

ComputationResult (org.graylog2.plugin.dashboards.widgets.ComputationResult)6 DateTime (org.joda.time.DateTime)3 HistogramResult (org.graylog2.indexer.results.HistogramResult)2 Searches (org.graylog2.indexer.searches.Searches)2 RelativeRange (org.graylog2.plugin.indexer.searches.timeranges.RelativeRange)2 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CountResult (org.graylog2.indexer.results.CountResult)1 FieldStatsResult (org.graylog2.indexer.results.FieldStatsResult)1 TermsResult (org.graylog2.indexer.results.TermsResult)1 WidgetStrategy (org.graylog2.plugin.dashboards.widgets.WidgetStrategy)1 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)1