[jboss-cvs] JBossAS SVN: r64900 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers/deployer/support and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 27 22:06:38 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-08-27 22:06:37 -0400 (Mon, 27 Aug 2007)
New Revision: 64900

Modified:
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/managed/DefaultManagedDeploymentCreator.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
Log:
Handle the mapping of a runtime MangedObject props/ops to the base ManagedObject

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/managed/DefaultManagedDeploymentCreator.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/managed/DefaultManagedDeploymentCreator.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/managed/DefaultManagedDeploymentCreator.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -47,23 +47,6 @@
    /** The metadata type to ManagedComponent handlers */
    private Map<Class, ManagedComponentCreator> mdCreators;
 
-   public ManagedObjectFactory getMoFactory()
-   {
-      return moFactory;
-   }
-   public void setMoFactory(ManagedObjectFactory moFactory)
-   {
-      this.moFactory = moFactory;
-   }
-
-   public <T> void addManagedComponentCreator(ManagedComponentCreator<T> mcc)
-   {
-      Type type = mcc.getClass().getGenericInterfaces()[0];
-      ParameterizedType pt = (ParameterizedType) type;
-      Class ptType = (Class) pt.getActualTypeArguments()[0];
-      mdCreators.put(ptType, mcc);
-   }
-
    public ManagedDeployment build(DeploymentUnit unit,
          Map<String, ManagedObject> unitMOs,
          ManagedDeployment parent)

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -21,6 +21,8 @@
  */
 package org.jboss.test.deployers.deployer.support;
 
+import java.io.Serializable;
+
 import org.jboss.managed.api.ManagedOperation.Impact;
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementObjectID;
@@ -35,7 +37,10 @@
  */
 @ManagementObject(isRuntime=true)
 public class DSServiceMetaData
+   implements Serializable
 {
+   private static final long serialVersionUID = 1;
+
    /** The name of the ManagedObject this runtime view augments */
    private String managementName;
    private String runtimeProp1;
@@ -70,9 +75,14 @@
       this.runtimeProp2 = runtimeProp2;
    }
 
-   @ManagementOperation(description="Flush the connection pool", impact=Impact.WriteOnly)
+   @ManagementOperation(description="Flush the connections in the pool", impact=Impact.WriteOnly)
    public void flushPool()
    {
       
    }
+   @ManagementOperation(description="Close the connections in the pool", impact=Impact.WriteOnly)
+   public void closePool()
+   {
+      
+   }
 }

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -21,6 +21,7 @@
  */
 package org.jboss.test.deployers.managed.support;
 
+import java.lang.annotation.Annotation;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -33,13 +34,14 @@
 import org.jboss.managed.api.ComponentType;
 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.ManagedDeployment.DeploymentPhase;
 import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementObjectID;
 import org.jboss.managed.api.annotation.ManagementObjectRef;
 import org.jboss.managed.plugins.ManagedComponentImpl;
-import org.jboss.managed.plugins.ManagedDeploymentImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
 import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
 import org.jboss.metatype.api.types.ArrayMetaType;
 import org.jboss.metatype.api.types.MetaType;
@@ -60,9 +62,16 @@
    private DeployerClient main;
    /** id/type key to ManagedObject map */
    private Map<String, ManagedObject> moRegistry = new HashMap<String, ManagedObject>();
+   /** The deployment map */
    private Map<String, Deployment> deployments = new HashMap<String, Deployment>();
+   /** The deployment name to ManagedDeployment map */
    private Map<String, ManagedDeployment> managedDeployments = new HashMap<String, ManagedDeployment>();
+   /** The ManagedPropertys with unresolved ManagementObjectRefs */
    private Map<String, Set<ManagedProperty>> unresolvedRefs = new HashMap<String, Set<ManagedProperty>>();
+   /** A map of runtime ManagedObjects needing to be merged with their
+    * mathing ManagedObject.
+    */
+   private Map<String, ManagedObject> runtimeMOs = new HashMap<String, ManagedObject>();
 
    public MockProfileService(DeployerClient main)
    {
@@ -113,6 +122,31 @@
    {
       String key = mo.getName() + "/" + mo.getNameType();
       log.debug("ID for ManagedObject: "+key+", attachmentName: "+mo.getAttachmentName());
+
+      // See if this is a runtime ManagedObject
+      Map<String, Annotation> moAnns = mo.getAnnotations();
+      ManagementObject managementObject = (ManagementObject) moAnns.get(ManagementObject.class.getName());
+      if (managementObject.isRuntime())
+      {
+         // Merge this with the ManagedObject
+         ManagedObject parentMO = moRegistry.get(key);
+         if (parentMO == null)
+         {
+            // Save the runtime mo for merging
+            runtimeMOs.put(key, mo);
+            return;
+         }
+         mergeRuntimeMO(parentMO, mo);
+      }
+      else
+      {
+         // See if there is runtime info to merge
+         ManagedObject runtimeMO = runtimeMOs.get(key);
+         if (runtimeMO != null)
+            mergeRuntimeMO(mo, runtimeMO);
+      }
+
+      // Update the MO registry
       ManagedObject prevMO = moRegistry.put(key, mo);
       if( prevMO != null )
          log.warn("Duplicate mo for key: "+key+", prevMO: "+prevMO);
@@ -120,7 +154,7 @@
       checkForReferences(key, mo);
 
       // Create ManagedComponents for 
-      ManagementComponent mc = (ManagementComponent) mo.getAnnotations().get(ManagementComponent.class.getName());
+      ManagementComponent mc = (ManagementComponent) moAnns.get(ManagementComponent.class.getName());
       if (mc != null)
       {
          ComponentType type = new ComponentType(mc.type(), mc.subtype());
@@ -218,4 +252,30 @@
          unresolvedRefs.remove(key);
       }      
    }
+
+   /**
+    * Merge the runtime props and ops
+    * TODO: need a plugin to access the ManagedObject impl
+    * @param mo
+    * @param runtimeMO
+    */
+   protected void mergeRuntimeMO(ManagedObject mo, ManagedObject runtimeMO)
+   {
+      Map<String, ManagedProperty> moProps = mo.getProperties();
+      Set<ManagedOperation> moOps = mo.getOperations();
+      HashMap<String, ManagedProperty> props = new HashMap<String, ManagedProperty>(moProps);
+      HashSet<ManagedOperation> ops = new HashSet<ManagedOperation>(moOps);
+
+      Map<String, ManagedProperty> runtimeProps = runtimeMO.getProperties();
+      Set<ManagedOperation> runtimeOps = runtimeMO.getOperations();
+
+      if (runtimeProps != null)
+         props.putAll(runtimeProps);
+      if (runtimeOps != null)
+         ops.addAll(runtimeOps);
+
+      ManagedObjectImpl moi = (ManagedObjectImpl) mo;
+      moi.setProperties(props);
+      moi.setOperations(ops);
+   }
 }

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -21,10 +21,7 @@
 */
 package org.jboss.test.deployers.managed.test;
 
-import java.lang.annotation.Annotation;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -33,31 +30,25 @@
 
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.plugins.attachments.AttachmentsImpl;
 import org.jboss.deployers.spi.attachments.MutableAttachments;
-import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
 import org.jboss.managed.api.ComponentType;
 import org.jboss.managed.api.ManagedComponent;
 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.factory.ManagedObjectFactory;
-import org.jboss.metatype.api.values.ArrayValue;
 import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.reflect.plugins.ClassInfoImpl;
-import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl;
-import org.jboss.reflect.spi.AnnotationValue;
-import org.jboss.reflect.spi.MethodInfo;
 import org.jboss.test.deployers.AbstractDeployerTest;
 import org.jboss.test.deployers.deployer.support.ConnMetaData;
 import org.jboss.test.deployers.deployer.support.DSMetaData;
+import org.jboss.test.deployers.deployer.support.DSServiceMetaData;
 import org.jboss.test.deployers.deployer.support.LocalDataSourceMetaData;
 import org.jboss.test.deployers.deployer.support.MCFDeployer;
 import org.jboss.test.deployers.deployer.support.SecMetaData;
 import org.jboss.test.deployers.deployer.support.SecurityDeployment;
 import org.jboss.test.deployers.deployer.support.XADataSourceMetaData;
 import org.jboss.test.deployers.managed.support.MockProfileService;
-import org.jboss.test.deployers.managed.support.TestManagedObjectDeployer;
 
 /**
  * ManagedDeployment unit tests.
@@ -99,6 +90,7 @@
       // Deploy a datasource with local and xa factories
       Deployment ctx1 = createSimpleDeployment("deployment1");
       DSMetaData dsmd = new DSMetaData();
+      // The base LocalDataSourceMeta
       LocalDataSourceMetaData ds = new LocalDataSourceMetaData();
       ds.setJndiName("java:DefaultDS1");
       ds.setMaxSize(100);
@@ -128,6 +120,10 @@
 
       MutableAttachments a1 = (MutableAttachments) ctx1.getPredeterminedManagedObjects();
       a1.addAttachment(DSMetaData.class, dsmd);
+      // The mbeans associated with the local DS
+      DSServiceMetaData localMBeans = new DSServiceMetaData();
+      localMBeans.setManagementName("java:DefaultDS1");
+      a1.addAttachment(DSServiceMetaData.class, localMBeans);
       ps.addDeployment(ctx1);
 
       // Deploy security domain1
@@ -170,8 +166,9 @@
       // Get the LocalDataSourceMetaData/SecMetaData/domain ManagedProperty
       assertNotNull("LocalDataSourceMetaData MO", localDataMO);
       assertEquals("LocalDataSourceMetaData comp type", new ComponentType("DataSource", "LocalTx"), localDataMO.getType());
-      log.debug("LocalDataSourceMetaData MO.props: "+localDataMO.getProperties());
-      assertNotNull("LocalDataSourceMetaData MO.props", localDataMO.getProperties());
+      Map<String, ManagedProperty> localDataProps = localDataMO.getProperties();
+      log.debug("LocalDataSourceMetaData MO.props: "+localDataProps);
+      assertNotNull("LocalDataSourceMetaData MO.props", localDataProps);
       ManagedProperty localSecDomainProp = localDataMO.getProperty("security-domain");
       assertNotNull("localSecDomainProp", localSecDomainProp);
       GenericValue localSecDomainPropGV = (GenericValue) localSecDomainProp.getValue();
@@ -212,6 +209,26 @@
       assertNotNull("java:/jaas/domain2 MO", sd2MO);
       ManagedObject xaSecDomainPropTarget = xaSecDomainRefProp.getTargetManagedObject();
       assertEquals(sd2MO, xaSecDomainPropTarget);
+
+      // Validate the operations on the localDataMO
+      Set<ManagedOperation> localDataOps = localDataMO.getOperations();
+      assertEquals("localDataOps ops count is 2", 2, localDataOps.size());
+      ManagedOperation flushPool = null;
+      ManagedOperation closePool = null;
+      for(ManagedOperation op : localDataOps)
+      {
+         if (op.getName().equals("flushPool"))
+            flushPool = op;
+         if (op.getName().equals("closePool"))
+            closePool = op;
+      }
+      assertNotNull("flushPool find", flushPool);
+      assertNotNull("closePool find", closePool);
+      // Validate that the localDataMO includes the runtime properties
+      ManagedProperty rtp1 = localDataProps.get("runtimeProp1");
+      assertNotNull("runtimeProp1", rtp1);
+      ManagedProperty rtp2 = localDataProps.get("runtimeProp2");
+      assertNotNull("runtimeProp2", rtp2);      
    }
 
    protected DeployerClient getMainDeployer()

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -27,7 +27,15 @@
 import java.util.Set;
 
 /**
- * ManagedObject.
+ * ManagedObject is an interface for a manageable element. It
+ * consists of:
+ * - a name/name type for a registry/references
+ * - an attachment name to associate the ManagedObject with a
+ *    deployment attachment
+ * - annotations from the metadata making up the ManagedObject
+ * - the attachment instance
+ * - the ManagedPropertys for the interface
+ * - the ManagedOperations for the interface 
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Scott.Stark at jboss.org
@@ -77,7 +85,7 @@
     * @return the property names
     */
    Set<String> getPropertyNames();
-   
+
    /**
     * Get a property
     * 

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -196,6 +196,10 @@
    {
       return properties;
    }
+   public void setProperties(Map<String, ManagedProperty> properties)
+   {
+      this.properties = properties;
+   }
 
    public Serializable getAttachment()
    {
@@ -211,11 +215,19 @@
    {
       this.attachment = attachment;
    }
-   
+
+   /**
+    * get the ManagedOperations
+    * @return 
+    */
    public Set<ManagedOperation> getOperations()
    {
       return operations;
    }
+   public void setOperations(Set<ManagedOperation> operations)
+   {
+      this.operations = operations;
+   }
 
    @Override
    public boolean equals(Object obj)

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2007-08-27 22:00:18 UTC (rev 64899)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2007-08-28 02:06:37 UTC (rev 64900)
@@ -205,6 +205,7 @@
          moAnnotations.put(ManagementObjectID.class.getName(), moID);
 
       // Process the ManagementObject fields
+      boolean isRuntime = managementObject.isRuntime();
       String name = classInfo.getName();
       String nameType = null;
       String attachmentName = classInfo.getName();
@@ -236,6 +237,9 @@
       if (managementObject != null)
          propertyType = managementObject.properties();
 
+      log.debug("Building MangedObject(name="+name+",nameType="+nameType
+            +",attachmentName="+attachmentName+",isRuntime="+isRuntime+")");
+
       // Build the ManagedProperties
       Set<ManagedProperty> properties = new HashSet<ManagedProperty>();
 
@@ -408,6 +412,8 @@
          result.setNameType(nameType);
       if (attachmentName != null)
          result.setAttachmentName(attachmentName);
+      if (operations.size() > 0 )
+         result.setOperations(operations);
       for (ManagedProperty property : properties)
       {
          // FIXME: this either needs to be passed in via the factory or setter added to ManagedProperty




More information about the jboss-cvs-commits mailing list