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 WeakStopListener implements EnvironmentListener { 43 private static final L10N L = new L10N(WeakStopListener.class); 44 private static final Logger log = Log.open(WeakStopListener.class); 45 46 private WeakReference <Object > _resourceRef; 47 48 53 public WeakStopListener(Object resource) 54 { 55 _resourceRef = new WeakReference <Object >(resource); 56 } 57 58 61 public void environmentStart(EnvironmentClassLoader loader) 62 { 63 } 64 65 68 public void environmentStop(EnvironmentClassLoader loader) 69 { 70 Object resource = _resourceRef.get(); 71 if (resource == null) 72 return; 73 74 Method destroy = getStopMethod(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 static Method getStopMethod(Class cl) 87 { 88 try { 89 return cl.getMethod("stop", new Class [0]); 90 } catch (Throwable e) { 91 } 92 93 return null; 94 } 95 } 96 97 | Popular Tags |