Search in sources :

Example 1 with WidgetStrategy

use of org.graylog2.plugin.dashboards.widgets.WidgetStrategy 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)1 WidgetStrategy (org.graylog2.plugin.dashboards.widgets.WidgetStrategy)1