[jboss-cvs] JBossAS SVN: r74095 - trunk/system-jmx/src/main/org/jboss/system.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 4 08:31:40 EDT 2008


Author: adrian at jboss.org
Date: 2008-06-04 08:31:40 -0400 (Wed, 04 Jun 2008)
New Revision: 74095

Modified:
   trunk/system-jmx/src/main/org/jboss/system/ServiceMBeanSupport.java
Log:
[JBAS-5578] - Redirect JMX operations to the MC when registered as a POJO - add POJO lifecycle callbacks to differentiate callbacks from the MC from invocations using the JMX interface

Modified: trunk/system-jmx/src/main/org/jboss/system/ServiceMBeanSupport.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/ServiceMBeanSupport.java	2008-06-04 12:30:04 UTC (rev 74094)
+++ trunk/system-jmx/src/main/org/jboss/system/ServiceMBeanSupport.java	2008-06-04 12:31:40 UTC (rev 74095)
@@ -30,8 +30,18 @@
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
+import org.jboss.beans.metadata.api.annotations.Create;
+import org.jboss.beans.metadata.api.annotations.Destroy;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.beans.metadata.api.annotations.Start;
+import org.jboss.beans.metadata.api.annotations.Stop;
+import org.jboss.beans.metadata.api.model.FromContext;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployment.DeploymentInfo;
 import org.jboss.deployment.SARDeployerMBean;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
 import org.jboss.logging.Logger;
 import org.jboss.mx.util.JBossNotificationBroadcasterSupport;
 
@@ -51,7 +61,7 @@
  */
 public class ServiceMBeanSupport
    extends JBossNotificationBroadcasterSupport
-   implements ServiceMBean, MBeanRegistration
+   implements ServiceMBean, MBeanRegistration, KernelControllerContextAware
 {
    /** The signature for service controller operations */
    public static final String[] SERVICE_CONTROLLER_SIG = new String[] { ObjectName.class.getName() };
@@ -74,6 +84,9 @@
 
    /** For backwards compatibility */
    private boolean isJBossInternalLifecycleExposed = false;
+
+   /** The controller context */
+   private KernelControllerContext controllerContext;
    
    /**
     * Construct a <t>ServiceMBeanSupport</tt>.
@@ -94,6 +107,7 @@
     *
     * @param type   The class type to determine category name from.
     */
+   @SuppressWarnings("unchecked")
    public ServiceMBeanSupport(final Class type)
    {
       this(type.getName());
@@ -122,8 +136,26 @@
       log.trace("Constructing");
    }
 
+   @Inject(fromContext=FromContext.CONTEXT)
+   public void setControllerContext(KernelControllerContext controllerContext)
+   {
+      this.controllerContext = controllerContext;
+   }
+   
+   public void setKernelControllerContext(KernelControllerContext controllerContext) throws Exception
+   {
+      this.controllerContext = controllerContext;
+   }
+
+   public void unsetKernelControllerContext(KernelControllerContext controllerContext) throws Exception
+   {
+      this.controllerContext = null;
+   }
+
    /**
     * Use the short class name as the default for the service name.
+    * 
+    * @return a description of the mbean
     */
    public String getName()
    {
@@ -179,10 +211,57 @@
    ///////////////////////////////////////////////////////////////////////////
    //                             State Mutators                            //
    ///////////////////////////////////////////////////////////////////////////
+
+   @Create
+   public void pojoCreate() throws Exception
+   {
+      jbossInternalCreate();
+   }
    
+   @Start
+   public void pojoStart() throws Exception
+   {
+      jbossInternalStart();
+   }
+
+   @Stop
+   public void pojoStop() throws Exception
+   {
+      jbossInternalStop();
+   }
+   
+   @Destroy
+   public void pojoDestroy() throws Exception
+   {
+      jbossInternalDestroy();
+   }
+
+   protected void pojoChange(ControllerState state)
+   {
+      Controller controller = controllerContext.getController();
+      try
+      {
+         controller.change(controllerContext, state);
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Error e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error changing state of " + controllerContext.getName() + " to " + state.getStateString(), t);
+      }
+   }
+   
    public void create() throws Exception
    {
-      if (serviceName != null && isJBossInternalLifecycleExposed)
+      if (controllerContext != null)
+         pojoChange(ControllerState.CREATE);
+      else if (serviceName != null && isJBossInternalLifecycleExposed)
          server.invoke(ServiceController.OBJECT_NAME, "create", new Object[] { serviceName }, SERVICE_CONTROLLER_SIG);
       else
          jbossInternalCreate();
@@ -190,7 +269,9 @@
    
    public void start() throws Exception
    {
-      if (serviceName != null && isJBossInternalLifecycleExposed)
+      if (controllerContext != null)
+         pojoChange(ControllerState.START);
+      else if (serviceName != null && isJBossInternalLifecycleExposed)
          server.invoke(ServiceController.OBJECT_NAME, "start", new Object[] { serviceName }, SERVICE_CONTROLLER_SIG);
       else
          jbossInternalStart();
@@ -200,7 +281,9 @@
    {
       try
       {
-         if (serviceName != null && isJBossInternalLifecycleExposed)
+         if (controllerContext != null)
+            pojoChange(ControllerState.CREATE);
+         else if (serviceName != null && isJBossInternalLifecycleExposed)
             server.invoke(ServiceController.OBJECT_NAME, "stop", new Object[] { serviceName }, SERVICE_CONTROLLER_SIG);
          else
             jbossInternalStop();
@@ -215,7 +298,9 @@
    {
       try
       {
-         if (serviceName != null && isJBossInternalLifecycleExposed)
+         if (controllerContext != null)
+            pojoChange(ControllerState.CONFIGURED);
+         else if (serviceName != null && isJBossInternalLifecycleExposed)
             server.invoke(ServiceController.OBJECT_NAME, "destroy", new Object[] { serviceName }, SERVICE_CONTROLLER_SIG);
          else
             jbossInternalDestroy();
@@ -385,6 +470,8 @@
     * @param name      Name specified by the creator of the MBean. Note that you can
     *                  overwrite it when the given ObjectName is null otherwise the
     *                  change is discarded (maybe a bug in JMX-RI).
+    * @return the ObjectName
+    * @throws Exception for any error
     */
    public ObjectName preRegister(MBeanServer server, ObjectName name)
       throws Exception
@@ -457,6 +544,11 @@
    /**
     * Sub-classes should override this method if they only need to set their
     * object name during MBean pre-registration.
+    * 
+    * @param server the mbeanserver
+    * @param name the suggested name, maybe null
+    * @return the object name
+    * @throws MalformedObjectNameException for a bad object name
     */
    protected ObjectName getObjectName(MBeanServer server, ObjectName name)
       throws MalformedObjectNameException
@@ -471,6 +563,8 @@
     * <p>This method is empty, and is provided for convenience
     *    when concrete service classes do not need to perform
     *    anything specific for this state change.
+    * 
+    * @throws Exception for any error
     */
    protected void createService() throws Exception {}
    
@@ -481,6 +575,8 @@
     * <p>This method is empty, and is provided for convenience
     *    when concrete service classes do not need to perform
     *    anything specific for this state change.
+    * 
+    * @throws Exception for any error
     */
    protected void startService() throws Exception {}
    
@@ -491,6 +587,8 @@
     * <p>This method is empty, and is provided for convenience
     *    when concrete service classes do not need to perform
     *    anything specific for this state change.
+    * 
+    * @throws Exception for any error
     */
    protected void stopService() throws Exception {}
    
@@ -501,6 +599,8 @@
     * <p>This method is empty, and is provided for convenience
     *    when concrete service classes do not need to perform
     *    anything specific for this state change.
+    * 
+    * @throws Exception for any error
     */
    protected void destroyService() throws Exception {}
    




More information about the jboss-cvs-commits mailing list