[jboss-cvs] JBossAS SVN: r65117 - in trunk/profileservice/src/main/org/jboss/profileservice: remoting and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 5 15:47:46 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-09-05 15:47:46 -0400 (Wed, 05 Sep 2007)
New Revision: 65117

Modified:
   trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
   trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProfileServiceInvocationHandler.java
   trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java
Log:
Introduce ManagedOperation proxies

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2007-09-05 19:41:34 UTC (rev 65116)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2007-09-05 19:47:46 UTC (rev 65117)
@@ -24,7 +24,7 @@
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.text.MessageFormat;
-import java.util.Collection;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
@@ -34,6 +34,15 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.naming.InitialContext;
+
+import org.jboss.aop.Dispatcher;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.proxy.Proxy;
+import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.aspects.remoting.MergeMetaDataInterceptor;
+import org.jboss.aspects.remoting.Remoting;
+import org.jboss.aspects.security.SecurityClientInterceptor;
 import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.client.spi.main.MainDeployer;
 import org.jboss.deployers.spi.management.DeploymentTemplate;
@@ -67,6 +76,8 @@
 import org.jboss.profileservice.spi.Profile;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.util.naming.Util;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -93,6 +104,8 @@
    private MainDeployer mainDeployer;
    /** */
    private AttachmentsSerializer serializer;
+   private InvokerLocator locator;
+
    /** */
    private HashMap<String, DeploymentTemplate> templates = new HashMap<String, DeploymentTemplate>();
    /** */
@@ -141,6 +154,7 @@
          throw new NoSuchProfileException(msg);
       }
       // Process the deployments
+      // TODO: this should only be done once for a profile
       Set<String> deploymentNames = activeProfile.getDeploymentNames();
       for(String name : deploymentNames)
       {
@@ -169,6 +183,7 @@
     * @param md - 
     */
    protected void processManagedObject(ManagedObject mo, ManagedDeployment md)
+      throws Exception
    {
       String key = mo.getName() + "/" + mo.getNameType();
       log.debug("ID for ManagedObject: "+key+", attachmentName: "+mo.getAttachmentName());
@@ -184,26 +199,37 @@
          {
             // Save the runtime mo for merging
             runtimeMOs.put(key, mo);
-            return;
          }
-         mergeRuntimeMO(parentMO, mo);
+         else
+         {
+            mergeRuntimeMO(parentMO, mo);
+            runtimeMOs.remove(key);
+         }
+         // There is no further processing of runtime ManagedObjects
+         return;
       }
       else
       {
          // See if there is runtime info to merge
          ManagedObject runtimeMO = runtimeMOs.get(key);
          if (runtimeMO != null)
+         {
             mergeRuntimeMO(mo, runtimeMO);
+            runtimeMOs.remove(key);
+         }
       }
 
       // Update the MO registry
       ManagedObject prevMO = moRegistry.put(key, mo);
       if( prevMO != null )
-         log.warn("Duplicate mo for key: "+key+", prevMO: "+prevMO);
+      {
+         // This should only matter for ManagedObjects that have a ManagementObjectID
+         log.debug("Duplicate mo for key: "+key+", prevMO: "+prevMO);
+      }
       // Check for unresolved refs
       checkForReferences(key, mo);
 
-      // Create ManagedComponents for 
+      // Create ManagedComponents for ManagedObjects annotated with ManagementComponent
       ManagementComponent mc = (ManagementComponent) moAnns.get(ManagementComponent.class.getName());
       if (mc != null)
       {
@@ -274,7 +300,7 @@
          {
             GenericValue gv = (GenericValue) prop.getValue();
             ManagedObject propMO = (ManagedObject) gv.getValue();
-            // TODO: This is probably an error condition
+            // TODO: a null is probably an error condition
             if (propMO != null)
                processManagedObject(propMO, md);
          }
@@ -290,7 +316,7 @@
                {
                   GenericValue gv = (GenericValue) avalue.getValue(n);
                   ManagedObject propMO = (ManagedObject) gv.getValue();
-                  // TODO: This is probably an error condition
+                  // TODO: a null is probably an error condition
                   if (propMO != null)
                      processManagedObject(propMO, md);
                }
@@ -304,46 +330,6 @@
       return unresolvedRefs;
    }
 
-   protected void checkForReferences(String key, ManagedObject mo)
-   {
-      Set<ManagedProperty> referers =  unresolvedRefs.get(key);
-      log.debug("checkForReferences, "+key+" has referers: "+referers);
-      if (referers != null)
-      {
-         for(ManagedProperty prop : referers)
-         {
-            prop.setTargetManagedObject(mo);
-         }
-         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);
-   }
-
    public ProfileService getProfileService()
    {
       return ps;
@@ -354,6 +340,15 @@
       log.debug("setProfileService: "+ps);
    }
 
+   public InvokerLocator getLocator()
+   {
+      return locator;
+   }
+   public void setLocator(InvokerLocator locator)
+   {
+      this.locator = locator;
+   }
+
    public AttachmentsSerializer getSerializer()
    {
       return serializer;
@@ -646,37 +641,85 @@
       }
    }
 
-   private ManagedDeployment getManagedDeployment(Deployment ctx)
+   protected void checkForReferences(String key, ManagedObject mo)
+   {
+      Set<ManagedProperty> referers =  unresolvedRefs.get(key);
+      log.debug("checkForReferences, "+key+" has referers: "+referers);
+      if (referers != null)
+      {
+         for(ManagedProperty prop : referers)
+         {
+            prop.setTargetManagedObject(mo);
+         }
+         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)
       throws Exception
    {
-      ManagedDeployment md = mainDeployer.getManagedDeployment(ctx.getName());
-      return md;
+      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)
+      {
+         runtimeOps = createOperationProxies(runtimeOps);
+         ops.addAll(runtimeOps);
+      }
+
+      ManagedObjectImpl moi = (ManagedObjectImpl) mo;
+      moi.setProperties(props);
+      moi.setOperations(ops);
    }
 
    /**
-    * Get the map of the ManagedPropertys keyed by the property mapped name.
-    * The mapped name is used as this is the external view of the
-    * property name. The name corresponds to the attachment field name.
+    * TODO: An aspect that performs the operation dispatch is still needed
     * 
-    * @param mos
+    * @param ops
     * @return
+    * @throws Exception
     */
-   private Map<String, ManagedProperty> getProperties(Map<String, ManagedObject> mos)
+   protected Set<ManagedOperation> createOperationProxies(Set<ManagedOperation> ops)
+      throws Exception
    {
-      HashMap<String, ManagedProperty> props = new HashMap<String, ManagedProperty>();
-      for(ManagedObject mo : mos.values())
+      ClassLoader loader = getClass().getClassLoader();
+      ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
+      interceptors.add(SecurityClientInterceptor.singleton);
+      interceptors.add(MergeMetaDataInterceptor.singleton);
+      interceptors.add(InvokeRemoteInterceptor.singleton);
+
+      // Create the ManagedOperation proxies
+      HashSet<ManagedOperation> opProxies = new HashSet<ManagedOperation>();
+      Class[] ifaces = {ManagedOperation.class};
+      for (ManagedOperation op : ops)
       {
-         Collection<ManagedProperty> moProps = mo.getProperties().values();
-         for(ManagedProperty prop : moProps)
-         {
-            // Use the mapped name if it exists
-            String name = prop.getMappedName();
-            if( name == null )
-               name = prop.getName();
-            props.put(name, prop);
-         }
+         String dispatchName = "ProfileService.ManagedOperation@"+System.identityHashCode(op);
+         Dispatcher.singleton.registerTarget(dispatchName, op);
+         ManagedOperation opProxy = (ManagedOperation) Remoting.createRemoteProxy(dispatchName,
+               loader, ifaces, locator, interceptors, "ProfileService");
+         opProxies.add(opProxy);
       }
-      return props;
+      return opProxies;
    }
 
+   private ManagedDeployment getManagedDeployment(Deployment ctx)
+      throws Exception
+   {
+      ManagedDeployment md = mainDeployer.getManagedDeployment(ctx.getName());
+      return md;
+   }
+
 }

Modified: trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProfileServiceInvocationHandler.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProfileServiceInvocationHandler.java	2007-09-05 19:41:34 UTC (rev 65116)
+++ trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProfileServiceInvocationHandler.java	2007-09-05 19:47:46 UTC (rev 65117)
@@ -21,10 +21,12 @@
  */
 package org.jboss.profileservice.remoting;
 
+import org.jboss.aop.Dispatcher;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.proxy.Proxy;
 import org.jboss.aspects.remoting.AOPRemotingInvocationHandler;
 import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.logging.Logger;
 import org.jboss.remoting.InvocationRequest;
 import org.jboss.remoting.ServerInvocationHandler;
 
@@ -40,6 +42,7 @@
 public class ProfileServiceInvocationHandler extends AOPRemotingInvocationHandler
    implements ServerInvocationHandler
 {
+   private static final Logger log = Logger.getLogger(ProfileServiceInvocationHandler.class);
    private Proxy mgtViewProxy;
 
    public Proxy getManagementViewProxy()
@@ -54,6 +57,10 @@
    public Object invoke(InvocationRequest invocation)
       throws Throwable
    {
+      org.jboss.aop.joinpoint.Invocation inv =(org.jboss.aop.joinpoint.Invocation)invocation.getParameter();
+      Object oid = inv.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
+      log.debug("Invocation for: "+oid);
+
       InvocationResponse value = (InvocationResponse) super.invoke(invocation);
       if( value.getResponse() instanceof ManagementView )
       {

Modified: trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java	2007-09-05 19:41:34 UTC (rev 65116)
+++ trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java	2007-09-05 19:47:46 UTC (rev 65117)
@@ -133,6 +133,7 @@
             interceptors, "ProfileService");
       InitialContext ctx = new InitialContext();
       Util.bind(ctx, jndiName, psProxy);
+      log.debug("Bound ProfileService proxy");
 
       // Create the ManagementView proxy
       Class[] mvIfaces = {ManagementView.class};
@@ -140,13 +141,12 @@
       Dispatcher.singleton.registerTarget(mvDispatchName, mgtView);
       mgtViewProxy = Remoting.createRemoteProxy(mvDispatchName, loader, mvIfaces, locator,
             interceptors, "ProfileService");
-      log.debug("Bound ProfileService proxy");
+      log.debug("Created ManagementView proxy");
    }
 
    public void stop()
       throws Exception
    {
-      ClassLoader loader = Thread.currentThread().getContextClassLoader();
       Dispatcher.singleton.unregisterTarget(dispatchName);
       String mvDispatchName = dispatchName+".ManagementView";
       Dispatcher.singleton.unregisterTarget(mvDispatchName);




More information about the jboss-cvs-commits mailing list