1 16 package net.sf.dozer.util.mapping.jmx; 17 18 import java.util.Iterator ; 19 import java.util.Set ; 20 import java.util.TreeSet ; 21 22 import net.sf.dozer.util.mapping.config.GlobalSettings; 23 import net.sf.dozer.util.mapping.config.Settings; 24 import net.sf.dozer.util.mapping.stats.GlobalStatistics; 25 import net.sf.dozer.util.mapping.stats.StatisticEntry; 26 import net.sf.dozer.util.mapping.stats.StatisticTypeConstants; 27 import net.sf.dozer.util.mapping.stats.StatisticsManagerIF; 28 29 30 33 public class DozerStatisticsController implements DozerStatisticsControllerMBean { 34 private final StatisticsManagerIF statsMgr = GlobalStatistics.getInstance().getStatsMgr(); 35 private final Settings globalSettings = GlobalSettings.getInstance().getSettings(); 36 37 public void clearAll() { 38 statsMgr.clearAll(); 39 } 40 41 public boolean isStatisticsEnabled() { 42 return globalSettings.isStatisticsEnabled(); 43 } 44 45 public void setStatisticsEnabled(boolean statisticsEnabled) { 46 globalSettings.setStatisticsEnabled(statisticsEnabled); 47 } 48 49 public long getMappingSuccessCount() { 50 return getStatisticValue(StatisticTypeConstants.MAPPING_SUCCESS_COUNT); 51 } 52 53 public long getMappingFailureCount() { 54 return getStatisticValue(StatisticTypeConstants.MAPPING_FAILURE_COUNT); 55 } 56 57 public long getMapperInstancesCount() { 58 return getStatisticValue(StatisticTypeConstants.MAPPER_INSTANCES_COUNT); 59 } 60 61 public long getMappingOverallTime() { 62 return getStatisticValue(StatisticTypeConstants.MAPPING_TIME); 63 } 64 65 public Set getMappingFailureExceptionTypes() { 66 return getStatisticEntries(StatisticTypeConstants.MAPPING_FAILURE_EX_TYPE_COUNT); 67 } 68 69 public Set getMappingFailureTypes() { 70 return getStatisticEntries(StatisticTypeConstants.MAPPING_FAILURE_TYPE_COUNT); 71 } 72 73 public Set getCacheHitCount() { 74 return getStatisticEntries(StatisticTypeConstants.CACHE_HIT_COUNT); 75 } 76 77 public Set getCacheMissCount() { 78 return getStatisticEntries(StatisticTypeConstants.CACHE_MISS_COUNT); 79 } 80 81 public long getFieldMappingSuccessCount() { 82 return getStatisticValue(StatisticTypeConstants.FIELD_MAPPING_SUCCESS_COUNT); 83 } 84 85 public long getFieldMappingFailureCount() { 86 return getStatisticValue(StatisticTypeConstants.FIELD_MAPPING_FAILURE_COUNT); 87 } 88 89 public long getFieldMappingFailureIgnoredCount() { 90 return getStatisticValue(StatisticTypeConstants.FIELD_MAPPING_FAILURE_IGNORED_COUNT); 91 } 92 93 public Set getStatisticTypes() { 94 return statsMgr.getStatisticTypes(); 95 } 96 97 public double getMappingAverageTime() { 98 double totalTime = getStatisticValue(StatisticTypeConstants.MAPPING_TIME); 99 double totalCount = getStatisticValue(StatisticTypeConstants.MAPPING_SUCCESS_COUNT); 100 return totalTime/totalCount; 101 } 102 103 public Set getStatisticEntries(String statisticType) { 104 Set result = new TreeSet (); 105 if (statsMgr.statisticExists(statisticType)) { 106 Set entries = statsMgr.getStatisticEntries(statisticType); 107 Iterator iter = entries.iterator(); 108 while(iter.hasNext()) { 109 StatisticEntry entry = (StatisticEntry) iter.next(); 110 result.add(entry.getKey().toString() + ":Count " + entry.getValue()); 111 } 112 } 113 return result; 114 } 115 116 public void logStatistics() { 117 statsMgr.logStatistics(); 118 } 119 120 public String dumpStatistics() { 121 return statsMgr.getStatistics().toString(); 122 } 123 124 protected long getStatisticValue(String statisticType) { 125 long result = 0; 126 if(statsMgr.statisticExists(statisticType)) { 127 result = statsMgr.getStatisticValue(statisticType); 128 } 129 return result; 130 } 131 } 132 | Popular Tags |