1 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 ; 11 import java.beans.PropertyChangeListener ; 12 import java.beans.PropertyChangeSupport ; 13 14 import javax.management.ObjectName ; 15 16 public class DSOClient { 17 private ConnectionContext cc; 18 private ObjectName bean; 19 private String channelID; 20 private String remoteAddress; 21 private String host; 22 private Integer port; 23 protected PropertyChangeSupport changeHelper; 24 25 private static final String CHANNEL_ID_PROPERTY = "channelID"; 26 27 public DSOClient(ConnectionContext cc, ObjectName bean) { 28 this.cc = cc; 29 this.bean = bean; 30 this.channelID = bean.getKeyProperty(CHANNEL_ID_PROPERTY); 31 changeHelper = new PropertyChangeSupport (this); 32 } 33 34 public ObjectName getObjectName() { 35 return bean; 36 } 37 38 public String getChannelID() { 39 return channelID; 40 } 41 42 public String getRemoteAddress() { 43 if(remoteAddress == null) { 44 try { 45 remoteAddress = (String )cc.getAttribute(bean, "RemoteAddress"); 46 } 47 catch(Exception e) { 48 AdminClient.getContext().log(e); 49 } 50 } 51 52 return remoteAddress; 53 } 54 55 public String getHost() { 56 if(host == null) { 57 host = "unknown"; 58 59 String 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 (-1); 71 72 String addr = getRemoteAddress(); 73 if(addr != null && addr.indexOf(":") != -1) { 74 try { 75 port = new Integer (addr.substring(addr.lastIndexOf(':')+1)); 76 } catch(Exception e) {} 77 } 78 } 79 80 return port.intValue(); 81 } 82 83 public void refresh() { 84 try { 85 cc.invoke(bean, "refresh", new Object []{}, new String []{}); 86 87 changeHelper.firePropertyChange( 88 new PropertyChangeEvent (this, null, null, null)); 89 } 90 catch(Exception e) { 91 AdminClient.getContext().log(e); 92 } 93 } 94 95 public String toString() { 96 return getRemoteAddress(); 97 } 98 99 public CountStatistic getObjectFlushRate() { 100 try { 101 return (CountStatistic)cc.getAttribute(bean, "ObjectFlushRate"); 102 } 103 catch(Exception 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 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 e) { 126 AdminClient.getContext().log(e); 127 } 128 129 return null; 130 } 131 132 public void addPropertyChangeListener(PropertyChangeListener listener) { 133 changeHelper.addPropertyChangeListener(listener); 134 } 135 136 public void removePropertyChangeListener(PropertyChangeListener listener) { 137 changeHelper.removePropertyChangeListener(listener); 138 } 139 } 140 | Popular Tags |