[jboss-cvs] JBossAS SVN: r87850 - in branches/Branch_5_x: profileservice/src/main/org/jboss/profileservice/remoting and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 27 03:22:19 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-04-27 03:22:18 -0400 (Mon, 27 Apr 2009)
New Revision: 87850

Modified:
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationDelegate.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationProxyFactory.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java
   branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentManagedObjectCreator.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/ServerInfo.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/BootstrapDeployment.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java
Log:
JBAS-6618, stats and operations of the bootstrap deployment beans were not being associated with runtime components

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -32,9 +32,11 @@
 import org.jboss.managed.api.ManagedOperation;
 import org.jboss.managed.api.ManagedParameter;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.values.EnumValueSupport;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
 import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.profileservice.spi.types.ControllerStateMetaType;
 
 /**
  * Microcontainer KernelBus runtime component dispatcher.
@@ -76,9 +78,9 @@
 
    public MetaValue get(Object componentName, String propertyName)
    {
+      ManagedProperty prop = AbstractRuntimeComponentDispatcher.getActiveProperty();
       try
       {
-         ManagedProperty prop = AbstractRuntimeComponentDispatcher.getActiveProperty();
          Object value = bus.get(componentName, propertyName);
          MetaValue mvalue = null;
          if(value != null)
@@ -100,7 +102,16 @@
       }
       catch (Throwable t)
       {
-         throw new UndeclaredThrowableException(t, "Failed to get property '" + propertyName + "' on component '" + componentName + "'.");
+         if(propertyName.equals("state") && prop.getMetaType().equals(ControllerStateMetaType.TYPE))
+         {
+            String stateString = getState(componentName);
+            EnumValueSupport state = new EnumValueSupport(ControllerStateMetaType.TYPE, stateString);
+            return state;
+         }
+         else
+         {
+            throw new UndeclaredThrowableException(t, "Failed to get property '" + propertyName + "' on component '" + componentName + "'.");
+         }
       }
    }
 

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationDelegate.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationDelegate.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationDelegate.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -54,6 +54,11 @@
       this.dispatcherProxy = dispatcherProxy;
    }
 
+   public long getOpID()
+   {
+      return opID;
+   }
+
    public MetaValue invoke(MetaValue... metaValues)
    {
       MetaValue mvalue = dispatcherProxy.invoke(opID, componentName, delegate.getName(), metaValues);

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationProxyFactory.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationProxyFactory.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationProxyFactory.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -150,6 +150,16 @@
       HashSet<ManagedOperation> opProxies = new HashSet<ManagedOperation>();
       for (ManagedOperation op : ops)
       {
+         // If this is already oa delegage just use it
+         if(op instanceof ManagedOperationDelegate)
+         {
+            opProxies.add(op);
+            ManagedOperationDelegate proxy = (ManagedOperationDelegate) op;
+            // Make sure the proxy is in the operations map since clear() may have removed it
+            long opID = proxy.getOpID();
+            this.operations.put(opID, proxy);
+            continue;
+         }
          long opID = operationID.incrementAndGet();
          ManagedOperationDelegate proxy = new ManagedOperationDelegate(opID, op, componentName, dispatcherProxy);
          this.operations.put(opID, proxy);

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -261,7 +261,7 @@
       }
       catch(Exception e)
       {
-         log.warn("Failed to process ManagedDeployments for the platform beans");
+         log.warn("Failed to process ManagedDeployments for the platform beans", e);
       }
 
       if(wasInterrupted)
@@ -455,7 +455,7 @@
       // See if this is a runtime ManagedObject
       Map<String, Annotation> moAnns = mo.getAnnotations();
       ManagementObject managementObject = (ManagementObject) moAnns.get(ManagementObject.class.getName());
-      if (managementObject.isRuntime())
+      if (managementObject != null && managementObject.isRuntime())
       {
          boolean merged = false;
          ManagementComponent mc = managementObject.componentType();
@@ -1350,39 +1350,30 @@
          // We need to pull the runtime values for stats
          for(ManagedProperty prop : runtimeProps.values())
          {
-            Map<String, Annotation> pannotations = prop.getAnnotations();
-            if(pannotations != null)
+            if(prop.hasViewUse(ViewUse.STATISTIC))
             {
-               ManagementProperty mpa = (ManagementProperty) pannotations.get(ManagementProperty.class.getName());
-               ViewUse[] uses = mpa.use();
-               for(ViewUse use : uses)
+               String propName = prop.getMappedName();
+               try
                {
-                  if(use == ViewUse.STATISTIC)
-                  {
-                     String propName = prop.getMappedName();
-                     try
-                     {
-                        AbstractRuntimeComponentDispatcher.setActiveProperty(prop);
-                        MetaValue propValue = dispatcher.get(componentName, propName);
-                        if(propValue != null)
-                           prop.setValue(propValue);
-                     }
-                     catch(Throwable t)
-                     {
-                        log.debug("Failed to get stat value, "+componentName+":"+propName);
-                     }
-                     ManagedProperty proxiedProp = createPropertyProxy(prop);
-                     props.put(prop.getName(), proxiedProp);
-                  }
-                  else
-                  {
-                     props.put(prop.getName(), prop);
-                  }
+                  AbstractRuntimeComponentDispatcher.setActiveProperty(prop);
+                  MetaValue propValue = dispatcher.get(componentName, propName);
+                  if(propValue != null)
+                     prop.setValue(propValue);
                }
-               // Keep the property associated with the runtime MO for invocations/updates
-               if (prop.getTargetManagedObject() == null)
-                  prop.setTargetManagedObject(runtimeMO);
+               catch(Throwable t)
+               {
+                  log.debug("Failed to get stat value, "+componentName+":"+propName);
+               }
+               ManagedProperty proxiedProp = createPropertyProxy(prop);
+               props.put(prop.getName(), proxiedProp);
             }
+            else
+            {
+               props.put(prop.getName(), prop);
+            }
+            // Keep the property associated with the runtime MO for invocations/updates
+            if (prop.getTargetManagedObject() == null)
+               prop.setTargetManagedObject(runtimeMO);
          }
          
          log.debug("Properties after:"+props);

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -45,13 +45,15 @@
  * interfaces.
  * 
  * @author Scott.Stark at jboss.org
- * @version $Revision:$
+ * @version $Revision$
  */
 public class ProxyFactory
 {
    private static final Logger log = Logger.getLogger(ProxyFactory.class);
    private String dispatchName = "ProfileService";
    private String jndiName = "ProfileService";
+   private String mgtViewJndiName = "java:ManagementView";
+   private String deployMgrJndiName = "java:DeploymentManager";
    private InvokerLocator locator;
    private ProfileService ps;
    private ManagementView mgtView;
@@ -81,6 +83,27 @@
       this.jndiName = jndiName;
    }
 
+   
+   public String getMgtViewJndiName()
+   {
+      return mgtViewJndiName;
+   }
+
+   public void setMgtViewJndiName(String mgtViewJndiName)
+   {
+      this.mgtViewJndiName = mgtViewJndiName;
+   }
+
+   public String getDeployMgrJndiName()
+   {
+      return deployMgrJndiName;
+   }
+
+   public void setDeployMgrJndiName(String deployMgrJndiName)
+   {
+      this.deployMgrJndiName = deployMgrJndiName;
+   }
+
    public InvokerLocator getLocator()
    {
       return locator;
@@ -164,7 +187,7 @@
       psProxy = Remoting.createRemoteProxy(dispatchName, loader, ifaces, locator, proxyInterceptors, "ProfileService");
       InitialContext ctx = new InitialContext();
       Util.bind(ctx, jndiName, psProxy);
-      log.debug("Bound ProfileService proxy");
+      log.debug("Bound ProfileService proxy under: "+jndiName);
 
       // Create the ManagementView proxy
       Class[] mvIfaces = {ManagementView.class};
@@ -172,6 +195,11 @@
       Dispatcher.singleton.registerTarget(mvDispatchName, mgtView);
       mgtViewProxy = Remoting.createRemoteProxy(mvDispatchName, loader, mvIfaces, locator, proxyInterceptors, "ProfileService");
       log.debug("Created ManagementView proxy");
+      if(mgtViewJndiName != null && mgtViewJndiName.length() > 0)
+      {
+         Util.bind(ctx, mgtViewJndiName, mgtViewProxy);
+         log.debug("Bound ManagementView proxy under: "+mgtViewJndiName);
+      }
 
       // Create the DeploymentManager proxy
       Class[] dmIfaces = {DeploymentManager.class};
@@ -179,6 +207,11 @@
       Dispatcher.singleton.registerTarget(dmDispatchName, deployMgr);
       deployMgrProxy = Remoting.createRemoteProxy(dmDispatchName, loader, dmIfaces, locator, proxyInterceptors, "DeploymentManager");
       log.debug("Created DeploymentManager proxy");      
+      if(deployMgrJndiName != null && deployMgrJndiName.length() > 0)
+      {
+         Util.bind(ctx, deployMgrJndiName, deployMgrProxy);
+         log.debug("Bound DeploymentManager proxy under: "+deployMgrJndiName);
+      }
    }
 
    public void stop()
@@ -190,5 +223,15 @@
       InitialContext ctx = new InitialContext();
       Util.unbind(ctx, jndiName);
       log.debug("Unbound ProfileService proxy");
+      if(mgtViewJndiName != null && mgtViewJndiName.length() > 0)
+      {
+         Util.unbind(ctx, mgtViewJndiName);
+         log.debug("Unbound ManagementView proxy");
+      }
+      if(deployMgrJndiName != null && deployMgrJndiName.length() > 0)
+      {
+         Util.unbind(ctx, deployMgrJndiName);
+         log.debug("Unbound DeploymentManager proxy");
+      }
    }
 }

Modified: branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentManagedObjectCreator.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentManagedObjectCreator.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentManagedObjectCreator.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -41,6 +41,7 @@
 import org.jboss.managed.api.MutableManagedObject;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
 import org.jboss.managed.plugins.ManagedPropertyImpl;
 import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
 import org.jboss.metadata.spi.MetaData;
@@ -119,7 +120,10 @@
             
             ManagedObject bmdfMO = mof.initManagedObject(bmdf, metaData);
             if(bmdfMO == null)
-               continue;
+            {
+               // Create a container managed object
+               bmdfMO = createFactoryManagedObject(bmdf, deploymentMO, metaData);
+            }
 
             if((bmdfMO instanceof MutableManagedObject) == false)
             {
@@ -184,6 +188,16 @@
       beanFactoriesMP.getFields().setField(Fields.VALUE, values);
    }
 
+   protected ManagedObject createFactoryManagedObject(BeanMetaDataFactory bmdf,
+         ManagedObject parent, MetaData metaData)
+   {
+      ManagedObjectImpl bmdfMO = new ManagedObjectImpl(bmdf.getClass().getName());
+      Map<String, ManagedProperty> newProps = new HashMap<String, ManagedProperty>();
+      bmdfMO.setParent(parent);
+      bmdfMO.setProperties(newProps);
+      return bmdfMO;
+   }
+
    /**
     * 
     * @param bmd
@@ -221,6 +235,7 @@
       DefaultFieldsImpl fields = new DefaultFieldsImpl();
       fields.setMetaType(type);
       fields.setName(name);
+      fields.setField(Fields.MAPPED_NAME, name);
       fields.setMandatory(false);
       fields.setDescription("The bean controller state");
 

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/ServerInfo.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/ServerInfo.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/ServerInfo.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -45,8 +45,13 @@
 import javax.management.openmbean.CompositeData;
 
 import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedOperation.Impact;
 import org.jboss.managed.api.annotation.ManagementComponent;
 import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementParameter;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ViewUse;
 import org.jboss.util.platform.Java;
 
 /**
@@ -214,51 +219,61 @@
    //                            Server Information                         //
    ///////////////////////////////////////////////////////////////////////////
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getJavaVersion()
    {
       return System.getProperty("java.version");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getJavaVendor()
    {
       return System.getProperty("java.vendor");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getJavaVMName()
    {
       return System.getProperty("java.vm.name");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getJavaVMVersion()
    {
       return System.getProperty("java.vm.version");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getJavaVMVendor()
    {
       return System.getProperty("java.vm.vendor");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getOSName()
    {
       return System.getProperty("os.name");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getOSVersion()
    {
       return System.getProperty("os.version");
    }
 
+   @ManagementProperty(use={ViewUse.RUNTIME}, readOnly=true)
    public String getOSArch()
    {
       return System.getProperty("os.arch");
    }
    
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public Long getTotalMemory()
    {
       return new Long(Runtime.getRuntime().totalMemory());
    }
    
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public Long getFreeMemory()
    {
       return new Long(Runtime.getRuntime().freeMemory());
@@ -268,6 +283,7 @@
     * Returns <tt>Runtime.getRuntime().maxMemory()<tt> on 
     * JDK 1.4 vms or -1 on previous versions.
     */
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public Long getMaxMemory()
    {
       if (Java.isCompatible(Java.VERSION_1_4)) {
@@ -292,6 +308,7 @@
     * Returns <tt>Runtime.getRuntime().availableProcessors()</tt> on 
     * JDK 1.4 vms or -1 on previous versions.
     */
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public Integer getAvailableProcessors()
    {
       if (Java.isCompatible(Java.VERSION_1_4)) {
@@ -315,6 +332,7 @@
    /**
     * Returns InetAddress.getLocalHost().getHostName();
     */
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public String getHostName()
    {
       if (hostName == null)
@@ -336,6 +354,7 @@
    /**
     * Returns InetAddress.getLocalHost().getHostAddress();
     */
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public String getHostAddress()
    {
       if (hostAddress == null)
@@ -359,6 +378,9 @@
     * 
     * @param fancy produce a text-based graph when true
     */
+   @ManagementOperation(description="Return a listing of the thread pools on jdk5+",
+         impact=Impact.ReadOnly,
+         params={@ManagementParameter(name="fancy", description="produce a text-based graph when true")})
    public String listMemoryPools(boolean fancy)
    {
       StringBuffer sbuf = new StringBuffer(4196);
@@ -420,12 +442,14 @@
       
       return sbuf.toString();      
    }
-      
+
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public Integer getActiveThreadCount()
    {
       return new Integer(getRootThreadGroup().activeCount());
    }
 
+   @ManagementProperty(use={ViewUse.STATISTIC}, readOnly=true)
    public Integer getActiveThreadGroupCount()
    {
       return new Integer(getRootThreadGroup().activeGroupCount());
@@ -434,6 +458,8 @@
    /**
     * Return a listing of the active threads and thread groups.
     */
+   @ManagementOperation(description="Return a listing of the active threads and thread groups",
+         impact=Impact.ReadOnly)
    public String listThreadDump()
    {
       ThreadGroup root = getRootThreadGroup();
@@ -464,6 +490,8 @@
    /**
     * Return a listing of the active threads and thread groups.
     */
+   @ManagementOperation(description="Return a listing of the active threads and thread groups",
+         impact=Impact.ReadOnly)
    public String listThreadCpuUtilization()
    {
       Set threads = getThreadCpuUtilization(); 

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/BootstrapDeployment.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/BootstrapDeployment.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/BootstrapDeployment.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -35,6 +35,10 @@
 import org.jboss.kernel.spi.deployment.KernelDeployment;
 
 /**
+ * A DeploymentUnit for exposing the MCServer deployments
+ * 
+ * @see org.jboss.bootstrap.spi.microcontainer.MCServer#getDeployments
+ * 
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -21,6 +21,7 @@
  */
 package org.jboss.system.server.profileservice;
 
+import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -35,6 +36,7 @@
 
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
 import org.jboss.bootstrap.spi.Bootstrap;
 import org.jboss.bootstrap.spi.Server;
 import org.jboss.bootstrap.spi.ServerConfig;
@@ -58,25 +60,32 @@
 import org.jboss.kernel.spi.registry.KernelRegistryPlugin;
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.Fields;
 import org.jboss.managed.api.ManagedDeployment;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedOperation;
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.MutableManagedObject;
 import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementConstants;
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ViewUse;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.plugins.DefaultFieldsImpl;
 import org.jboss.managed.plugins.ManagedComponentImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
 import org.jboss.managed.plugins.ManagedOperationImpl;
 import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
 import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
 import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.CollectionValueSupport;
 import org.jboss.metatype.api.values.EnumValue;
 import org.jboss.metatype.api.values.EnumValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
 import org.jboss.profileservice.spi.MutableProfile;
 import org.jboss.profileservice.spi.NoSuchProfileException;
 import org.jboss.profileservice.spi.Profile;
@@ -410,14 +419,13 @@
       Map<String, KernelDeployment> serverDeployments = null;
       if(server instanceof MCServer)
       {
+         // Build ManagedDeployments for the KernelDeployments
          MCServer mcserver = MCServer.class.cast(server);
          Kernel kernel = mcserver.getKernel();
          serverDeployments = mcserver.getDeployments();
          ManagedDeployment firstDeployment = null;
          for(KernelDeployment kd : serverDeployments.values())
          {
-            ManagedObject kdMO = mof.initManagedObject(kd, null);
-            Map<String, ManagedObject> kdMOs = Collections.singletonMap(kd.getName(), kdMO);
             BootstrapDeployment deploymentUnit = new BootstrapDeployment(kd);
             KernelDeploymentVisitor visitor = new KernelDeploymentVisitor();
             try
@@ -429,9 +437,20 @@
                log.debug("Failed to build ManagedDeployment for: "+kd, e);
                continue;
             }
-            ManagedDeployment md = mgtDeploymentCreator.build(deploymentUnit, kdMOs, null);
-            if(firstDeployment == null)
-               firstDeployment = md;
+
+            /* Create minimal deployment ManagedObject. Don't use the ManagedObjectFactory
+             * as this will create ManagedObjects for the beans via the beansFactory
+             * property. We handle the beans below.
+            */
+            Set<ManagedProperty> kdProperties = new HashSet<ManagedProperty>();
+            HashSet<ManagedOperation> ops = null;
+            ManagedObject kdMO = new ManagedObjectImpl(kd.getName(), "",
+                  KernelDeployment.class.getName(),
+                  kdProperties, ops, (Serializable) kd);
+            Map<String, ManagedObject> kdMOs = new HashMap<String, ManagedObject>();
+            kdMOs.put(kd.getName(), kdMO);
+
+            // Traverse the deployment components 
             for(DeploymentUnit compUnit : deploymentUnit.getComponents())
             {
                BeanMetaData bmd = compUnit.getAttachment(BeanMetaData.class);
@@ -445,17 +464,17 @@
                if(bmdMO instanceof MutableManagedObject)
                {
                   MutableManagedObject mmo = (MutableManagedObject) bmdMO;
-                  if(mo != null && mo.name().length() > 0)
+                  if(mo != null && mo.name().length() > 0 && mo.name().equals(ManagementConstants.GENERATED) == false)
                      mmo.setName(mo.name());
                   else
                      mmo.setName(bmd.getName());
                   mmo.setParent(kdMO);
                   // Add an alias property
                   Set<Object> bmdAliases = bmd.getAliases();
+                  Map<String, ManagedProperty> oldProps = mmo.getProperties();
+                  Map<String, ManagedProperty> newProps = new HashMap<String, ManagedProperty>(oldProps);
                   if(bmdAliases != null && bmdAliases.size() > 0)
                   {
-                     Map<String, ManagedProperty> oldProps = mmo.getProperties();
-                     Map<String, ManagedProperty> newProps = new HashMap<String, ManagedProperty>(oldProps);
                      ArrayMetaType aliasType = new ArrayMetaType(SimpleMetaType.STRING, false);
                      DefaultFieldsImpl fields = getFields("alias", aliasType);
                      fields.setDescription("Aliases of the bean");
@@ -469,21 +488,34 @@
                      fields.setValue(value);
                      ManagedPropertyImpl aliasesMP = new ManagedPropertyImpl(bmdMO, fields);
                      newProps.put("alias", aliasesMP);
-                     // Add a state property
-                     DefaultFieldsImpl stateFields = getFields("state", ControllerStateMetaType.TYPE);
-                     stateFields.setViewUse(new ViewUse[]{ViewUse.STATISTIC});
-                     EnumValue stateValue = getState(bmd.getName(), kernel);
-                     stateFields.setValue(stateValue);
-                     stateFields.setDescription("The bean controller state");
-                     ManagedPropertyImpl stateMP = new ManagedPropertyImpl(mmo, stateFields);
-                     newProps.put("state", stateMP);
-                     // Update the properties
-                     mmo.setProperties(newProps);
                   }
+                  // Add a state property
+                  DefaultFieldsImpl stateFields = getFields("state", ControllerStateMetaType.TYPE);
+                  stateFields.setViewUse(new ViewUse[]{ViewUse.STATISTIC});
+                  EnumValue stateValue = getState(bmd.getName(), kernel);
+                  stateFields.setValue(stateValue);
+                  stateFields.setDescription("The bean controller state");
+                  ManagedPropertyImpl stateMP = new ManagedPropertyImpl(mmo, stateFields);
+                  newProps.put("state", stateMP);
+                  // Update the properties
+                  mmo.setProperties(newProps);
                }
                log.debug("Created ManagedObject: "+bmdMO+" for bean: "+bmd.getName());
+               kdMOs.put(bmd.getName(), bmdMO);
 
+            }
+            // Create the ManagedDeployment
+            ManagedDeployment md = mgtDeploymentCreator.build(deploymentUnit, kdMOs, null);
+            if(firstDeployment == null)
+               firstDeployment = md;
+            // Create the ManagedComponents
+            for(ManagedObject bmdMO : kdMOs.values())
+            {
+               if(bmdMO.getAttachmentName().equals(KernelDeployment.class.getName()))
+                  continue;
+
                ComponentType type = KnownComponentTypes.MCBean.Any.getType();
+               Map<String, Annotation> moAnns = bmdMO.getAnnotations();
                ManagementComponent mc = (ManagementComponent) moAnns.get(ManagementComponent.class.getName());
                if(mc != null)
                {
@@ -491,8 +523,9 @@
                }
                ManagedComponentImpl comp = new ManagedComponentImpl(type, md, bmdMO);
                md.addComponent(bmdMO.getName(), comp);
-               log.debug("Created ManagedComponent of type: "+type+" for bean: "+bmd.getName());
+               log.debug("Created ManagedComponent of type: "+type+" for bean: "+bmdMO.getName());               
             }
+
             if(md != null)
                bootstrapMDs.put(kd.getName(), md);
          }
@@ -547,10 +580,12 @@
       DefaultFieldsImpl fields = new DefaultFieldsImpl();
       fields.setMetaType(type);
       fields.setName(name);
+      fields.setField(Fields.MAPPED_NAME, name);
       fields.setMandatory(false);
 
       return fields;
    }
+
    /**
     * Get the state of a bean
     * 

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java	2009-04-27 00:45:29 UTC (rev 87849)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java	2009-04-27 07:22:18 UTC (rev 87850)
@@ -39,6 +39,7 @@
 import org.jboss.managed.plugins.ManagedOperationMatcher;
 import org.jboss.metatype.api.types.EnumMetaType;
 import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.metatype.api.values.EnumValue;
 import org.jboss.metatype.api.values.EnumValueSupport;
 import org.jboss.metatype.api.values.MetaValue;
@@ -73,6 +74,7 @@
       throws Exception
    {
       ManagementView mgtView = getManagementView();
+      mgtView.reload();
       ComponentType type = new ComponentType("MCBean", "ServerInfo");
       getLog().debug("MCBeans: "+mgtView.getComponentsForType(type));
       ManagedComponent mc = mgtView.getComponent("jboss.system:type=ServerInfo", type);
@@ -110,6 +112,33 @@
       long activeThreadGroupCountValue = getLong(activeThreadGroupCount);
       assertTrue("activeThreadGroupCount > 0", activeThreadGroupCountValue > 0);
       
+      // Operations
+      Set<ManagedOperation> ops = mc.getOperations();
+      log.info("ServerInfo.ops: "+ ops);
+      ManagedOperation listThreadCpuUtilization = ManagedOperationMatcher.findOperation(ops, "listThreadCpuUtilization");
+      assertNotNull(listThreadCpuUtilization);
+      MetaValue listThreadCpuUtilizationMV = listThreadCpuUtilization.invoke();
+      // TODO
+      assertNotNull(listThreadCpuUtilizationMV);
+      assertEquals(SimpleMetaType.STRING, listThreadCpuUtilizationMV.getMetaType());
+      SimpleValue listThreadCpuUtilizationSV = (SimpleValue) listThreadCpuUtilizationMV;
+      String cpuUtilization = (String) listThreadCpuUtilizationSV.getValue();
+      log.info(cpuUtilization);
+      assertTrue(cpuUtilization.length() > 100);
+      
+
+      // Try invoking listThreadCpuUtilization and checking freeMemory until it changes
+      long currentFreeMemoryValue = freeMemoryValue;
+      for(int n = 0; n < 100; n ++)
+      {
+         listThreadCpuUtilization.invoke();
+         currentFreeMemoryValue = getLong(freeMemory);
+         if(currentFreeMemoryValue != freeMemoryValue)
+            break;
+      }
+      assertTrue("currentFreeMemoryValue != original freeMemoryValue",
+            currentFreeMemoryValue != freeMemoryValue);
+
       // The bean state
       ManagedProperty state = props.get("state");
       assertNotNull("state", state);




More information about the jboss-cvs-commits mailing list