1 22 package org.jboss.monitor.services; 23 24 import javax.management.Notification ; 25 import javax.management.ObjectName ; 26 27 import org.jboss.logging.DynamicLogger; 28 import org.jboss.system.ListenerServiceMBeanSupport; 29 30 import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong; 31 32 42 public class NotificationListener extends ListenerServiceMBeanSupport 43 implements NotificationListenerMBean 44 { 45 46 48 49 private SynchronizedLong notificationCount; 50 51 52 private boolean dynamicSubscriptions; 53 54 55 private ObjectName notificationListener; 56 57 59 60 protected DynamicLogger log = DynamicLogger.getDynamicLogger(super.log.getName()); 61 62 64 67 public NotificationListener() 68 { 69 notificationCount = new SynchronizedLong(0); 70 dynamicSubscriptions = true; 71 notificationListener = null; 72 log.setLogLevel(DynamicLogger.LOG_LEVEL_INFO); 73 } 74 75 77 82 public long getNotificationCount() 83 { 84 return this.notificationCount.get(); 85 } 86 87 92 public void setDynamicSubscriptions(boolean dynamicSubscriptions) 93 { 94 this.dynamicSubscriptions = dynamicSubscriptions; 95 } 96 97 102 public boolean getDynamicSubscriptions() 103 { 104 return this.dynamicSubscriptions; 105 } 106 107 112 public void setNotificationListener(ObjectName notificationListener) 113 { 114 this.notificationListener = notificationListener; 115 } 116 117 122 public ObjectName getNotificationListener() 123 { 124 return this.notificationListener; 125 } 126 127 132 public void setLogLevel(String logLevel) 133 { 134 log.setLogLevelAsString(logLevel); 135 } 136 137 142 public String getLogLevel() 143 { 144 return log.getLogLevelAsString(); 145 } 146 147 149 152 public void startService() throws Exception 153 { 154 if (this.notificationListener == null) 155 { 156 super.subscribe(this.dynamicSubscriptions); } 158 else 159 { 160 super.subscribe(this.dynamicSubscriptions, this.notificationListener); 161 } 162 } 163 164 167 public void stopService() throws Exception 168 { 169 super.unsubscribe(); 171 } 172 173 176 public void handleNotification2(Notification notification, Object handback) 177 { 178 log.log("Got notification (#" + Long.toString(this.notificationCount.increment()) 179 + "): " + notification + ", handback: " + handback); 180 } 181 } 182 | Popular Tags |