1 9 package org.jboss.portal.common.mx; 10 11 import javax.management.InstanceNotFoundException ; 12 import javax.management.ListenerNotFoundException ; 13 import javax.management.MBeanServer ; 14 import javax.management.Notification ; 15 import javax.management.NotificationFilter ; 16 import javax.management.NotificationListener ; 17 import javax.management.ObjectName ; 18 19 import org.apache.log4j.Logger; 20 21 27 public class Listener implements NotificationFilter , NotificationListener 28 { 29 30 protected final MBeanServer server; 31 protected final Logger log; 32 33 public Listener(MBeanServer server) 34 { 35 if (server == null) 36 { 37 throw new IllegalArgumentException ("server must not be null"); 38 } 39 this.server = server; 40 this.log = Logger.getLogger(getClass()); 41 } 42 43 public void register(ObjectName broadcaster) 44 { 45 register(broadcaster, null); 46 } 47 48 public void register(ObjectName broadcaster, Object handback) 49 { 50 try 51 { 52 if (broadcaster == null) 53 { 54 throw new IllegalArgumentException ("Broadcaster is null"); 55 } 56 57 log.debug("Register notifications on MBean " + broadcaster.getCanonicalName()); 58 server.addNotificationListener(broadcaster, this, this, handback); 59 } 60 catch (InstanceNotFoundException e) 61 { 62 throw new ListenerException(e); 63 } 64 } 65 66 public void unregister(ObjectName broadcaster) 67 { 68 try 69 { 70 if (broadcaster == null) 71 { 72 throw new IllegalArgumentException ("Broadcaster is null"); 73 } 74 75 log.debug("Unregister notifications on MBean " + broadcaster.getCanonicalName()); 76 server.removeNotificationListener(broadcaster, this); 77 } 78 catch (InstanceNotFoundException e) 79 { 80 throw new ListenerException(e); 81 } 82 catch (ListenerNotFoundException e) 83 { 84 throw new ListenerException(e); 85 } 86 } 87 88 91 public boolean isNotificationEnabled(Notification notification) 92 { 93 return true; 94 } 95 96 99 public void handleNotification(Notification notification, Object handback) 100 { 101 } 102 } 103 | Popular Tags |