1 8 9 package mx4j.remote; 10 11 import java.io.IOException ; 12 import javax.management.NotificationBroadcasterSupport ; 13 import javax.management.remote.JMXConnectionNotification ; 14 import javax.management.remote.JMXConnector ; 15 16 19 public class ConnectionNotificationEmitter extends NotificationBroadcasterSupport 20 { 21 private static long sequenceNumber; 22 23 private JMXConnector connector; 24 25 public ConnectionNotificationEmitter(JMXConnector connector) 26 { 27 this.connector = connector; 28 } 29 30 private long getNextNotificationNumber() 31 { 32 synchronized (ConnectionNotificationEmitter.class) 33 { 34 return sequenceNumber++; 35 } 36 } 37 38 private String getConnectionId() 39 { 40 try 41 { 42 return connector.getConnectionId(); 43 } 44 catch (IOException x) 45 { 46 return null; 47 } 48 } 49 50 public void sendConnectionNotificationOpened() 51 { 52 JMXConnectionNotification notification = new JMXConnectionNotification (JMXConnectionNotification.OPENED, connector, getConnectionId(), getNextNotificationNumber(), "Connection opened", null); 53 sendNotification(notification); 54 } 55 56 public void sendConnectionNotificationClosed() 57 { 58 JMXConnectionNotification notification = new JMXConnectionNotification (JMXConnectionNotification.CLOSED, connector, getConnectionId(), getNextNotificationNumber(), "Connection closed", null); 59 sendNotification(notification); 60 } 61 62 public void sendConnectionNotificationFailed() 63 { 64 JMXConnectionNotification notification = new JMXConnectionNotification (JMXConnectionNotification.FAILED, connector, getConnectionId(), getNextNotificationNumber(), "Connection failed", null); 65 sendNotification(notification); 66 } 67 68 public void sendConnectionNotificationLost(long howMany) 69 { 70 JMXConnectionNotification notification = new JMXConnectionNotification (JMXConnectionNotification.NOTIFS_LOST, connector, getConnectionId(), getNextNotificationNumber(), "Some notification (" + howMany + ") was lost", null); 71 sendNotification(notification); 72 } 73 } 74 | Popular Tags |