Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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 net.sf.ehcache.statistics.beans;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.statistics.extended.ExtendedStatistics;
import net.sf.ehcache.statistics.extended.ExtendedStatistics.Operation;
import net.sf.ehcache.statistics.extended.ExtendedStatistics.Result;
import net.sf.ehcache.statistics.extended.ExtendedStatistics.Statistic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terracotta.statistics.ValueStatistic;
import org.terracotta.statistics.archive.Timestamped;
/**
* A dynamically built mbean based on the available statistics for a cache.
*
* @author cschanck
*
*/
public class ExtendedStatisticsMBean extends ProxiedDynamicMBean {
private static final Logger LOGGER = LoggerFactory.getLogger(ExtendedStatisticsMBean.class);
/**
* Instantiates a new extended statistics m bean.
*
* @param cache the cache
* @param extendedStatistics the extended statistics
*/
public ExtendedStatisticsMBean(Ehcache cache, ExtendedStatistics extendedStatistics) {
super(divineName(cache), "Extended statistics for " + divineName(cache), Collections.EMPTY_LIST);
LinkedList proxies = new LinkedList();
processMethods(extendedStatistics, proxies);
initialize(proxies);
}
private void processMethods(ExtendedStatistics extendedStatistics, List proxies) {
for (Method m : ExtendedStatistics.class.getDeclaredMethods()) {
try {
extractAttributes(extendedStatistics, proxies, m);
} catch (IllegalArgumentException e) {
LOGGER.info(e.getMessage());
} catch (IllegalAccessException e) {
LOGGER.info(e.getMessage());
} catch (InvocationTargetException e) {
LOGGER.info(e.getMessage());
}
}
}
private void extractAttributes(ExtendedStatistics extendedStatistics, List proxies, Method m)
throws IllegalAccessException, InvocationTargetException {
if (m.getReturnType().equals(ValueStatistic.class)) {
ValueStatistic stat = (ValueStatistic) m.invoke(extendedStatistics, new Object[0]);
if (stat != null) {
recordValueStatistic(proxies, stat, "cache.", m);
}
} else if (m.getReturnType().equals(ExtendedStatistics.Statistic.class)) {
Statistic stat = (Statistic) m.invoke(extendedStatistics, new Object[0]);
if (stat != null) {
recordStatistic(proxies, stat, "cache.", m);
}
} else if (m.getReturnType().equals(ExtendedStatistics.Result.class)) {
Result res = (Result) m.invoke(extendedStatistics, new Object[0]);
if (res != null) {
recordResult(proxies, res, m.getName());
}
} else if (m.getReturnType().equals(ExtendedStatistics.Operation.class)) {
Operation op = (Operation) m.invoke(extendedStatistics, new Object[0]);
if (op.type() != null && op.type().isEnum() && op.type().getEnumConstants() != null) {
recordOperation(proxies, extendedStatistics, m.getName(), op);
}
}
}
private void recordStatistic(List proxies, final Statistic stat, String prefix, Method m) {
String name = m.getName();
if (name.startsWith("get")) {
name = name.substring("get".length());
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
}
name = prefix + name;
AttributeProxy