* ******************************************************************/
package org.aspectj.weaver;
+import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
+import org.aspectj.apache.bcel.util.ClassLoaderReference;
+
/**
* Wraps a reference to a classloader inside a WeakReference. This should be used where we do not want the existence of
* a classloader reference to prevent garbage collection of that classloader (and possibly an associated weaver instance
*
* @author Andy Clement
*/
-public class WeakClassLoaderReference {
+public class WeakClassLoaderReference implements ClassLoaderReference {
+ private int hashcode;
+
private WeakReference loaderRef;
public WeakClassLoaderReference(ClassLoader loader) {
loaderRef = new WeakReference(loader);
+ hashcode = loader.hashCode() * 37;
+ }
+
+ public WeakClassLoaderReference(ClassLoader loader, ReferenceQueue q) {
+ loaderRef = new WeakReference(loader, q);
+ hashcode = loader.hashCode() * 37;
}
public ClassLoader getClassLoader() {
// Assert instance!=null
return instance;
}
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof WeakClassLoaderReference)) return false;
+ WeakClassLoaderReference other = (WeakClassLoaderReference) obj;
+ return (other.hashcode == hashcode);
+ }
+
+ public int hashCode() {
+ return hashcode;
+ }
}