[jboss-cvs] JBossAS SVN: r91980 - projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 4 17:24:32 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-08-04 17:24:32 -0400 (Tue, 04 Aug 2009)
New Revision: 91980
Added:
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactoryImpl.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepositoryCallback.java
Modified:
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java
Log:
[JBREFLECT-56] Created a callback for ClassPoolRepository
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java 2009-08-04 21:24:08 UTC (rev 91979)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java 2009-08-04 21:24:32 UTC (rev 91980)
@@ -1,5 +1,6 @@
package org.jboss.classpool;
+import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -137,6 +138,16 @@
super.close();
unregisterWithParent();
repository.unregisterClassLoader(getClassLoader());
+
+ for (Iterator<AbstractClassPool> childIterator = children.keySet().iterator(); childIterator.hasNext();)
+ {
+ AbstractClassPool child = childIterator.next();
+ childIterator.remove();
+ if (child.getClassLoader() != null)
+ {
+ child.close();
+ }
+ }
// for (Iterator<AbstractClassPool> it = children.keySet().iterator() ; it.hasNext() ; )
// {
// AbstractClassPool child = it.next();
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java 2009-08-04 21:24:08 UTC (rev 91979)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java 2009-08-04 21:24:32 UTC (rev 91980)
@@ -1,47 +1,17 @@
-/*
- * 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;
import javassist.ClassPool;
-import javassist.scopedpool.ScopedClassPool;
import javassist.scopedpool.ScopedClassPoolFactory;
import javassist.scopedpool.ScopedClassPoolRepository;
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 55872 $
- *
- **/
-public class AbstractClassPoolFactory implements ScopedClassPoolFactory
+// TODO: check why ScopedClassPoolRepository and not AbstractClassPoolRepository
+public interface AbstractClassPoolFactory extends ScopedClassPoolFactory
{
- public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
- {
- return new AbstractClassPool(cl, src, repository);
- }
- public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
- {
- return new AbstractClassPool(src, repository);
- }
+ public abstract AbstractClassPool create(ClassLoader cl, ClassPool src,
+ ScopedClassPoolRepository repository);
+
+ public abstract AbstractClassPool create(ClassPool src,
+ ScopedClassPoolRepository repository);
+
}
\ No newline at end of file
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactoryImpl.java (from rev 91617, projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactoryImpl.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactoryImpl.java 2009-08-04 21:24:32 UTC (rev 91980)
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 55872 $
+ *
+ **/
+public class AbstractClassPoolFactoryImpl implements AbstractClassPoolFactory
+{
+ /* (non-Javadoc)
+ * @see org.jboss.classpool.AbstractClassPoolFactory#create(java.lang.ClassLoader, javassist.ClassPool, javassist.scopedpool.ScopedClassPoolRepository)
+ */
+ public AbstractClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return new AbstractClassPool(cl, src, repository);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.classpool.AbstractClassPoolFactory#create(javassist.ClassPool, javassist.scopedpool.ScopedClassPoolRepository)
+ */
+ public AbstractClassPool create(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return new AbstractClassPool(src, repository);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java 2009-08-04 21:24:08 UTC (rev 91979)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java 2009-08-04 21:24:32 UTC (rev 91980)
@@ -32,6 +32,23 @@
*/
public abstract class AbstractJBossDelegatingClassPoolFactory extends AbstractJBossClassPoolFactory
{
+ // TODO: check if this is needed
+ /*protected ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ //Make sure that we get classpools for all the parent classloaders
+ if (cl == null)
+ {
+ return ClassPool.getDefault();
+ }
+ ClassLoader parent = SecurityActions.getParent(cl);
+
+ if (parent != null)
+ {
+ return repository.registerClassLoader(parent);
+ }
+ return src;
+ }*/
+
public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
{
return new TempJBossDelegatingClassPool(src, repository);
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java 2009-08-04 21:24:08 UTC (rev 91979)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java 2009-08-04 21:24:32 UTC (rev 91980)
@@ -1,28 +1,26 @@
/*
-* 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.
-*/
+ * 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;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import javassist.ClassPool;
@@ -31,8 +29,6 @@
import javassist.scopedpool.ScopedClassPoolRepository;
import javassist.scopedpool.ScopedClassPoolRepositoryImpl;
-import org.jboss.logging.Logger;
-
/**
* Singleton classpool repository
*
@@ -41,14 +37,15 @@
*/
public class ClassPoolRepository implements ScopedClassPoolRepository
{
- private static final Logger logger = Logger.getLogger(ClassPoolRepository.class);
+ //private static final Logger logger = Logger.getLogger(ClassPoolRepository.class);
private final static ClassPoolRepository instance = new ClassPoolRepository();
/** The classes per classppol */
- protected final HashMap<ClassLoader, HashSet<Class<?>>> ucl2classes = new HashMap<ClassLoader, HashSet<Class<?>>>();
+ //protected final HashMap<ClassLoader, HashSet<Class<?>>> ucl2classes = new HashMap<ClassLoader, HashSet<Class<?>>>();
- ScopedClassPoolRepository delegate;
+ private ScopedClassPoolRepository delegate;
+ private ClassPoolRepositoryCallback callback;
public static ClassPoolRepository getInstance()
{
@@ -59,8 +56,8 @@
{
this.delegate = ScopedClassPoolRepositoryImpl.getInstance();
//This was needed when jboss-aop.jar was deployed in the jboss/lib directory since the AspectManager bean had no chance to initialise it
- delegate.setClassPoolFactory(new AbstractClassPoolFactory());
-// if (!setJBossSpecificStartupVariables())
+ delegate.setClassPoolFactory(new AbstractClassPoolFactoryImpl());
+ // if (!setJBossSpecificStartupVariables())
// {
// delegate.setClassPoolFactory(new AbstractClassPoolFactory());
// }
@@ -96,6 +93,16 @@
{
return delegate.getClassPoolFactory();
}
+
+ public void setClassPoolRepositoryCallback(ClassPoolRepositoryCallback callback)
+ {
+ this.callback = callback;
+ }
+
+ public ClassPoolRepositoryCallback getClassPoolRepositoryCallback()
+ {
+ return this.callback;
+ }
public boolean isPrune()
{
@@ -135,21 +142,30 @@
delegate.clearUnregisteredClassLoaders();
}
- public ClassPool registerClassLoader(ClassLoader ucl)
+ public ClassPool registerClassLoader(ClassLoader classLoader)
{
- if (ucl == null)
+ if (classLoader == null)
{
- return delegate.registerClassLoader(SecurityActions.getContextClassLoader());
+ classLoader = SecurityActions.getContextClassLoader();
}
- return delegate.registerClassLoader(ucl);
+ ClassPool classPool = delegate.registerClassLoader(classLoader);
+ if (callback != null)
+ {
+ callback.classLoaderRegistered(classLoader);
+ }
+ return classPool;
}
- public void unregisterClassLoader(ClassLoader cl)
+ public void unregisterClassLoader(ClassLoader classLoader)
{
- delegate.unregisterClassLoader(cl);
+ delegate.unregisterClassLoader(classLoader);
+ if (callback != null)
+ {
+ callback.classLoaderUnregistered(classLoader);
+ }
}
- public void registerClass(Class<?> clazz)
+ /*public void registerClass(Class<?> clazz)
{
ClassLoader classLoader = SecurityActions.getClassLoader(clazz);
HashSet<Class<?>> classes = ucl2classes.get(classLoader);
@@ -159,10 +175,10 @@
ucl2classes.put(classLoader, classes);
}
classes.add(clazz);
- }
+ }*/
- public void perfomUnregisterClassLoader(ClassLoader cl)
+ /*public void perfomUnregisterClassLoader(ClassLoader cl)
{
ucl2classes.remove(cl);
- }
+ }*/
}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepositoryCallback.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepositoryCallback.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepositoryCallback.java 2009-08-04 21:24:32 UTC (rev 91980)
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+
+/**
+ * Singleton classpool repository
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 87799 $
+ */
+public interface ClassPoolRepositoryCallback {
+ public void classLoaderRegistered(ClassLoader classLoader);
+ public void classLoaderUnregistered(ClassLoader classLoader);
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list