[jboss-cvs] JBossAS SVN: r73207 - projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 9 10:12:46 EDT 2008


Author: wolfc
Date: 2008-05-09 10:12:46 -0400 (Fri, 09 May 2008)
New Revision: 73207

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxClientKernelAbstraction.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxDependencyPolicy.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxKernelAbstraction.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/KernelAbstractionFactory.java
Log:
EJBTHREE-1293: reinstated JMX invocations

Copied: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxClientKernelAbstraction.java (from rev 73147, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxClientKernelAbstraction.java)
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxClientKernelAbstraction.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxClientKernelAbstraction.java	2008-05-09 14:12:46 UTC (rev 73207)
@@ -0,0 +1,84 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3;
+
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.JMXExceptionDecoder;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class JmxClientKernelAbstraction implements ClientKernelAbstraction
+{
+   private static final Logger log = Logger.getLogger(JmxKernelAbstraction.class);
+
+   private MBeanServerConnection server;
+
+   public JmxClientKernelAbstraction(MBeanServerConnection server)
+   {
+      this.server = server;
+   }
+   
+   private Exception decode(Exception e)
+   {
+      Throwable t = JMXExceptionDecoder.decode(e);
+      if(t instanceof Exception)
+         return (Exception) t;
+      throw (Error) t;
+   }
+   
+   public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws Exception
+   {
+      try
+      {
+         return server.invoke(name, operationName, params, signature);
+      }
+      catch(Exception e)
+      {
+         throw decode(e);
+      }
+   }
+   
+   public Object getAttribute(ObjectName name, String attribute) throws Exception
+   {
+      try
+      {
+         return server.getAttribute(name, attribute);
+      }
+      catch(Exception e)
+      {
+         throw decode(e);
+      }
+   }
+   
+   public Set getMBeans(ObjectName query) throws Exception
+   {
+      Set mbeans = server.queryMBeans(query, null);
+      
+      return mbeans;
+   }
+}

Copied: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxDependencyPolicy.java (from rev 73147, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxDependencyPolicy.java)
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxDependencyPolicy.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxDependencyPolicy.java	2008-05-09 14:12:46 UTC (rev 73207)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3;
+
+import java.util.Collection;
+import java.util.HashSet;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+/**
+ * Old JMX Kernel dependency registry
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+ at Deprecated
+public class JmxDependencyPolicy implements DependencyPolicy
+{
+   protected HashSet<ObjectName> dependencies = new HashSet<ObjectName>();
+
+   public void addDependency(String dependency)
+   {
+      ObjectName on = null;
+      try
+      {
+         on = new ObjectName(dependency);
+      }
+      catch (MalformedObjectNameException e)
+      {
+         throw new RuntimeException(dependency, e);
+      }
+      dependencies.add(on);
+   }
+
+   public Collection getDependencies()
+   {
+      return dependencies;
+   }
+
+   public Collection getDependencies(Collection currentDependencies)
+   {
+      dependencies.addAll(currentDependencies);
+      return dependencies;
+   }
+
+   public void addDatasource(String jndiName)
+   {
+      String ds = jndiName;
+      if (ds.startsWith("java:/"))
+      {
+         ds = ds.substring(6);
+
+      }
+      else if (ds.startsWith("java:"))
+      {
+         ds = ds.substring(5);
+      }
+      //tring onStr = "jboss.jca:name=" + ds + ",service=ManagedConnectionFactory";
+      String onStr = "jboss.jca:name=" + ds + ",service=DataSourceBinding";
+
+      try
+      {
+         dependencies.add(new ObjectName(onStr));
+      }
+      catch (MalformedObjectNameException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+}

Copied: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxKernelAbstraction.java (from rev 73147, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxKernelAbstraction.java)
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxKernelAbstraction.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/JmxKernelAbstraction.java	2008-05-09 14:12:46 UTC (rev 73207)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3;
+
+import javax.management.DynamicMBean;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import org.jboss.deployment.DeploymentInfo;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.system.ServiceControllerMBean;
+import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class JmxKernelAbstraction
+   extends JmxClientKernelAbstraction
+   implements KernelAbstraction
+{
+   private static final Logger log = Logger.getLogger(JmxKernelAbstraction.class);
+
+   private MBeanServer server;
+   private ServiceControllerMBean serviceController;
+   private DeploymentInfo di;
+
+   public JmxKernelAbstraction(DeploymentInfo di)
+   {
+      super(di.getServer());
+      this.server = di.getServer();
+      serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME,
+            di.getServer());
+      this.di = di;
+   }
+   
+   public JmxKernelAbstraction(MBeanServer server)
+   {
+      super(server);
+      serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME,
+                                                                        server);
+   }
+   
+   public void setMbeanServer(MBeanServer server)
+   {
+      this.server = server;
+   }
+
+
+   public void install(String name, DependencyPolicy dependencies,
+         DeploymentUnit unit, Object service)
+   {
+      if (!(service instanceof ServiceMBeanSupport) && !(service instanceof DynamicMBean))
+      {
+         log.debug("creating wrapper delegate for: " + service.getClass().getName());
+         // create mbean delegate.
+         service = new ServiceDelegateWrapper(service);
+      }
+      JmxDependencyPolicy policy = (JmxDependencyPolicy)dependencies;
+      try
+      {
+         log.info("installing MBean: " + name + " with dependencies:");
+         for (Object obj : policy.getDependencies())
+         {
+            log.info("\t" + obj);
+         }
+         ObjectName on = new ObjectName(name);
+         
+         if(policy.getDependencies().contains(on))
+            throw new IllegalStateException("circular dependencies detected");
+         
+         server.registerMBean(service, on);
+         addParentDependency(on);
+
+         serviceController.create(on, policy.getDependencies());
+         serviceController.start(on);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   private void addParentDependency(ObjectName on)
+   {
+      //di.mbeans.add(on);
+
+      // this is done so that we can get dependency error messages.
+      // and this is the only reason this is done.
+      // if you don't put add to the top DI mbean list, then no dependency
+      // error message is printed out if there is one.
+      DeploymentInfo parent = di;
+      while (parent.parent != null)
+      {
+         parent = parent.parent;
+      }
+      parent.mbeans.add(on);
+
+   }
+   
+   private void removeParentDependency(ObjectName on)
+   {
+      DeploymentInfo parent = di;
+      while (parent.parent != null)
+      {
+         parent = parent.parent;
+      }
+      parent.mbeans.remove(on);
+   }
+
+   public void installMBean(ObjectName on, DependencyPolicy dependencies, Object service)
+   {
+      JmxDependencyPolicy policy = (JmxDependencyPolicy)dependencies;
+      try
+      {
+         server.registerMBean(service, on);
+         addParentDependency(on);
+         serviceController.create(on, policy.getDependencies());
+         serviceController.start(on);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public void uninstallMBean(ObjectName on)
+   {
+      try
+      {
+         serviceController.stop(on);
+         serviceController.destroy(on);
+         serviceController.remove(on);
+         removeParentDependency(on);
+         if(server.isRegistered(on))
+            server.unregisterMBean(on);
+         else
+            log.warn(on + " is not registered");
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public void uninstall(String name)
+   {
+      ObjectName on;
+      try
+      {
+         on = new ObjectName(name);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+      
+      uninstallMBean(on);
+   }
+}

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/KernelAbstractionFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/KernelAbstractionFactory.java	2008-05-09 11:58:19 UTC (rev 73206)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/KernelAbstractionFactory.java	2008-05-09 14:12:46 UTC (rev 73207)
@@ -44,7 +44,12 @@
       if (kernelAbstraction == null)
       {
          MBeanServer mbeanServer = (MBeanServer)getMBeanServer();
-         kernelAbstraction = new MCKernelAbstraction(kernel, mbeanServer);
+         if (kernel != null)
+            kernelAbstraction = new MCKernelAbstraction(kernel, mbeanServer);
+         else
+         {
+            kernelAbstraction = new JmxKernelAbstraction(mbeanServer);
+         }
       }
      
      return kernelAbstraction;
@@ -54,7 +59,15 @@
    {
       if (clientKernelAbstraction == null)
       {
-         clientKernelAbstraction = new MCClientKernelAbstraction(kernel);
+         if (kernel != null)
+         {
+            clientKernelAbstraction = new MCClientKernelAbstraction(kernel);
+         }
+         else
+         {
+            MBeanServerConnection mbeanServer = (MBeanServerConnection)getMBeanServer();
+            clientKernelAbstraction = new JmxClientKernelAbstraction(mbeanServer);
+         }
       }
      
      return clientKernelAbstraction;




More information about the jboss-cvs-commits mailing list