public Statistic getStatistic(String statName) { return genericStatsDelegate.getStatistic(statName); }
public String[] getStatisticNames() { return genericStatsDelegate.getStatisticNames(); }
public Statistic[] getStatistics() { return genericStatsDelegate.getStatistics(); }
private void populateGetterMap() { // Fix for Bugs 5045435, 6172088 //final Method[] apis = statsInterface.getDeclaredMethods(); //all of these should be PUBLIC. final Method[] m = statsInterface.getMethods(); // exclude methods that belong to the javax.management.j2ee.Stats final Method[] apis = filterStatsMethods(m); final Method[] methods = getGetters(apis); final String[] names = methods2Statistics(methods); assert (names.length == methods.length) : ("Statistic names array is not having same length as that of array of getters"); int i; for (i = 0 ; i < names.length ; i++) { getters.put(names[i], methods[i]); } assert (getters.size() == i) : ("Getters map is incorrect, names.length = " + names.length + " methods.length = " + methods.length); }
/** Constructs a new instance of this class for a given interface and its implementation. * It is mandatory that following contract is satisfied to call this satisfactorily: * <ul> * <li> None of the parameters are null. </li> * <li> Given statsProvider implements the given statsInterface. </li> * <li> Given statsInterface has to extend the @{link Stats} interface. </li> * </ul> * Note that it is expected (though not mandatory) to have a getXXX method that * does not return an instance of {@link Statistic} interface. * @throws NullPointerException if any of the given parameters are null * @throws IllegalArgumentException if the contract is not satisfied by given parameters */ public GenericStatsImpl(Class statsInterface, Object statsProvider) { if (!implementsInterface(statsInterface, statsProvider) || ! extendsStatsInterface(statsInterface)) { throw new IllegalArgumentException("Contract violation: invalid interface-implementation pair"); } this.statsProvider = statsProvider; this.statsInterface = statsInterface; this.getters = new HashMap(); populateGetterMap(); }
public Statistic[] getStatistics() { return ( getStatisticsOneByOne() ); //invokes sequentially }
protected void initialize(String statInterfaceName) { try{ genericStatsDelegate = new GenericStatsImpl(statInterfaceName, this); } catch(ClassNotFoundException cnfEx) { throw new RuntimeException(statInterfaceName + " not found", cnfEx); } }
private Method[] filterStatsMethods(Method[] m) { ArrayList methodList = new ArrayList(); for(int i = 0; i < m.length; i++) { if(! isStatsInterfaceMethod(m[i].getName())) methodList.add(m[i]); } final Method[] methods = new Method[methodList.size()]; return (Method[])methodList.toArray(methods); } }
private Statistic[] getStatisticsOneByOne() { final Iterator iter = getters.keySet().iterator(); final Statistic[] stats = new Statistic[getters.keySet().size()]; int i = 0; while (iter.hasNext()) { final String sn = (String) iter.next(); stats[i++] = this.getStatistic(sn); } assert (stats.length == i); return ( stats ); }