1 25 package org.objectweb.jonas.management; 26 27 import javax.management.ListenerNotFoundException ; 29 import javax.management.MBeanNotificationInfo ; 30 import javax.management.Notification ; 31 import javax.management.NotificationBroadcasterSupport ; 32 import javax.management.NotificationFilter ; 33 import javax.management.NotificationListener ; 34 35 import org.objectweb.util.monolog.api.BasicLevel; 36 import org.objectweb.util.monolog.api.Logger; 37 38 46 public class ReconfigDispatcher extends NotificationBroadcasterSupport implements ReconfigDispatcherMBean { 47 48 private static Logger slogger = null; 49 50 53 public static final String RECONFIG_TYPE = "jonas.management.reconfiguration"; 54 57 public static final String SAVE_RECONFIG_TYPE = "jonas.management.reconfiguration.save"; 58 61 final String RECONFIG_NOTIF_CLASS = "jmx.management.Notification"; 62 final String SAVE_RECONFIG_NOTIF_CLASS = "jmx.management.Notification"; 63 64 67 ListenerJavaBean myListener = null; 68 69 74 public void initLogger(Logger mylogger) { 75 slogger = mylogger; 76 } 77 78 84 public void addNotificationListener(NotificationListener listner, 85 NotificationFilter filter, 86 java.lang.Object handback) 87 throws java.lang.IllegalArgumentException { 88 89 if (slogger.isLoggable(BasicLevel.DEBUG)) { 90 slogger.log(BasicLevel.DEBUG, "handback: " + handback); 91 if (myListener == null) { 92 slogger.log(BasicLevel.DEBUG, "Register the listener"); 93 } else { 94 slogger.log(BasicLevel.DEBUG, "Caution : Re-register a listener !!! "); 95 } 96 } 97 myListener = new ListenerJavaBean(listner, filter, handback); 98 } 99 103 public void removeNotificationListener(NotificationListener listner) throws ListenerNotFoundException { 104 NotificationListener registeredListener = myListener.getListener(); 105 if (registeredListener.equals(listner)) 106 myListener = null; 107 } 108 112 public MBeanNotificationInfo [] getNotificationInfo() { 113 String [] notifsType = new String [2]; 114 notifsType[0] = new String (RECONFIG_TYPE); 115 notifsType[1] = new String (SAVE_RECONFIG_TYPE); 116 117 MBeanNotificationInfo [] myNotifInfos = new MBeanNotificationInfo [2]; 118 MBeanNotificationInfo myNotifInfo = new MBeanNotificationInfo (notifsType, RECONFIG_NOTIF_CLASS, "Notify service reconfiguration events"); 119 myNotifInfos[0] = myNotifInfo; 120 121 myNotifInfo = new MBeanNotificationInfo (notifsType, SAVE_RECONFIG_NOTIF_CLASS, "Notify save reconfiguretion events"); 122 myNotifInfos[1] = myNotifInfo; 123 124 return myNotifInfos; 125 } 126 127 131 public NotificationListener getListener() { 132 if (myListener != null) 133 return myListener.getListener(); 134 else 135 return null; 136 } 137 141 public NotificationFilter getFilter() { 142 if (myListener != null) 143 return myListener.getFilter(); 144 else 145 return null; 146 } 147 151 public java.lang.Object getHandback() { 152 if (myListener != null) 153 return myListener.getHandback(); 154 else 155 return null; 156 } 157 158 164 public void sendSaveNotification(long sequenceNumber, String resourceName) { 165 Notification saveNotif = new Notification (SAVE_RECONFIG_TYPE, this, sequenceNumber, resourceName); 167 if (slogger.isLoggable(BasicLevel.DEBUG)) { 168 slogger.log(BasicLevel.DEBUG, saveNotif.getType() + " notification object created"); 169 } 170 171 NotificationListener listenerMBean = getListener(); 173 Object handback = getHandback(); 174 if (listenerMBean != null) { 175 listenerMBean.handleNotification(saveNotif, handback); 176 } else { 177 if (slogger.isLoggable(BasicLevel.DEBUG)) { 178 slogger.log(BasicLevel.ERROR, "MBean can't send management notification as no listener registered !!"); 179 } 180 } 181 } 182 183 190 public void sendReconfigNotification(long sequenceNumber, String resourceName, Object userData) { 191 Notification configNotif = new Notification (RECONFIG_TYPE, this, sequenceNumber, resourceName); 193 configNotif.setUserData(userData); 194 if (slogger.isLoggable(BasicLevel.DEBUG)) { 195 slogger.log(BasicLevel.DEBUG, configNotif.getType() + " notification object created"); 196 } 197 198 NotificationListener listenerMBean = getListener(); 200 Object handback = getHandback(); 201 if (listenerMBean != null) { 202 listenerMBean.handleNotification(configNotif, handback); 203 } else { 204 if (slogger.isLoggable(BasicLevel.DEBUG)) { 205 slogger.log(BasicLevel.ERROR, "MBean can't send management notification as no listener registered !!"); 206 } 207 } 208 } 209 } 210 | Popular Tags |