1 22 package org.jboss.ejb3; 23 24 import javax.management.DynamicMBean ; 25 import javax.management.MBeanServer ; 26 import javax.management.ObjectName ; 27 import org.jboss.deployment.DeploymentInfo; 28 import org.jboss.mx.util.MBeanProxyExt; 29 import org.jboss.system.ServiceControllerMBean; 30 import org.jboss.system.ServiceMBeanSupport; 31 import org.jboss.logging.Logger; 32 33 39 public class JmxKernelAbstraction 40 extends JmxClientKernelAbstraction 41 implements KernelAbstraction 42 { 43 private static final Logger log = Logger.getLogger(JmxKernelAbstraction.class); 44 45 private MBeanServer server; 46 private ServiceControllerMBean serviceController; 47 private DeploymentInfo di; 48 49 public JmxKernelAbstraction(DeploymentInfo di) 50 { 51 super(di.getServer()); 52 this.server = di.getServer(); 53 serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME, 54 di.getServer()); 55 this.di = di; 56 } 57 58 public JmxKernelAbstraction(MBeanServer server) 59 { 60 super(server); 61 serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME, 62 server); 63 } 64 65 public void setMbeanServer(MBeanServer server) 66 { 67 this.server = server; 68 } 69 70 71 public void install(String name, DependencyPolicy dependencies, Object service) 72 { 73 if (!(service instanceof ServiceMBeanSupport) && !(service instanceof DynamicMBean )) 74 { 75 log.debug("creating wrapper delegate for: " + service.getClass().getName()); 76 service = new ServiceDelegateWrapper(service); 78 } 79 JmxDependencyPolicy policy = (JmxDependencyPolicy)dependencies; 80 try 81 { 82 log.info("installing MBean: " + name + " with dependencies:"); 83 for (Object obj : policy.getDependencies()) 84 { 85 log.info("\t" + obj); 86 } 87 ObjectName on = new ObjectName (name); 88 89 if(policy.getDependencies().contains(on)) 90 throw new IllegalStateException ("circular dependencies detected"); 91 92 server.registerMBean(service, on); 93 addParentDependency(on); 94 95 serviceController.create(on, policy.getDependencies()); 96 serviceController.start(on); 97 } 98 catch (Exception e) 99 { 100 throw new RuntimeException (e); 101 } 102 } 103 104 private void addParentDependency(ObjectName on) 105 { 106 108 DeploymentInfo parent = di; 113 while (parent.parent != null) 114 { 115 parent = parent.parent; 116 } 117 parent.mbeans.add(on); 118 119 } 120 121 private void removeParentDependency(ObjectName on) 122 { 123 DeploymentInfo parent = di; 124 while (parent.parent != null) 125 { 126 parent = parent.parent; 127 } 128 parent.mbeans.remove(on); 129 } 130 131 public void installMBean(ObjectName on, DependencyPolicy dependencies, Object service) 132 { 133 JmxDependencyPolicy policy = (JmxDependencyPolicy)dependencies; 134 try 135 { 136 server.registerMBean(service, on); 137 addParentDependency(on); 138 serviceController.create(on, policy.getDependencies()); 139 serviceController.start(on); 140 } 141 catch (Exception e) 142 { 143 throw new RuntimeException (e); 144 } 145 } 146 147 public void uninstallMBean(ObjectName on) 148 { 149 try 150 { 151 serviceController.stop(on); 152 serviceController.destroy(on); 153 serviceController.remove(on); 154 removeParentDependency(on); 155 if(server.isRegistered(on)) 156 server.unregisterMBean(on); 157 else 158 log.warn(on + " is not registered"); 159 } 160 catch (Exception e) 161 { 162 throw new RuntimeException (e); 163 } 164 } 165 166 public void uninstall(String name) 167 { 168 ObjectName on; 169 try 170 { 171 on = new ObjectName (name); 172 } 173 catch (Exception e) 174 { 175 throw new RuntimeException (e); 176 } 177 178 uninstallMBean(on); 179 } 180 } 181 | Popular Tags |