[jboss-cvs] JBossAS SVN: r96657 - in projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool: spi and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 20 15:22:29 EST 2009


Author: flavia.rainone at jboss.com
Date: 2009-11-20 15:22:29 -0500 (Fri, 20 Nov 2009)
New Revision: 96657

Added:
   projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolRepository.java
Modified:
   projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi/ClassPoolRepository.java
Log:
[JBREFLECT-69] The classpools should also be registered per module, so that when the CL is not available, we can use the module to retrieve the class pool that needs to be cleaned up. For that reason, a repository specific for usage with modules has been created JBossClDelegatingCPRepository, and CPRepository has been adapted so it could extended.

Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolRepository.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolRepository.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolRepository.java	2009-11-20 20:22:29 UTC (rev 96657)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.plugins.as5.jbosscl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classpool.spi.ClassPoolRepository;
+import org.jboss.logging.Logger;
+
+/**
+ * Repository for JBossclDelegatingClassPools.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ *
+ * @version $Revision$
+ */
+
+public class JBossClDelegatingClassPoolRepository extends ClassPoolRepository
+{
+   Logger logger = Logger.getLogger(this.getClass());
+   
+   private final static JBossClDelegatingClassPoolRepository instance = new JBossClDelegatingClassPoolRepository();
+   
+   /**
+    * Returns the singleton instance.
+    * 
+    * @return the singleton repository instance
+    */
+   public static JBossClDelegatingClassPoolRepository getInstance()
+   {
+      return instance;
+   }
+   
+   /** The registered modules */
+   protected Map<Module, ScopedClassPool> registeredModules =
+      Collections.synchronizedMap(new WeakHashMap<Module, ScopedClassPool>());
+   
+   @Override
+   public synchronized ClassPool registerClassLoader(ClassLoader classLoader)
+   {
+      ScopedClassPool classPool = (ScopedClassPool) super.registerClassLoader(classLoader);
+      if (classPool == null)
+      {
+         delegate.unregisterClassLoader(classLoader);
+      }
+      else
+      {
+         Module module = getModuleForClassLoader(classLoader);
+         this.registeredModules.put(module, classPool);
+      }
+      return classPool;
+   }
+   
+
+   public synchronized void unregisterClassLoader(ClassLoader classLoader, Module module)
+   {
+      ScopedClassPool classPool = registeredModules.remove(module);
+      if (classLoader == null)
+      {
+         if (classPool == null)
+         {
+            throw new IllegalStateException("Module " + module + " is not registered");
+         }
+         classPool.close();
+      }
+      else
+      {
+         unregisterClassLoader(classLoader);
+      }
+   }
+   
+   private Module getModuleForClassLoader(final ClassLoader classLoader)
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<Module>()
+      {
+         public Module run()
+         {
+            return ClassLoading.getModuleForClassLoader(classLoader);
+         }
+      });
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolRepository.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi/ClassPoolRepository.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi/ClassPoolRepository.java	2009-11-20 20:16:29 UTC (rev 96656)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi/ClassPoolRepository.java	2009-11-20 20:22:29 UTC (rev 96657)
@@ -42,10 +42,10 @@
 {
    private final static ClassPoolRepository instance = new ClassPoolRepository();
    
-   private ScopedClassPoolRepository delegate;
+   protected ScopedClassPoolRepository delegate;
    private ClassPoolRepositoryCallback callback;
    private Collection<ClassLoader> currentClassLoaders = new HashSet<ClassLoader>();
-
+   
    /**
     * Returns the singleton instance.
     * 
@@ -59,7 +59,7 @@
    /**
     * Constructor.
     */
-   private ClassPoolRepository()
+   protected ClassPoolRepository()
    {
       this.delegate = ScopedClassPoolRepositoryImpl.getInstance();
       //TODO: This was needed when jboss-aop.jar was deployed in the jboss/lib directory since the AspectManager bean had no chance to initialise it
@@ -173,9 +173,11 @@
       }
       // TODO JBREFLECT-63 review this
       currentClassLoaders.add(classLoader);
-      ClassPool classPool = delegate.registerClassLoader(classLoader);
+      ScopedClassPool classPool = (ScopedClassPool) delegate.registerClassLoader(classLoader);
       currentClassLoaders.remove(classLoader);
-      if (callback != null)
+      
+      // TODO review classPool != null check for AOP tests
+      if (classPool != null && callback != null)
       {
          callback.classLoaderRegistered(classLoader);
       }




More information about the jboss-cvs-commits mailing list