00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.jmx.listeners;
00032
00033 import java.io.IOException;
00034
00035 import javax.management.NotificationBroadcasterSupport;
00036 import javax.management.remote.JMXConnectionNotification;
00037
00038 import org.objectweb.proactive.jmx.server.ProActiveConnector;
00039
00040
00047 public class ProActiveConnectionNotificationEmitter
00048 extends NotificationBroadcasterSupport {
00049 private static long sequenceNumber;
00050 private ProActiveConnector connector;
00051
00056 public ProActiveConnectionNotificationEmitter(ProActiveConnector connector) {
00057 this.connector = connector;
00058 addNotificationListener(connector, null, null);
00059 }
00060
00064 public void sendConnectionNotificationOpened() {
00065 JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.OPENED,
00066 connector, getConnectionId(), getNextNotificationNumber(),
00067 "Connection opened", null);
00068 sendNotification(notification);
00069 }
00070
00074 public void sendConnectionNotificationClosed() {
00075 JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.CLOSED,
00076 connector, getConnectionId(), getNextNotificationNumber(),
00077 "Connection closed", null);
00078 sendNotification(notification);
00079 }
00080
00084 public void sendConnectionNotificationFailed() {
00085 JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.FAILED,
00086 connector, getConnectionId(), getNextNotificationNumber(),
00087 "Connection failed", null);
00088 sendNotification(notification);
00089 }
00090
00091 private long getNextNotificationNumber() {
00092 synchronized (ProActiveConnectionNotificationEmitter.class) {
00093 return sequenceNumber++;
00094 }
00095 }
00096
00097 private String getConnectionId() {
00098 try {
00099 return connector.getConnectionId();
00100 } catch (IOException x) {
00101 return null;
00102 }
00103 }
00104 }