001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.dso;
005:
006: import com.tc.admin.AdminClient;
007: import com.tc.admin.ConnectionContext;
008: import com.tc.stats.statistics.CountStatistic;
009:
010: import java.beans.PropertyChangeEvent;
011: import java.beans.PropertyChangeListener;
012: import java.beans.PropertyChangeSupport;
013:
014: import javax.management.ObjectName;
015:
016: public class DSOClient {
017: private ConnectionContext cc;
018: private ObjectName bean;
019: private String channelID;
020: private String remoteAddress;
021: private String host;
022: private Integer port;
023: protected PropertyChangeSupport changeHelper;
024:
025: private static final String CHANNEL_ID_PROPERTY = "channelID";
026:
027: public DSOClient(ConnectionContext cc, ObjectName bean) {
028: this .cc = cc;
029: this .bean = bean;
030: this .channelID = bean.getKeyProperty(CHANNEL_ID_PROPERTY);
031: changeHelper = new PropertyChangeSupport(this );
032: }
033:
034: public ObjectName getObjectName() {
035: return bean;
036: }
037:
038: public String getChannelID() {
039: return channelID;
040: }
041:
042: public String getRemoteAddress() {
043: if (remoteAddress == null) {
044: try {
045: remoteAddress = (String) cc.getAttribute(bean,
046: "RemoteAddress");
047: } catch (Exception e) {
048: AdminClient.getContext().log(e);
049: }
050: }
051:
052: return remoteAddress;
053: }
054:
055: public String getHost() {
056: if (host == null) {
057: host = "unknown";
058:
059: String addr = getRemoteAddress();
060: if (addr != null && addr.indexOf(':') != -1) {
061: host = addr.substring(0, addr.lastIndexOf(':'));
062: }
063: }
064:
065: return host;
066: }
067:
068: public int getPort() {
069: if (port == null) {
070: port = new Integer(-1);
071:
072: String addr = getRemoteAddress();
073: if (addr != null && addr.indexOf(":") != -1) {
074: try {
075: port = new Integer(addr.substring(addr
076: .lastIndexOf(':') + 1));
077: } catch (Exception e) {/**/
078: }
079: }
080: }
081:
082: return port.intValue();
083: }
084:
085: public void refresh() {
086: try {
087: cc
088: .invoke(bean, "refresh", new Object[] {},
089: new String[] {});
090:
091: changeHelper.firePropertyChange(new PropertyChangeEvent(
092: this , null, null, null));
093: } catch (Exception e) {
094: AdminClient.getContext().log(e);
095: }
096: }
097:
098: public String toString() {
099: return getRemoteAddress();
100: }
101:
102: public CountStatistic getObjectFlushRate() {
103: try {
104: return (CountStatistic) cc.getAttribute(bean,
105: "ObjectFlushRate");
106: } catch (Exception e) {
107: AdminClient.getContext().log(e);
108: }
109:
110: return null;
111: }
112:
113: public CountStatistic getObjectFaultRate() {
114: try {
115: return (CountStatistic) cc.getAttribute(bean,
116: "ObjectFaultRate");
117: } catch (Exception e) {
118: AdminClient.getContext().log(e);
119: }
120:
121: return null;
122: }
123:
124: public CountStatistic getTransactionRate() {
125: try {
126: return (CountStatistic) cc.getAttribute(bean,
127: "TransactionRate");
128: } catch (Exception e) {
129: AdminClient.getContext().log(e);
130: }
131:
132: return null;
133: }
134:
135: public void addPropertyChangeListener(
136: PropertyChangeListener listener) {
137: changeHelper.addPropertyChangeListener(listener);
138: }
139:
140: public void removePropertyChangeListener(
141: PropertyChangeListener listener) {
142: changeHelper.removePropertyChangeListener(listener);
143: }
144: }
|