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.management.AbstractTerracottaMBean;
07: import com.tc.net.TCSocketAddress;
08: import com.tc.net.protocol.tcm.ChannelID;
09: import com.tc.net.protocol.tcm.MessageChannel;
10: import com.tc.object.net.ChannelStats;
11: import com.tc.stats.counter.sampled.SampledCounter;
12: import com.tc.stats.statistics.CountStatistic;
13: import com.tc.stats.statistics.Statistic;
14:
15: import java.lang.reflect.Method;
16:
17: import javax.management.NotCompliantMBeanException;
18:
19: public class DSOClient extends AbstractTerracottaMBean implements
20: DSOClientMBean {
21:
22: private final MessageChannel channel;
23: private final SampledCounter txnRate;
24: private final SampledCounter flushRate;
25: private final SampledCounter faultRate;
26:
27: public DSOClient(final MessageChannel channel,
28: final ChannelStats channelStats)
29: throws NotCompliantMBeanException {
30: super (DSOClientMBean.class, false);
31: this .channel = channel;
32: this .txnRate = (SampledCounter) channelStats.getCounter(
33: channel, ChannelStats.TXN_RATE);
34: this .flushRate = (SampledCounter) channelStats.getCounter(
35: channel, ChannelStats.OBJECT_FLUSH_RATE);
36: this .faultRate = (SampledCounter) channelStats.getCounter(
37: channel, ChannelStats.OBJECT_REQUEST_RATE);
38: }
39:
40: public void reset() {
41: // nothing to reset
42: }
43:
44: public ChannelID getChannelID() {
45: return channel.getChannelID();
46: }
47:
48: public String getRemoteAddress() {
49: TCSocketAddress addr = channel.getRemoteAddress();
50: if (addr == null) {
51: return "not connected";
52: }
53: return addr.getStringForm();
54: }
55:
56: public CountStatistic getTransactionRate() {
57: return StatsUtil.makeCountStat(txnRate);
58: }
59:
60: public CountStatistic getObjectFaultRate() {
61: return StatsUtil.makeCountStat(faultRate);
62: }
63:
64: public CountStatistic getObjectFlushRate() {
65: return StatsUtil.makeCountStat(flushRate);
66: }
67:
68: public Statistic[] getStatistics(final 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: }
|