[jboss-cvs] JBossAS SVN: r89302 - 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
Fri May 22 17:40:32 EDT 2009


Author: alesj
Date: 2009-05-22 17:40:32 -0400 (Fri, 22 May 2009)
New Revision: 89302

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/ServiceProxy.java
Log:
Optimize ServiceProxy a bit;
Introduce JBKERNEL-32 to ServiceControllerContext.

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 20:08:02 UTC (rev 89301)
+++ projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceControllerContext.java	2009-05-22 21:40:32 UTC (rev 89302)
@@ -33,7 +33,7 @@
 import org.jboss.dependency.spi.ControllerMode;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.dependency.spi.DependencyItem;
-import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+import org.jboss.dependency.spi.dispatch.LifecycleDispatchContext;
 import org.jboss.system.Service;
 import org.jboss.system.ServiceContext;
 import org.jboss.system.ServiceController;
@@ -48,7 +48,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
-public class ServiceControllerContext extends AbstractControllerContext implements InvokeDispatchContext
+public class ServiceControllerContext extends AbstractControllerContext implements LifecycleDispatchContext
 {
    /** The ObjectName */
    private ObjectName objectName;
@@ -199,6 +199,11 @@
       }
    }
 
+   public ControllerState lifecycleInvocation(String name, Object[] parameters, String[] signature) throws Throwable
+   {
+      return null; // TODO
+   }
+
    /**
     * Get the ObjectName.
     * 

Modified: projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceProxy.java
===================================================================
--- projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceProxy.java	2009-05-22 20:08:02 UTC (rev 89301)
+++ projects/microcontainer/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ServiceProxy.java	2009-05-22 21:40:32 UTC (rev 89302)
@@ -25,7 +25,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.HashMap;
-
+import java.util.Map;
 import javax.management.MBeanInfo;
 import javax.management.MBeanOperationInfo;
 import javax.management.MBeanServer;
@@ -51,6 +51,7 @@
  * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
  * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
 public class ServiceProxy implements InvocationHandler
@@ -59,7 +60,7 @@
     * A mapping from the Service interface method names to the corresponding
     * index into the ServiceProxy.hasOp array.
     */
-   private static HashMap<String, Integer> serviceOpMap = new HashMap<String, Integer>();
+   private static Map<String, Integer> serviceOpMap = new HashMap<String, Integer>();
 
    // A singleton proxy with no callouts
    private static Service NO_LIFECYCLE_CALLOUT;
@@ -69,10 +70,10 @@
     */
    static
    {
-      serviceOpMap.put("create", new Integer(0));
-      serviceOpMap.put("start", new Integer(1));
-      serviceOpMap.put("destroy", new Integer(2));
-      serviceOpMap.put("stop", new Integer(3));
+      serviceOpMap.put("create", 0);
+      serviceOpMap.put("start", 1);
+      serviceOpMap.put("destroy", 2);
+      serviceOpMap.put("stop", 3);
       Class<?>[] interfaces = { Service.class };
       NO_LIFECYCLE_CALLOUT = (Service) Proxy.newProxyInstance(Service.class.getClassLoader(), interfaces, NoLifecycleCallout.INSTANCE);
    }
@@ -108,17 +109,18 @@
     */
    public static Service getServiceProxy(ObjectName objectName, MBeanServer server, boolean includeLifecycle) throws Exception
    {
-      Service service = null;
-      MBeanInfo info = server.getMBeanInfo(objectName);
-      MBeanOperationInfo[] opInfo = info.getOperations();
-      Class<?>[] interfaces = { Service.class };
-      InvocationHandler handler = new ServiceProxy(objectName, server, opInfo);
-      if (includeLifecycle == false)
-         service = NO_LIFECYCLE_CALLOUT; 
+      if (includeLifecycle)
+      {
+         MBeanInfo info = server.getMBeanInfo(objectName);
+         MBeanOperationInfo[] opInfo = info.getOperations();
+         Class<?>[] interfaces = { Service.class };
+         InvocationHandler handler = new ServiceProxy(objectName, server, opInfo);
+         return (Service) Proxy.newProxyInstance(Service.class.getClassLoader(), interfaces, handler);
+      }
       else
-         service = (Service) Proxy.newProxyInstance(Service.class.getClassLoader(), interfaces, handler);
-
-      return service;
+      {
+         return NO_LIFECYCLE_CALLOUT;
+      }
    }
 
    /**
@@ -135,9 +137,8 @@
       this.server = server;
       this.objectName = objectName;
 
-      for (int op = 0; op < opInfo.length; op++)
+      for (MBeanOperationInfo info : opInfo)
       {
-         MBeanOperationInfo info = opInfo[op];
          String name = info.getName();
 
          if (name.equals(ServiceController.JBOSS_INTERNAL_LIFECYCLE))
@@ -162,7 +163,7 @@
             continue;
          }
 
-         hasOp[opID.intValue()] = true;
+         hasOp[opID] = true;
       }
    }
 
@@ -171,14 +172,13 @@
     * corresponding hasOp array element is true, dispatch the method to the
     * mbean we are proxying.
     *
-    * @param proxy
-    * @param method
-    * @param args
-    * @return             Always null.
-    * @throws Throwable
+    * @param proxy the proxy
+    * @param method the method
+    * @param args the args
+    * @return always null.
+    * @throws Throwable for any error
     */
-   public Object invoke(Object proxy, Method method, Object[] args)
-         throws Throwable
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
       String name = method.getName();
 
@@ -197,7 +197,7 @@
 
       Integer opID = serviceOpMap.get(name);
 
-      if (opID != null && hasOp[opID.intValue()] == true)
+      if (opID != null && hasOp[opID])
       {
          // deal with those pesky JMX exceptions
          try




More information about the jboss-cvs-commits mailing list