[jboss-cvs] JBossAS SVN: r86916 - trunk/profileservice/src/main/org/jboss/profileservice/management.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 7 09:08:50 EDT 2009


Author: emuckenhuber
Date: 2009-04-07 09:08:50 -0400 (Tue, 07 Apr 2009)
New Revision: 86916

Modified:
   trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
Log:
[JBAS-6694] cleanup used resouces

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-07 12:55:43 UTC (rev 86915)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-07 13:08:50 UTC (rev 86916)
@@ -23,6 +23,8 @@
 
 import java.io.IOException;
 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;
@@ -37,6 +39,7 @@
 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;
@@ -159,6 +162,11 @@
    /** 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
    {
       
@@ -177,6 +185,18 @@
       stateMappings.put("Installed", RunState.RUNNING.name());
    }
    
+   public void start()
+   {
+      proxyLoader = new URLClassLoader(new URL[0], getClass().getClassLoader());
+   }
+   
+   public void stop()
+   {
+      // Cleanup on stop
+      release();
+      proxyLoader = null;
+   }
+   
    public boolean load()
    {
       // If the profile is not modified do nothing
@@ -301,8 +321,24 @@
       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());
@@ -1026,7 +1062,6 @@
    {
       mainDeployer.process();
       mainDeployer.checkComplete();
-      this.forceReload = true;
    }
 
    /**
@@ -1338,7 +1373,6 @@
       if (dispatcher == null)
          throw new IllegalArgumentException("Missing RuntimeComponentDispatcher.");
 
-      ClassLoader loader = getClass().getClassLoader();
       ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
       interceptors.add(SecurityClientInterceptor.singleton);
       interceptors.add(MergeMetaDataInterceptor.singleton);
@@ -1352,11 +1386,11 @@
          Class<?>[] ifaces = {ManagedProperty.class};
          Dispatcher.singleton.registerTarget(dispatchName, delegate);
          ManagedProperty proxy = (ManagedProperty) Remoting.createRemoteProxy(dispatchName,
-               loader, ifaces, locator, interceptors, "ProfileService");
+               proxyLoader, ifaces, locator, interceptors, "ProfileService");
+         remotingTargets.add(dispatchName);
          return proxy;
    }
 
-
    /**
     * Create ManagedOperation wrapper to intercept
     * its invocation, pushing the actual invocation
@@ -1380,7 +1414,6 @@
    protected Set<ManagedOperation> createOperationProxies(Set<ManagedOperation> ops, Object componentName)
       throws Exception
    {
-      ClassLoader loader = getClass().getClassLoader();
       ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
       interceptors.add(SecurityClientInterceptor.singleton);
       interceptors.add(MergeMetaDataInterceptor.singleton);
@@ -1395,7 +1428,8 @@
          String dispatchName = "ProfileService.ManagedOperation@"+System.identityHashCode(op);
          Dispatcher.singleton.registerTarget(dispatchName, new ManagedOperationDelegate(op, componentName));
          ManagedOperation opProxy = (ManagedOperation) Remoting.createRemoteProxy(dispatchName,
-               loader, ifaces, locator, interceptors, "ProfileService");
+               proxyLoader, ifaces, locator, interceptors, "ProfileService");
+         remotingTargets.add(dispatchName);
          opProxies.add(opProxy);
       }
       return opProxies;




More information about the jboss-cvs-commits mailing list