1 package hudson.remoting; 2 3 import java.lang.ref.WeakReference ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 import java.util.WeakHashMap ; 7 8 13 final class ExportedClassLoaderTable { 14 private final Map <Integer , WeakReference <ClassLoader >> table = new HashMap <Integer , WeakReference <ClassLoader >>(); 15 private final WeakHashMap <ClassLoader ,Integer > reverse = new WeakHashMap <ClassLoader ,Integer >(); 16 17 private int iota = 1; 19 20 21 public synchronized int intern(ClassLoader cl) { 22 if(cl==null) return 0; 24 Integer id = reverse.get(cl); 25 if(id==null) { 26 id = iota++; 27 table.put(id,new WeakReference <ClassLoader >(cl)); 28 reverse.put(cl,id); 29 } 30 31 return id; 32 } 33 34 public synchronized ClassLoader get(int id) { 35 WeakReference <ClassLoader > ref = table.get(id); 36 if(ref==null) return null; 37 return ref.get(); 38 } 39 } 40 | Popular Tags |