![JAR search and dependency download from the Maven repository](/logo.png)
org.terracotta.management.registry.DefaultStatisticQuery Maven / Gradle / Ivy
The newest version!
/*
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terracotta.management.registry;
import org.terracotta.management.model.context.Context;
import org.terracotta.management.model.stats.ContextualStatistics;
import org.terracotta.management.model.stats.Statistic;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
/**
* @author Mathieu Carbou
*/
public class DefaultStatisticQuery implements StatisticQuery {
private final CapabilityManagementSupport capabilityManagement;
private final String capabilityName;
private final Collection statisticNames;
private final Collection contexts;
private final long since;
public DefaultStatisticQuery(CapabilityManagementSupport capabilityManagement, String capabilityName, Collection statisticNames, Collection contexts, long since) {
this.capabilityManagement = capabilityManagement;
this.capabilityName = capabilityName;
this.statisticNames = Collections.unmodifiableSet(new LinkedHashSet(statisticNames));
this.since = since;
this.contexts = Collections.unmodifiableCollection(new ArrayList(contexts));
}
@Override
public String getCapabilityName() {
return capabilityName;
}
@Override
public Collection getContexts() {
return contexts;
}
@Override
public Collection getStatisticNames() {
return statisticNames;
}
@Override
public long getSince() {
return since;
}
@Override
public ResultSet execute() {
Map contextualStatistics = new LinkedHashMap(contexts.size());
Collection> managementProviders = capabilityManagement.getManagementProvidersByCapability(capabilityName);
for (Context context : contexts) {
Map> statistics = new HashMap>();
for (ManagementProvider> managementProvider : managementProviders) {
if (managementProvider.supports(context)) {
statistics.putAll(managementProvider.collectStatistics(context, statisticNames, since));
}
}
contextualStatistics.put(context, new ContextualStatistics(capabilityName, context, statistics));
}
return new DefaultResultSet(contextualStatistics);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy