[jboss-cvs] JBossAS SVN: r86956 - in branches/Branch_5_x/profileservice/src: resources and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 8 08:15:54 EDT 2009


Author: emuckenhuber
Date: 2009-04-08 08:15:54 -0400 (Wed, 08 Apr 2009)
New Revision: 86956

Added:
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationProxyFactory.java
Modified:
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
   branches/Branch_5_x/profileservice/src/resources/profileservice-jboss-beans.xml
Log:
[JBAS-6694] move creation of delegate operations/properties out of managementView

Added: 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	                        (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagedOperationProxyFactory.java	2009-04-08 12:15:54 UTC (rev 86956)
@@ -0,0 +1,232 @@
+/*
+ * 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.profileservice.management;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.aop.Dispatcher;
+import org.jboss.aop.advice.Interceptor;
+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.spi.management.RuntimeComponentDispatcher;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.remoting.InvokerLocator;
+
+/**
+ * A factory for generating managed operations and properties delegating
+ * request to a RuntimeComponentDispatcher proxy. 
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ManagedOperationProxyFactory implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1343224268002757169L;
+   private transient RuntimeComponentDispatcher dispatcher;
+   private transient MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+   private transient InvokerLocator locator;
+
+   /** The runtime component dispatcher proxy. */
+   private RuntimeComponentDispatcher dispatcherProxy;
+   
+   public RuntimeComponentDispatcher getDispatcher()
+   {
+      return dispatcher;
+   }
+   public void setDispatcher(RuntimeComponentDispatcher dispatcher)
+   {
+      this.dispatcher = dispatcher;
+   }
+   
+   public InvokerLocator getLocator()
+   {
+      return locator;
+   }
+   
+   public void setLocator(InvokerLocator locator)
+   {
+      this.locator = locator;
+   }
+
+   public RuntimeComponentDispatcher getDispatcherProxy()
+   {
+      return dispatcherProxy;
+   }
+   
+   public void start() throws Exception
+   {
+      if(this.dispatcher == null)
+         throw new IllegalStateException("Null dispatcher.");
+      if(this.locator == null)
+         throw new IllegalStateException("Null locator.");
+      
+      this.dispatcherProxy = createDispatcherProxy();
+   }
+
+   /**
+    * Create a delegating managed property. This is used for ViewUse.STATISTIC properties,
+    * delegating the getValue() request to the dispatcher proxy.
+    * 
+    * @param delegate the original property
+    * @param componentName the component name
+    * @return the delegate managed property
+    */
+   public ManagedProperty createPropertyProxy(ManagedProperty delegate, Object componentName)
+   {
+      return new ManagedPropertyDelegate(delegate, dispatcherProxy, componentName);
+   }
+   
+   /**
+    * Create managed operations for runtime components, where the invoke() can
+    * be invoked on the client side.
+    * 
+    * @param ops the managed operations
+    * @param componentName the component name
+    * @return a set of runtime operations
+    * @throws Exception
+    */
+   public Set<ManagedOperation> createOperationProxies(Set<ManagedOperation> ops, Object componentName)
+      throws Exception
+   {
+      HashSet<ManagedOperation> opProxies = new HashSet<ManagedOperation>();
+      for (ManagedOperation op : ops)
+      {
+         opProxies.add(new ManagedOperationDelegate(op, componentName));
+      }
+      return opProxies;
+   }
+   
+   /**
+    * Create a remoting dispachter proxy.
+    * 
+    * @return the proxy
+    * @throws Exception
+    */
+   protected RuntimeComponentDispatcher createDispatcherProxy() throws Exception
+   {
+      // The interceptors
+      ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
+      interceptors.add(SecurityClientInterceptor.singleton);
+      interceptors.add(MergeMetaDataInterceptor.singleton);
+      interceptors.add(InvokeRemoteInterceptor.singleton);
+      
+      String dispatchName = "ProfileService.RuntimeComponentDispatcher";
+      Class<?>[] ifaces = {RuntimeComponentDispatcher.class};
+      
+      RuntimeComponentDispatcher delegate = new DelegatingComponentDispatcher();
+      Dispatcher.singleton.registerTarget(dispatchName, delegate);
+      return (RuntimeComponentDispatcher) Remoting.createRemoteProxy(dispatchName,
+            getClass().getClassLoader(), ifaces, locator, interceptors, "ProfileService");
+   }
+   
+   public class ManagedOperationDelegate implements ManagedOperation
+   {
+      /** The serialVersionUID */
+      private static final long serialVersionUID = 2031110731596810579L;
+      private ManagedOperation delegate;
+      private Object componentName;
+
+      public ManagedOperationDelegate(ManagedOperation delegate, Object componentName)
+      {
+         if (delegate == null)
+            throw new IllegalArgumentException("Null delegate.");
+         this.delegate = delegate;
+         this.componentName = componentName;
+      }
+
+      public MetaValue invoke(MetaValue... metaValues)
+      {
+         return (MetaValue) dispatcherProxy.invoke(componentName, delegate.getName(), metaValues);
+      }
+
+      public String getDescription()
+      {
+         return delegate.getDescription();
+      }
+
+      public String getName()
+      {
+         return delegate.getName();
+      }
+
+      public Impact getImpact()
+      {
+         return delegate.getImpact();
+      }
+
+      public MetaType getReturnType()
+      {
+         return delegate.getReturnType();
+      }
+
+      public ManagedParameter[] getParameters()
+      {
+         return delegate.getParameters();
+      }
+      
+      public String[] getReflectionSignature()
+      {
+         return delegate.getReflectionSignature();
+      }
+   }
+      
+   /**
+    * A delegating runtime component dispatcher, used as the proxy.
+    * This contains additional unwrapping for managed operations.
+    */
+   public class DelegatingComponentDispatcher implements RuntimeComponentDispatcher
+   {
+      public MetaValue get(Object componentName, String propertyName)
+      {
+         return dispatcher.get(componentName, propertyName);
+      }
+
+      public Object invoke(Object componentName, String methodName, MetaValue... param)
+      {
+         MetaValue result = null;
+         if (componentName != null)
+         {
+            Object value = dispatcher.invoke(componentName, methodName, param);
+            if (value != null)
+               result = metaValueFactory.create(value);
+         }
+         return result; 
+      }
+
+      public void set(Object componentName, String propertyName, MetaValue value)
+      {
+         throw new IllegalArgumentException("Operation not supported remote.");
+      }
+   }
+}
+

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-08 11:42:24 UTC (rev 86955)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-08 12:15:54 UTC (rev 86956)
@@ -24,8 +24,6 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
-import java.net.URL;
-import java.net.URLClassLoader;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -40,13 +38,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Dispatcher;
-import org.jboss.aop.advice.Interceptor;
-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.main.MainDeployer;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.management.DeploymentTemplate;
@@ -61,7 +52,6 @@
 import org.jboss.managed.api.ManagedDeployment;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedOperation;
-import org.jboss.managed.api.ManagedParameter;
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.MutableManagedComponent;
 import org.jboss.managed.api.MutableManagedObject;
@@ -97,7 +87,6 @@
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.profileservice.spi.ProfileService;
-import org.jboss.remoting.InvokerLocator;
 import org.jboss.system.server.profileservice.attachments.AttachmentStore;
 
 /**
@@ -160,17 +149,16 @@
    
    /** The dispatcher handles ManagedOperation dispatches */
    private RuntimeComponentDispatcher dispatcher;
-   private InvokerLocator locator;
+   /** The managed operation proxy factory. */
+   private ManagedOperationProxyFactory proxyFactory;
+
    /** . */
    private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
    /** ManagedObjectFactory used for platform mbean ManagedObjects */
    ManagedObjectFactory managedObjFactory = ManagedObjectFactory.getInstance();
    
-   /** FIXME A cl used to reference AOP proxies. */
-   private ClassLoader proxyLoader;
-   /** The created remoting targets. */
-   private List<String> remotingTargets = new ArrayList<String>();
    
+   
    public ManagementViewImpl() throws IOException
    {
       
@@ -189,16 +177,15 @@
       stateMappings.put("Installed", RunState.RUNNING.name());
    }
    
-   public void start()
+   public void start() throws Exception
    {
-      proxyLoader = new URLClassLoader(new URL[0], getClass().getClassLoader());
+      // nothing
    }
    
    public void stop()
    {
       // Cleanup on stop
       release();
-      proxyLoader = null;
    }
    
    public boolean load()
@@ -301,24 +288,8 @@
       this.unresolvedRefs.clear();
       this.lastModified.clear();
       this.rootDeployments.clear();
-      
-      cleanupProxies();
-      
-      // Unregister targets
-      for(String target : remotingTargets)
-         Dispatcher.singleton.unregisterTarget(target);
-
-      log.debug("Unregistered " + remotingTargets.size() + " targets.");
-      this.remotingTargets.clear();  
    }
    
-   protected void cleanupProxies()
-   {
-      // FIXME this is a hack
-      AspectManager.instance().unregisterClassLoader(proxyLoader);   
-      proxyLoader = new URLClassLoader(new URL[0], getClass().getClassLoader());
-   }
-   
    protected void loadProfiles(boolean trace)
    {
       log.debug("reloading profiles: "+ this.ps.getActiveProfileKeys());
@@ -718,16 +689,16 @@
       log.debug("setProfileService: "+ps);
    }
 
-   public InvokerLocator getLocator()
+   public ManagedOperationProxyFactory getProxyFactory()
    {
-      return locator;
+      return proxyFactory;
    }
-
-   public void setLocator(InvokerLocator locator)
+   
+   public void setProxyFactory(ManagedOperationProxyFactory proxyFactory)
    {
-      this.locator = locator;
+      this.proxyFactory = proxyFactory;
    }
-
+   
    public AttachmentStore getAttachmentStore()
    {
       return store;
@@ -1365,25 +1336,12 @@
    private ManagedProperty createPropertyProxy(ManagedProperty prop)
       throws Exception
    {
-      if (dispatcher == null)
+      if (proxyFactory == null)
          throw new IllegalArgumentException("Missing RuntimeComponentDispatcher.");
-
-      ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
-      interceptors.add(SecurityClientInterceptor.singleton);
-      interceptors.add(MergeMetaDataInterceptor.singleton);
-      interceptors.add(InvokeRemoteInterceptor.singleton);
-
-      // Create the ManagedProperty proxy
-         // This is just a unique name registered with the dispatcher and remoting layers
-         String dispatchName = "ProfileService.ManagedProperty@"+System.identityHashCode(prop);
-         Object componentName = prop.getManagedObject().getComponentName();
-         ManagedPropertyDelegate delegate = new ManagedPropertyDelegate(prop, dispatcher, componentName);
-         Class<?>[] ifaces = {ManagedProperty.class};
-         Dispatcher.singleton.registerTarget(dispatchName, delegate);
-         ManagedProperty proxy = (ManagedProperty) Remoting.createRemoteProxy(dispatchName,
-               proxyLoader, ifaces, locator, interceptors, "ProfileService");
-         remotingTargets.add(dispatchName);
-         return proxy;
+      
+      // Create the delegate property
+      Object componentName = prop.getManagedObject().getComponentName();
+      return proxyFactory.createPropertyProxy(prop, componentName);
    }
 
    /**
@@ -1400,94 +1358,20 @@
    protected Set<ManagedOperation> createOperationProxies(ManagedObject mo, Set<ManagedOperation> ops)
       throws Exception
    {
-      if (dispatcher == null)
+      if (proxyFactory == null)
          throw new IllegalArgumentException("Missing RuntimeComponentDispatcher.");
 
       Object componentName = mo.getComponentName();
       return createOperationProxies(ops, componentName);
    }
+   
    protected Set<ManagedOperation> createOperationProxies(Set<ManagedOperation> ops, Object componentName)
       throws Exception
    {
-      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)
-      {
-         // This is just a unique name registered with the dispatcher and remoting layers
-         String dispatchName = "ProfileService.ManagedOperation@"+System.identityHashCode(op);
-         Dispatcher.singleton.registerTarget(dispatchName, new ManagedOperationDelegate(op, componentName));
-         ManagedOperation opProxy = (ManagedOperation) Remoting.createRemoteProxy(dispatchName,
-               proxyLoader, ifaces, locator, interceptors, "ProfileService");
-         remotingTargets.add(dispatchName);
-         opProxies.add(opProxy);
-      }
-      return opProxies;
+      // Create the delegate operation
+      return proxyFactory.createOperationProxies(ops, componentName);
    }
 
-   public class ManagedOperationDelegate implements ManagedOperation
-   {
-      private static final long serialVersionUID = -775240509110032859L;
-      private ManagedOperation delegate;
-      private Object componentName;
-
-      public ManagedOperationDelegate(ManagedOperation delegate, Object componentName)
-      {
-         if (delegate == null)
-            throw new IllegalArgumentException("Null delegate.");
-         this.delegate = delegate;
-         this.componentName = componentName;
-      }
-
-      public MetaValue invoke(MetaValue... metaValues)
-      {
-         MetaValue result = null;
-         if (componentName != null)
-         {
-            Object value = dispatcher.invoke(componentName, delegate.getName(), metaValues);
-            if (value != null)
-               result = metaValueFactory.create(value);
-         }
-
-         return result;
-      }
-
-      public String getDescription()
-      {
-         return delegate.getDescription();
-      }
-
-      public String getName()
-      {
-         return delegate.getName();
-      }
-
-      public Impact getImpact()
-      {
-         return delegate.getImpact();
-      }
-
-      public MetaType getReturnType()
-      {
-         return delegate.getReturnType();
-      }
-
-      public ManagedParameter[] getParameters()
-      {
-         return delegate.getParameters();
-      }
-      
-      public String[] getReflectionSignature()
-      {
-         return delegate.getReflectionSignature();
-      }
-   }
-
    private ManagedDeployment getManagedDeployment(ProfileDeployment ctx) throws DeploymentException
    {
       return mainDeployer.getManagedDeployment(ctx.getName());

Modified: branches/Branch_5_x/profileservice/src/resources/profileservice-jboss-beans.xml
===================================================================
--- branches/Branch_5_x/profileservice/src/resources/profileservice-jboss-beans.xml	2009-04-08 11:42:24 UTC (rev 86955)
+++ branches/Branch_5_x/profileservice/src/resources/profileservice-jboss-beans.xml	2009-04-08 12:15:54 UTC (rev 86956)
@@ -77,6 +77,11 @@
        </constructor>
     </bean>
     
+    <bean name="ManagedOperationProxyFactory" class="org.jboss.profileservice.management.ManagedOperationProxyFactory">
+    	<property name="locator"><inject bean="ConnectorMBean" property="invokerLocator"/></property>
+        <property name="dispatcher"><inject bean="RuntimeComponentDispatcher"/></property>
+    </bean>
+    
     <!-- The default applications profile key -->
     <bean name="ApplicationsProfileKey" class="org.jboss.profileservice.spi.ProfileKey">
 		<constructor><parameter><inject bean="BootstrapProfileFactory" property="applicationsName" /></parameter></constructor>
@@ -101,8 +106,8 @@
        	<property name="attachmentStore"><inject bean="AttachmentStore" /></property>
        	<property name="deploymentManager"><inject bean="DeploymentManager"/></property>
         <property name="defaultProfileKey"><inject bean="ApplicationsProfileKey"/></property>
-        <property name="locator"><inject bean="ConnectorMBean" property="invokerLocator"/></property>
         <property name="dispatcher"><inject bean="RuntimeComponentDispatcher"/></property>
+        <property name="proxyFactory"><inject bean="ManagedOperationProxyFactory"/></property>
         <property name="bootstrapManagedDeployments"><inject bean="ProfileServiceBootstrap" property="bootstrapMDs"/></property>
         <!-- Accept any implementor of DeploymentTemplate -->
         <incallback method="addTemplate"/>




More information about the jboss-cvs-commits mailing list