1 22 package org.jboss.jmx.examples.configuration; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.system.ServiceMBeanSupport; 26 27 import javax.management.*; 28 import java.io.Serializable ; 29 30 33 public class MBeanConfigurator extends ServiceMBeanSupport implements MBeanConfiguratorMBean, NotificationListener 34 { 35 36 private static final Logger log = Logger.getLogger(MBeanConfigurator.class.getName()); 37 38 41 public String getName() 42 { 43 return "MBeanConfigurator"; 44 } 45 46 public void startService() 47 { 48 try 49 { 50 log.debug("Starting MBeanConfigurator service."); 51 ObjectName mbeanserver = new ObjectName("JMImplementation:type=MBeanServerDelegate"); 52 RegistrationNotificationFilter mbeanServerNotificationFilter = new RegistrationNotificationFilter(); 53 getServer().addNotificationListener(mbeanserver, this, mbeanServerNotificationFilter, null); 54 } 55 catch (Exception e) 56 { 57 log.error("Could not start MBeanConfigurator service.", e); 58 } 59 } 60 61 62 public void mbeanRegistered(ObjectName objectName) 63 throws ReflectionException, InstanceNotFoundException, MBeanException, MalformedObjectNameException 64 { 65 log.debug("MBean " + objectName + " registered. Will see if any attribute bindings present."); 66 ObjectName serviceBindingMgr = new ObjectName("jboss.system:service=ServiceBindingManager"); 68 Object [] args = {objectName}; 69 String [] sig = {"javax.management.ObjectName"}; 70 MBeanServer server = getServer(); 71 if(server != null) 72 { 73 server.invoke(serviceBindingMgr, "applyServiceConfig", args, sig); 74 } 75 } 76 77 85 public void handleNotification(Notification notification, Object handback) 86 { 87 if (notification instanceof MBeanServerNotification) 89 { 90 if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) 91 { 92 MBeanServerNotification serverNotification = (MBeanServerNotification) notification; 93 try 94 { 95 mbeanRegistered(serverNotification.getMBeanName()); 96 } 97 catch (Exception e) 98 { 99 log.error("Error configuring mbean " + serverNotification.getMBeanName(), e); 100 } 101 } 102 } 103 104 } 105 106 public class RegistrationNotificationFilter implements NotificationFilter, Serializable 107 { 108 109 116 public boolean isNotificationEnabled(Notification notification) 117 { 118 boolean processNotification = false; 119 if (notification instanceof MBeanServerNotification) 120 { 121 if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) 122 { 123 processNotification = true; 124 } 125 } 126 return processNotification; 127 } 128 } 129 } | Popular Tags |