01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.stats;
05:
06: import com.tc.objectserver.api.GCStats;
07: import com.tc.objectserver.api.ObjectManagerMBean;
08: import com.tc.objectserver.api.ObjectManagerStats;
09: 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;
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
59: .currentTimeMillis());
60: rv.setDoubleValue(value);
61: return rv;
62: }
63:
64: public CountStatistic getCacheMissRate() {
65: return StatsUtil.makeCountStat(objMgrStats.getCacheMissRate());
66: }
67:
68: public Statistic[] getStatistics(String[] names) {
69: int count = names.length;
70: Statistic[] result = new Statistic[count];
71: Method method;
72:
73: for (int i = 0; i < count; i++) {
74: try {
75: method = getClass().getMethod("get" + names[i],
76: new Class[] {});
77: result[i] = (Statistic) method.invoke(this ,
78: new Object[] {});
79: } catch (Exception e) {
80: e.printStackTrace();
81: }
82: }
83:
84: return result;
85: }
86:
87: public GCStats[] getGarbageCollectorStats() {
88: return this.objManager.getGarbageCollectorStats();
89: }
90:
91: }
|