1 25 package org.objectweb.jonas.ws.mbean; 26 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import javax.management.MBeanServer ; 31 import javax.management.MalformedObjectNameException ; 32 import javax.management.ObjectName ; 33 import javax.management.modelmbean.ModelMBean ; 34 35 import org.apache.commons.modeler.ManagedBean; 36 import org.apache.commons.modeler.Registry; 37 38 import org.objectweb.jonas.common.Log; 39 import org.objectweb.jonas.jmx.JmxService; 40 import org.objectweb.jonas.management.JonasMBeanTools; 41 import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject; 42 import org.objectweb.jonas.service.ServiceManager; 43 44 import org.objectweb.util.monolog.api.BasicLevel; 45 import org.objectweb.util.monolog.api.Logger; 46 47 53 public abstract class AbstractWebServiceMBean extends J2EEManagedObject { 54 55 58 private static Logger log = Log.getLogger(Log.JONAS_WS_PREFIX); 59 60 63 private ObjectName realObjectName = null; 64 65 69 public AbstractWebServiceMBean(String objectName) { 70 super(objectName); 71 try { 72 realObjectName = ObjectName.getInstance(objectName); 73 } catch (MalformedObjectNameException e) { 74 realObjectName = null; 76 } 77 } 78 79 82 public void register() { 83 register(getMBeanServer()); 84 } 85 86 90 public void register(MBeanServer server) { 91 92 Registry registry = JonasMBeanTools.getRegistry(); 94 ManagedBean managed = registry.findManagedBean(getMBeanType()); 96 try { 97 ModelMBean model = managed.createMBean(this); 99 server.registerMBean(model, realObjectName); 100 } catch (Exception e) { 101 log.log(BasicLevel.DEBUG, "Should never goes here", e); 103 } 104 105 List childs = getChildsMBeans(); 107 if (childs != null) { 108 for (Iterator i = childs.iterator(); i.hasNext();) { 109 AbstractWebServiceMBean child = (AbstractWebServiceMBean) i.next(); 110 child.register(server); 111 } 112 } 113 } 114 115 118 protected abstract String getMBeanType(); 119 120 123 public void unregister() { 124 unregister(getMBeanServer()); 125 } 126 127 131 public void unregister(MBeanServer server) { 132 try { 134 server.unregisterMBean(ObjectName.getInstance(getObjectName())); 135 } catch (Exception e) { 136 log.log(BasicLevel.DEBUG, "Should never goes here", e); 138 } 139 140 List childs = getChildsMBeans(); 142 if (childs != null) { 143 for (Iterator i = childs.iterator(); i.hasNext();) { 144 AbstractWebServiceMBean child = (AbstractWebServiceMBean) i.next(); 145 child.unregister(server); 146 } 147 } 148 } 149 150 153 protected abstract List getChildsMBeans(); 154 155 158 private MBeanServer getMBeanServer() { 159 ServiceManager sm; 160 try { 161 sm = ServiceManager.getInstance(); 162 } catch (Exception e) { 163 throw new IllegalStateException ( 165 "Cannot get ServiceManager inside JOnAS !"); 166 } 167 MBeanServer server = ((JmxService) sm.getJmxService()).getJmxServer(); 168 return server; 169 } 170 171 174 public ObjectName getRealObjectName() { 175 return this.realObjectName; 176 } 177 } 178 | Popular Tags |