KickJava   Java API By Example, From Geeks To Geeks.

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


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.management.AbstractTerracottaMBean;
7 import com.tc.net.TCSocketAddress;
8 import com.tc.net.protocol.tcm.ChannelID;
9 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 JavaDoc;
16
17 import javax.management.NotCompliantMBeanException JavaDoc;
18
19 public class DSOClient extends AbstractTerracottaMBean implements DSOClientMBean {
20
21   private final MessageChannel channel;
22   private final SampledCounter txnRate;
23   private final SampledCounter flushRate;
24   private final SampledCounter faultRate;
25
26   public DSOClient(final MessageChannel channel, final ChannelStats channelStats) throws NotCompliantMBeanException JavaDoc {
27     super(DSOClientMBean.class, false);
28     this.channel = channel;
29     this.txnRate = (SampledCounter) channelStats.getCounter(channel, ChannelStats.TXN_RATE);
30     this.flushRate = (SampledCounter) channelStats.getCounter(channel, ChannelStats.OBJECT_FLUSH_RATE);
31     this.faultRate = (SampledCounter) channelStats.getCounter(channel, ChannelStats.OBJECT_REQUEST_RATE);
32   }
33
34   public void reset() {
35     // nothing to reset
36
}
37
38   public ChannelID getChannelID() {
39     return channel.getChannelID();
40   }
41
42   public String JavaDoc getRemoteAddress() {
43     TCSocketAddress addr = channel.getRemoteAddress();
44     if (addr == null) { return "not connected"; }
45     return addr.getStringForm();
46   }
47
48   public CountStatistic getTransactionRate() {
49     return StatsUtil.makeCountStat(txnRate);
50   }
51
52   public CountStatistic getObjectFaultRate() {
53     return StatsUtil.makeCountStat(faultRate);
54   }
55
56   public CountStatistic getObjectFlushRate() {
57     return StatsUtil.makeCountStat(flushRate);
58   }
59
60   public Statistic[] getStatistics(final String JavaDoc[] names) {
61     int count = names.length;
62     Statistic[] result = new Statistic[count];
63     Method JavaDoc method;
64
65     for (int i = 0; i < count; i++) {
66       try {
67         method = getClass().getMethod("get" + names[i], new Class JavaDoc[] {});
68         result[i] = (Statistic) method.invoke(this, new Object JavaDoc[] {});
69       } catch (Exception JavaDoc e) {
70         e.printStackTrace();
71       }
72     }
73
74     return result;
75   }
76
77 }
78
Popular Tags