Coverage Report - org.dozer.jmx.DozerStatisticsController
 
Classes in this File Line Coverage Branch Coverage Complexity
DozerStatisticsController
47%
18/38
50%
1/2
1.043
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.dozer.jmx;
 17  
 
 18  
 import org.dozer.config.GlobalSettings;
 19  
 import org.dozer.stats.GlobalStatistics;
 20  
 import org.dozer.stats.StatisticEntry;
 21  
 import org.dozer.stats.StatisticType;
 22  
 import org.dozer.stats.StatisticsManager;
 23  
 
 24  
 import java.util.Set;
 25  
 import java.util.TreeSet;
 26  
 
 27  
 
 28  
 /**
 29  
  * Public Dozer JMX Bean
 30  
  *
 31  
  * @author tierney.matt
 32  
  */
 33  8
 public class DozerStatisticsController implements DozerStatisticsControllerMBean {
 34  
 
 35  8
   private final StatisticsManager statsMgr = GlobalStatistics.getInstance().getStatsMgr();
 36  
 
 37  
   public void clearAll() {
 38  2
     statsMgr.clearAll();
 39  2
   }
 40  
 
 41  
   public boolean isStatisticsEnabled() {
 42  2
     return GlobalSettings.getInstance().isStatisticsEnabled();
 43  
   }
 44  
 
 45  
   public void setStatisticsEnabled(boolean statisticsEnabled) {
 46  1
     GlobalSettings.getInstance().setStatisticsEnabled(statisticsEnabled);
 47  1
   }
 48  
 
 49  
   public long getMappingSuccessCount() {
 50  1
     return getStatisticValue(StatisticType.MAPPING_SUCCESS_COUNT);
 51  
   }
 52  
 
 53  
   public long getMappingFailureCount() {
 54  1
     return getStatisticValue(StatisticType.MAPPING_FAILURE_COUNT);
 55  
   }
 56  
 
 57  
   public long getMapperInstancesCount() {
 58  1
     return getStatisticValue(StatisticType.MAPPER_INSTANCES_COUNT);
 59  
   }
 60  
 
 61  
   public long getMappingOverallTimeInMillis() {
 62  1
     return getStatisticValue(StatisticType.MAPPING_TIME);
 63  
   }
 64  
 
 65  
   public Set<String> getMappingFailureExceptionTypes() {
 66  0
     return getStatisticEntries(StatisticType.MAPPING_FAILURE_EX_TYPE_COUNT);
 67  
   }
 68  
 
 69  
   public Set<String> getMappingFailureTypes() {
 70  0
     return getStatisticEntries(StatisticType.MAPPING_FAILURE_TYPE_COUNT);
 71  
   }
 72  
 
 73  
   public Set<String> getCacheHitCount() {
 74  0
     return getStatisticEntries(StatisticType.CACHE_HIT_COUNT);
 75  
   }
 76  
 
 77  
   public Set<String> getCacheMissCount() {
 78  0
     return getStatisticEntries(StatisticType.CACHE_MISS_COUNT);
 79  
   }
 80  
 
 81  
   public long getFieldMappingSuccessCount() {
 82  1
     return getStatisticValue(StatisticType.FIELD_MAPPING_SUCCESS_COUNT);
 83  
   }
 84  
 
 85  
   public long getFieldMappingFailureCount() {
 86  1
     return getStatisticValue(StatisticType.FIELD_MAPPING_FAILURE_COUNT);
 87  
   }
 88  
 
 89  
   public long getFieldMappingFailureIgnoredCount() {
 90  1
     return getStatisticValue(StatisticType.FIELD_MAPPING_FAILURE_IGNORED_COUNT);
 91  
   }
 92  
 
 93  
   public long getCustomConverterSuccessCount() {
 94  0
     return getStatisticValue(StatisticType.CUSTOM_CONVERTER_SUCCESS_COUNT);
 95  
   }
 96  
 
 97  
   public long getCustomConverterOverallTimeInMillis() {
 98  0
     return getStatisticValue(StatisticType.CUSTOM_CONVERTER_TIME);
 99  
   }
 100  
 
 101  
   public double getMappingAverageTimeInMillis() {
 102  0
     double totalTime = getStatisticValue(StatisticType.MAPPING_TIME);
 103  0
     double totalCount = getStatisticValue(StatisticType.MAPPING_SUCCESS_COUNT);
 104  0
     return totalTime / totalCount;
 105  
   }
 106  
 
 107  
   public double getCustomConverterAverageTimeInMillis() {
 108  0
     double totalTime = getStatisticValue(StatisticType.CUSTOM_CONVERTER_TIME);
 109  0
     double totalCount = getStatisticValue(StatisticType.CUSTOM_CONVERTER_SUCCESS_COUNT);
 110  0
     return totalTime / totalCount;
 111  
   }
 112  
 
 113  
   public double getCustomConverterPercentageOfMappingTime() {
 114  0
     double ccTotalTime = getStatisticValue(StatisticType.CUSTOM_CONVERTER_TIME);
 115  0
     double overallTime = getStatisticValue(StatisticType.MAPPING_TIME);
 116  0
     return (ccTotalTime / overallTime) * 100;
 117  
   }
 118  
 
 119  
   protected Set<String> getStatisticEntries(StatisticType statisticType) {
 120  1
     Set<String> result = new TreeSet<String>();
 121  1
     for (StatisticEntry entry : statsMgr.getStatisticEntries(statisticType)) {
 122  0
       result.add(entry.getKey().toString() + ": Count " + entry.getValue());
 123  0
     }
 124  1
     return result;
 125  
   }
 126  
 
 127  
   public void logStatistics() {
 128  0
     statsMgr.logStatistics();
 129  0
   }
 130  
 
 131  
   public String dumpStatistics() {
 132  0
     return statsMgr.getStatistics().toString();
 133  
   }
 134  
 
 135  
   protected long getStatisticValue(StatisticType statisticType) {
 136  7
     return statsMgr.getStatisticValue(statisticType);
 137  
   }
 138  
 
 139  
 }