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();
}
Aggregations