[jboss-cvs] JBossAS SVN: r89303 - projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat May 23 06:49:11 EDT 2009


Author: alesj
Date: 2009-05-23 06:49:11 -0400 (Sat, 23 May 2009)
New Revision: 89303

Added:
   projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/LifecycleInfo.java
Modified:
   projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceControllerContext.java
Log:
[JBKERNEL-32]; impl for SCC, todo tests

Added: projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/LifecycleInfo.java
===================================================================
--- projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/LifecycleInfo.java	                        (rev 0)
+++ projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/LifecycleInfo.java	2009-05-23 10:49:11 UTC (rev 89303)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.system.microcontainer;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
+import org.jboss.system.ServiceController;
+
+/**
+ * Holds the needed kernel bus lifecycle invocation info.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class LifecycleInfo
+{
+   private ServiceControllerContext context;
+   private Map<String, StateInfo> lifecycleOps;
+
+   public LifecycleInfo(ServiceControllerContext context) throws Throwable
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+
+      this.context = context;
+      // build possible lifecycle ops
+      lifecycleOps = new HashMap<String, StateInfo>();
+      lifecycleOps.put("create", new StateInfo(false, true, ControllerState.CREATE));
+      lifecycleOps.put("start", new StateInfo(false, true, ControllerState.START));
+      lifecycleOps.put("stop", new StateInfo(false, false, ControllerState.CREATE));
+      lifecycleOps.put("destroy", new StateInfo(false, false, ControllerState.CONFIGURED));
+
+      ServiceController controller = context.getServiceController();
+      MBeanServer server = controller.getMBeanServer();
+      if (server != null)
+      {
+         MBeanInfo info = server.getMBeanInfo(context.getObjectName());
+         MBeanOperationInfo[] ops = info.getOperations();
+         if (ops != null)
+         {
+            for (MBeanOperationInfo op : ops)
+            {
+               String name = op.getName();
+
+               StateInfo flag = lifecycleOps.get(name);
+               if (flag == null)
+               {
+                  continue;
+               }
+
+               // Validate that is a no-arg void return type method
+               if (op.getReturnType().equals("void") == false)
+               {
+                  continue;
+               }
+               if (op.getSignature().length != 0)
+               {
+                  continue;
+               }
+
+               flag.opExists = true;
+            }
+         }
+      }
+   }
+
+   /**
+    * Is this invocation a lifecycle invocation.
+    *
+    * Return state value to which this context should be moved
+    * or return current state if we're already past the lifecycle state
+    * or null if the invocation is actually not a lifecycle invocation.
+    *
+    * @param opName operation name
+    * @param signature method's parameter types / signatures
+    * @return state to which we should move this context, or null if this is not lifecycle invocation
+    * @throws Throwable for any error
+    */
+   public ControllerState lifecycleInvocation(String opName, String[] signature) throws Throwable
+   {
+      if (signature != null && signature.length > 0)
+         return null;
+
+      StateInfo flag = lifecycleOps.get(opName);
+      if (flag == null || flag.opExists == false)
+         return null;
+
+      Controller controller = context.getController();
+      ControllerStateModel model = controller.getStates();
+      ControllerState state = context.getState();
+      if (flag.installPhase)
+      {
+         if (model.isAfterState(flag.state, state))
+            return flag.state;
+         else
+            return state;
+      }
+      else
+      {
+         if (model.isBeforeState(flag.state, state))
+            return flag.state;
+         else
+            return state;
+      }
+   }
+
+   /**
+    * State info holder.
+    */
+   private class StateInfo
+   {
+      boolean opExists;
+      boolean installPhase;
+      ControllerState state;
+
+      private StateInfo(boolean opExists, boolean installPhase, ControllerState state)
+      {
+         this.opExists = opExists;
+         this.installPhase = installPhase;
+         this.state = state;
+      }
+   }
+}

Modified: projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceControllerContext.java
===================================================================
--- projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceControllerContext.java	2009-05-22 21:40:32 UTC (rev 89302)
+++ projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceControllerContext.java	2009-05-23 10:49:11 UTC (rev 89303)
@@ -62,8 +62,11 @@
    /** The service context */
    private ServiceContext serviceContext = new ServiceContext();
 
-   // Whether to include the lifecycle
+   /** Whether to include the lifecycle */
    private boolean includeLifecycle = true;
+
+   /** The lifecycle info */
+   private volatile LifecycleInfo lifecycleInfo;
    
    /**
     * Create a new ServiceControllerContext.
@@ -201,7 +204,10 @@
 
    public ControllerState lifecycleInvocation(String name, Object[] parameters, String[] signature) throws Throwable
    {
-      return null; // TODO
+      if (lifecycleInfo == null)
+         lifecycleInfo = new LifecycleInfo(this);
+
+      return lifecycleInfo.lifecycleInvocation(name, signature);
    }
 
    /**




More information about the jboss-cvs-commits mailing list