00001
00025 package org.objectweb.jonas.management;
00026
00027
00028 import javax.management.ListenerNotFoundException;
00029 import javax.management.MBeanNotificationInfo;
00030 import javax.management.Notification;
00031 import javax.management.NotificationBroadcasterSupport;
00032 import javax.management.NotificationFilter;
00033 import javax.management.NotificationListener;
00034
00035 import org.objectweb.util.monolog.api.BasicLevel;
00036 import org.objectweb.util.monolog.api.Logger;
00037
00046 public class ReconfigDispatcher extends NotificationBroadcasterSupport implements ReconfigDispatcherMBean {
00047
00048 private static Logger slogger = null;
00049
00053 public static final String RECONFIG_TYPE = "jonas.management.reconfiguration";
00057 public static final String SAVE_RECONFIG_TYPE = "jonas.management.reconfiguration.save";
00061 final String RECONFIG_NOTIF_CLASS = "jmx.management.Notification";
00062 final String SAVE_RECONFIG_NOTIF_CLASS = "jmx.management.Notification";
00063
00067 ListenerJavaBean myListener = null;
00068
00074 public void initLogger(Logger mylogger) {
00075 slogger = mylogger;
00076 }
00077
00084 public void addNotificationListener(NotificationListener listner,
00085 NotificationFilter filter,
00086 java.lang.Object handback)
00087 throws java.lang.IllegalArgumentException {
00088
00089 if (handback != null)
00090 slogger.log(BasicLevel.DEBUG, "handback: " + handback.toString());
00091
00092 if (myListener == null) {
00093 slogger.log(BasicLevel.DEBUG, "Register the listener");
00094 } else {
00095 slogger.log(BasicLevel.DEBUG, "Caution : Re-register a listener !!! ");
00096 }
00097 myListener = new ListenerJavaBean(listner, filter, handback);
00098 }
00103 public void removeNotificationListener(NotificationListener listner) throws ListenerNotFoundException {
00104 NotificationListener registeredListener = myListener.getListener();
00105 if (registeredListener.equals(listner))
00106 myListener = null;
00107 }
00112 public MBeanNotificationInfo[] getNotificationInfo() {
00113 String[] notifsType = new String[2];
00114 notifsType[0] = new String(RECONFIG_TYPE);
00115 notifsType[1] = new String(SAVE_RECONFIG_TYPE);
00116
00117 MBeanNotificationInfo[] myNotifInfos = new MBeanNotificationInfo[2];
00118 MBeanNotificationInfo myNotifInfo = new MBeanNotificationInfo(notifsType, RECONFIG_NOTIF_CLASS, "Notify service reconfiguration events");
00119 myNotifInfos[0] = myNotifInfo;
00120
00121 myNotifInfo = new MBeanNotificationInfo(notifsType, SAVE_RECONFIG_NOTIF_CLASS, "Notify save reconfiguretion events");
00122 myNotifInfos[1] = myNotifInfo;
00123
00124 return myNotifInfos;
00125 }
00126
00131 public NotificationListener getListener() {
00132 if (myListener != null)
00133 return myListener.getListener();
00134 else
00135 return null;
00136 }
00141 public NotificationFilter getFilter() {
00142 if (myListener != null)
00143 return myListener.getFilter();
00144 else
00145 return null;
00146 }
00151 public java.lang.Object getHandback() {
00152 if (myListener != null)
00153 return myListener.getHandback();
00154 else
00155 return null;
00156 }
00157
00164 public void sendSaveNotification(long sequenceNumber, String resourceName) {
00165
00166 Notification saveNotif = new Notification(SAVE_RECONFIG_TYPE, this, sequenceNumber, resourceName);
00167 slogger.log(BasicLevel.DEBUG, saveNotif.getType() + " notification object created");
00168
00169
00170 NotificationListener listenerMBean = getListener();
00171 Object handback = getHandback();
00172 if (listenerMBean != null)
00173 listenerMBean.handleNotification(saveNotif, handback);
00174 else
00175 slogger.log(BasicLevel.ERROR, "MBean can't send management notification as no listener registered !!");
00176 }
00177
00185 public void sendReconfigNotification(long sequenceNumber, String resourceName, Object userData) {
00186
00187 Notification configNotif = new Notification(RECONFIG_TYPE, this, sequenceNumber, resourceName);
00188 configNotif.setUserData(userData);
00189 slogger.log(BasicLevel.DEBUG, configNotif.getType() + " notification object created");
00190
00191
00192 NotificationListener listenerMBean = getListener();
00193 Object handback = getHandback();
00194 if (listenerMBean != null) {
00195 listenerMBean.handleNotification(configNotif, handback);
00196 } else
00197 slogger.log(BasicLevel.ERROR, "MBean can't send management notification as no listener registered !!");
00198 }
00199 }