aboutsummaryrefslogtreecommitdiff
path: root/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java')
-rw-r--r--src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java b/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java
index 2245c7d..8c20d97 100644
--- a/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java
+++ b/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java
@@ -1,11 +1,12 @@
/*
* Javassist, a Java-bytecode translator toolkit.
- * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved.
+ * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. Alternatively, the contents of this file may be used under
- * the terms of the GNU Lesser General Public License Version 2.1 or later.
+ * the terms of the GNU Lesser General Public License Version 2.1 or later,
+ * or the Apache License Version 2.0.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
@@ -17,7 +18,7 @@ package javassist.scopedpool;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@@ -42,8 +43,8 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
boolean pruneWhenCached;
/** The registered classloaders */
- protected Map registeredCLs = Collections
- .synchronizedMap(new WeakHashMap());
+ protected Map<ClassLoader,ScopedClassPool> registeredCLs = Collections
+ .synchronizedMap(new WeakHashMap<ClassLoader,ScopedClassPool>());
/** The default class pool */
protected ClassPool classpool;
@@ -75,6 +76,7 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
*
* @return the prune.
*/
+ @Override
public boolean isPrune() {
return prune;
}
@@ -84,6 +86,7 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
*
* @param prune a new value.
*/
+ @Override
public void setPrune(boolean prune) {
this.prune = prune;
}
@@ -95,10 +98,12 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
* @param src the original classpool.
* @return the classpool
*/
+ @Override
public ScopedClassPool createScopedClassPool(ClassLoader cl, ClassPool src) {
return factory.create(cl, src, this);
}
+ @Override
public ClassPool findClassPool(ClassLoader cl) {
if (cl == null)
return registerClassLoader(ClassLoader.getSystemClassLoader());
@@ -112,6 +117,7 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
* @param ucl the classloader.
* @return the classpool
*/
+ @Override
public ClassPool registerClassLoader(ClassLoader ucl) {
synchronized (registeredCLs) {
// FIXME: Probably want to take this method out later
@@ -120,7 +126,7 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
// a
// ClassPool.classpath
if (registeredCLs.containsKey(ucl)) {
- return (ClassPool)registeredCLs.get(ucl);
+ return registeredCLs.get(ucl);
}
ScopedClassPool pool = createScopedClassPool(ucl, classpool);
registeredCLs.put(ucl, pool);
@@ -131,7 +137,8 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
/**
* Get the registered classloaders.
*/
- public Map getRegisteredCLs() {
+ @Override
+ public Map<ClassLoader,ScopedClassPool> getRegisteredCLs() {
clearUnregisteredClassLoaders();
return registeredCLs;
}
@@ -140,34 +147,31 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
* This method will check to see if a register classloader has been
* undeployed (as in JBoss)
*/
+ @Override
public void clearUnregisteredClassLoaders() {
- ArrayList toUnregister = null;
+ List<ClassLoader> toUnregister = null;
synchronized (registeredCLs) {
- Iterator it = registeredCLs.values().iterator();
- while (it.hasNext()) {
- ScopedClassPool pool = (ScopedClassPool)it.next();
- if (pool.isUnloadedClassLoader()) {
- it.remove();
- ClassLoader cl = pool.getClassLoader();
+ for (Map.Entry<ClassLoader,ScopedClassPool> reg:registeredCLs.entrySet()) {
+ if (reg.getValue().isUnloadedClassLoader()) {
+ ClassLoader cl = reg.getValue().getClassLoader();
if (cl != null) {
- if (toUnregister == null) {
- toUnregister = new ArrayList();
- }
+ if (toUnregister == null)
+ toUnregister = new ArrayList<ClassLoader>();
toUnregister.add(cl);
}
+ registeredCLs.remove(reg.getKey());
}
}
- if (toUnregister != null) {
- for (int i = 0; i < toUnregister.size(); i++) {
- unregisterClassLoader((ClassLoader)toUnregister.get(i));
- }
- }
+ if (toUnregister != null)
+ for (ClassLoader cl:toUnregister)
+ unregisterClassLoader(cl);
}
}
+ @Override
public void unregisterClassLoader(ClassLoader cl) {
synchronized (registeredCLs) {
- ScopedClassPool pool = (ScopedClassPool)registeredCLs.remove(cl);
+ ScopedClassPool pool = registeredCLs.remove(cl);
if (pool != null)
pool.close();
}
@@ -177,10 +181,12 @@ public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
// Noop - this is the end
}
+ @Override
public void setClassPoolFactory(ScopedClassPoolFactory factory) {
this.factory = factory;
}
+ @Override
public ScopedClassPoolFactory getClassPoolFactory() {
return factory;
}