1 28 29 package com.caucho.loader; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import java.lang.ref.WeakReference ; 35 import java.lang.reflect.Method ; 36 import java.util.logging.Level ; 37 import java.util.logging.Logger ; 38 39 42 public class WeakCloseListener implements ClassLoaderListener { 43 private static final L10N L = new L10N(CloseListener.class); 44 private static final Logger log = Log.open(CloseListener.class); 45 46 private WeakReference <Object > _resourceRef; 47 48 53 public WeakCloseListener(Object resource) 54 { 55 _resourceRef = new WeakReference <Object >(resource); 56 } 57 58 61 public void classLoaderInit(DynamicClassLoader loader) 62 { 63 } 64 65 68 public void classLoaderDestroy(DynamicClassLoader loader) 69 { 70 Object resource = _resourceRef.get(); 71 if (resource == null) 72 return; 73 74 Method destroy = CloseListener.getDestroyMethod(resource.getClass()); 75 76 if (destroy == null) 77 return; 78 79 try { 80 destroy.invoke(resource, (Object []) null); 81 } catch (Throwable e) { 82 log.log(Level.WARNING, e.toString(), e); 83 } 84 } 85 86 public String toString() 87 { 88 return "WeakCloseListener[" + _resourceRef.get() + "]"; 89 } 90 } 91 92 | Popular Tags |