KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > stats > DSOStatsImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.stats;
5
6 import com.tc.objectserver.api.GCStats;
7 import com.tc.objectserver.api.ObjectManagerMBean;
8 import com.tc.objectserver.api.ObjectManagerStats;
9 import com.tc.objectserver.core.api.DSOGlobalServerStats;
10 import com.tc.objectserver.core.impl.ServerManagementContext;
11 import com.tc.stats.counter.sampled.SampledCounter;
12 import com.tc.stats.statistics.CountStatistic;
13 import com.tc.stats.statistics.DoubleStatistic;
14 import com.tc.stats.statistics.DoubleStatisticImpl;
15 import com.tc.stats.statistics.Statistic;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 /**
20  * This is the root interface to the global DSO Server statistics.
21  *
22  * @see StatsSupport
23  * @see DSOStats
24  */

25
26 public class DSOStatsImpl extends StatsSupport implements DSOStats {
27
28   private final DSOGlobalServerStats serverStats;
29   private final SampledCounter faultRate;
30   private final SampledCounter flushRate;
31   private final ObjectManagerStats objMgrStats;
32   private final SampledCounter txnRate;
33   private final ObjectManagerMBean objManager;
34
35   public DSOStatsImpl(ServerManagementContext context) {
36     this.objManager = context.getObjectManager();
37     this.serverStats = context.getServerStats();
38     this.objMgrStats = serverStats.getObjectManagerStats();
39     this.faultRate = serverStats.getObjectFaultCounter();
40     this.flushRate = serverStats.getObjectFlushCounter();
41     this.txnRate = serverStats.getTransactionCounter();
42   }
43
44   public CountStatistic getObjectFaultRate() {
45     return StatsUtil.makeCountStat(faultRate);
46   }
47
48   public CountStatistic getObjectFlushRate() {
49     return StatsUtil.makeCountStat(flushRate);
50   }
51
52   public CountStatistic getTransactionRate() {
53     return StatsUtil.makeCountStat(txnRate);
54   }
55
56   public DoubleStatistic getCacheHitRatio() {
57     double value = objMgrStats.getCacheHitRatio();
58     DoubleStatisticImpl rv = new DoubleStatisticImpl(System.currentTimeMillis());
59     rv.setDoubleValue(value);
60     return rv;
61   }
62   
63   public CountStatistic getCacheMissRate() {
64     return StatsUtil.makeCountStat( objMgrStats.getCacheMissRate());
65   }
66
67
68   public Statistic[] getStatistics(String JavaDoc[] names) {
69     int count = names.length;
70     Statistic[] result = new Statistic[count];
71     Method JavaDoc method;
72
73     for (int i = 0; i < count; i++) {
74       try {
75         method = getClass().getMethod("get" + names[i], new Class JavaDoc[] {});
76         result[i] = (Statistic) method.invoke(this, new Object JavaDoc[] {});
77       } catch (Exception JavaDoc e) {
78         e.printStackTrace();
79       }
80     }
81
82     return result;
83   }
84
85   public GCStats[] getGarbageCollectorStats() {
86     return this.objManager.getGarbageCollectorStats();
87   }
88
89 }
90
Popular Tags