[jboss-cvs] JBossAS SVN: r95654 - projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 28 00:43:54 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-10-28 00:43:54 -0400 (Wed, 28 Oct 2009)
New Revision: 95654
Modified:
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi/ClassPoolRepository.java
Log:
[JBREFLECT-65] Created a mechanism to avoid double-creation of the same classpool. This needs to be revised.
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-10-28 04:03:46 UTC (rev 95653)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/spi/ClassPoolRepository.java 2009-10-28 04:43:54 UTC (rev 95654)
@@ -21,6 +21,8 @@
*/
package org.jboss.classpool.spi;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Map;
import javassist.ClassPool;
@@ -42,6 +44,7 @@
private ScopedClassPoolRepository delegate;
private ClassPoolRepositoryCallback callback;
+ private Collection<ClassLoader> currentClassLoaders = new HashSet<ClassLoader>();
/**
* Returns the singleton instance.
@@ -158,13 +161,20 @@
* @param classLoader the ClassLoader to be added to this repository
* @return the ClassPool corresponding to {@code classLoader}
*/
- public ClassPool registerClassLoader(ClassLoader classLoader)
+ public synchronized ClassPool registerClassLoader(ClassLoader classLoader)
{
if (classLoader == null)
{
classLoader = SecurityActions.getContextClassLoader();
}
+ if (currentClassLoaders.contains(classLoader))
+ {
+ return null;
+ }
+ // TODO JBREFLECT-63 review this
+ currentClassLoaders.add(classLoader);
ClassPool classPool = delegate.registerClassLoader(classLoader);
+ currentClassLoaders.remove(classLoader);
if (callback != null)
{
callback.classLoaderRegistered(classLoader);
@@ -177,7 +187,7 @@
*
* @param classLoader the ClassLoader to be removed from this repository
*/
- public void unregisterClassLoader(ClassLoader classLoader)
+ public synchronized void unregisterClassLoader(ClassLoader classLoader)
{
delegate.unregisterClassLoader(classLoader);
if (callback != null)
More information about the jboss-cvs-commits
mailing list