1 7 8 package javax.management; 9 10 import java.util.Properties ; 12 import java.util.Random ; 13 14 import com.sun.jmx.defaults.JmxProperties; 16 import com.sun.jmx.defaults.ServiceName; 17 18 25 public class MBeanServerDelegate implements MBeanServerDelegateMBean , 26 NotificationEmitter { 27 28 29 private String mbeanServerId ; 30 31 33 private final NotificationBroadcasterSupport broadcaster; 34 35 private static long oldStamp = 0; 36 private final long stamp; 37 private long sequenceNumber = 1; 38 39 private static final MBeanNotificationInfo [] notifsInfo; 40 41 static { 42 final String [] types = { 43 MBeanServerNotification.UNREGISTRATION_NOTIFICATION, 44 MBeanServerNotification.REGISTRATION_NOTIFICATION 45 }; 46 notifsInfo = new MBeanNotificationInfo [1]; 47 notifsInfo[0] = 48 new MBeanNotificationInfo (types, 49 "javax.management.MBeanServerNotification", 50 "Notifications sent by the MBeanServerDelegate MBean"); 51 } 52 53 56 public MBeanServerDelegate () { 57 stamp = getStamp(); 58 broadcaster = new NotificationBroadcasterSupport () ; 59 } 60 61 62 67 public synchronized String getMBeanServerId() { 68 if (mbeanServerId == null) { 69 String localHost; 70 try { 71 localHost = java.net.InetAddress.getLocalHost().getHostName(); 72 } catch (java.net.UnknownHostException e) { 73 localHost = "localhost"; 74 } 75 mbeanServerId = new String (localHost + "_" + stamp); 76 } 77 return mbeanServerId; 78 } 79 80 86 public String getSpecificationName() { 87 return ServiceName.JMX_SPEC_NAME; 88 } 89 90 96 public String getSpecificationVersion() { 97 return ServiceName.JMX_SPEC_VERSION; 98 } 99 100 106 public String getSpecificationVendor() { 107 return ServiceName.JMX_SPEC_VENDOR; 108 } 109 110 115 public String getImplementationName() { 116 return ServiceName.JMX_IMPL_NAME; 117 } 118 119 124 public String getImplementationVersion() { 125 try { 126 return System.getProperty("java.runtime.version"); 127 } catch (SecurityException e) { 128 return ""; 129 } 130 } 131 132 137 public String getImplementationVendor() { 138 return ServiceName.JMX_IMPL_VENDOR; 139 } 140 141 public MBeanNotificationInfo [] getNotificationInfo() { 144 final int len = MBeanServerDelegate.notifsInfo.length; 145 final MBeanNotificationInfo [] infos = 146 new MBeanNotificationInfo [len]; 147 System.arraycopy(MBeanServerDelegate.notifsInfo,0,infos,0,len); 148 return infos; 149 } 150 151 public synchronized 154 void addNotificationListener(NotificationListener listener, 155 NotificationFilter filter, 156 Object handback) 157 throws IllegalArgumentException { 158 broadcaster.addNotificationListener(listener,filter,handback) ; 159 } 160 161 public synchronized 164 void removeNotificationListener(NotificationListener listener, 165 NotificationFilter filter, 166 Object handback) 167 throws ListenerNotFoundException { 168 broadcaster.removeNotificationListener(listener,filter,handback) ; 169 } 170 171 public synchronized 174 void removeNotificationListener(NotificationListener listener) 175 throws ListenerNotFoundException { 176 broadcaster.removeNotificationListener(listener) ; 177 } 178 179 187 public void sendNotification(Notification notification) { 188 if (notification.getSequenceNumber() < 1) { 189 synchronized (this) { 190 notification.setSequenceNumber(this.sequenceNumber++); 191 } 192 } 193 broadcaster.sendNotification(notification); 194 } 195 196 202 private static synchronized long getStamp() { 203 long s = System.currentTimeMillis(); 204 if (oldStamp >= s) { 205 s = oldStamp + 1; 206 } 207 oldStamp = s; 208 return s; 209 } 210 } 211 | Popular Tags |