KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > dso > 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.admin.dso;
5
6 import com.tc.admin.AdminClient;
7 import com.tc.admin.ConnectionContext;
8 import com.tc.stats.statistics.CountStatistic;
9
10 import java.beans.PropertyChangeEvent JavaDoc;
11 import java.beans.PropertyChangeListener JavaDoc;
12 import java.beans.PropertyChangeSupport JavaDoc;
13
14 import javax.management.ObjectName JavaDoc;
15
16 public class DSOClient {
17   private ConnectionContext cc;
18   private ObjectName JavaDoc bean;
19   private String JavaDoc channelID;
20   private String JavaDoc remoteAddress;
21   private String JavaDoc host;
22   private Integer JavaDoc port;
23   protected PropertyChangeSupport JavaDoc changeHelper;
24
25   private static final String JavaDoc CHANNEL_ID_PROPERTY = "channelID";
26
27   public DSOClient(ConnectionContext cc, ObjectName JavaDoc bean) {
28     this.cc = cc;
29     this.bean = bean;
30     this.channelID = bean.getKeyProperty(CHANNEL_ID_PROPERTY);
31     changeHelper = new PropertyChangeSupport JavaDoc(this);
32   }
33
34   public ObjectName JavaDoc getObjectName() {
35     return bean;
36   }
37
38   public String JavaDoc getChannelID() {
39     return channelID;
40   }
41
42   public String JavaDoc getRemoteAddress() {
43     if(remoteAddress == null) {
44       try {
45         remoteAddress = (String JavaDoc)cc.getAttribute(bean, "RemoteAddress");
46       }
47       catch(Exception JavaDoc e) {
48         AdminClient.getContext().log(e);
49       }
50     }
51
52     return remoteAddress;
53   }
54
55   public String JavaDoc getHost() {
56     if(host == null) {
57       host = "unknown";
58
59       String JavaDoc addr = getRemoteAddress();
60       if(addr != null && addr.indexOf(':') != -1) {
61         host = addr.substring(0, addr.lastIndexOf(':'));
62       }
63     }
64
65     return host;
66   }
67
68   public int getPort() {
69     if(port == null) {
70       port = new Integer JavaDoc(-1);
71
72       String JavaDoc addr = getRemoteAddress();
73       if(addr != null && addr.indexOf(":") != -1) {
74         try {
75           port = new Integer JavaDoc(addr.substring(addr.lastIndexOf(':')+1));
76         } catch(Exception JavaDoc e) {/**/}
77       }
78     }
79
80     return port.intValue();
81   }
82
83   public void refresh() {
84     try {
85       cc.invoke(bean, "refresh", new Object JavaDoc[]{}, new String JavaDoc[]{});
86
87       changeHelper.firePropertyChange(
88         new PropertyChangeEvent JavaDoc(this, null, null, null));
89     }
90     catch(Exception JavaDoc e) {
91       AdminClient.getContext().log(e);
92     }
93   }
94
95   public String JavaDoc toString() {
96     return getRemoteAddress();
97   }
98
99   public CountStatistic getObjectFlushRate() {
100     try {
101       return (CountStatistic)cc.getAttribute(bean, "ObjectFlushRate");
102     }
103     catch(Exception JavaDoc e) {
104       AdminClient.getContext().log(e);
105     }
106
107     return null;
108   }
109
110   public CountStatistic getObjectFaultRate() {
111     try {
112       return (CountStatistic)cc.getAttribute(bean, "ObjectFaultRate");
113     }
114     catch(Exception JavaDoc e) {
115       AdminClient.getContext().log(e);
116     }
117
118     return null;
119   }
120
121   public CountStatistic getTransactionRate() {
122     try {
123       return (CountStatistic)cc.getAttribute(bean, "TransactionRate");
124     }
125     catch(Exception JavaDoc e) {
126       AdminClient.getContext().log(e);
127     }
128
129     return null;
130   }
131
132   public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
133     changeHelper.addPropertyChangeListener(listener);
134   }
135
136   public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
137     changeHelper.removePropertyChangeListener(listener);
138   }
139 }
140
Popular Tags