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.reflect.Method ; 35 import java.util.logging.Level ; 36 import java.util.logging.Logger ; 37 38 41 public class CloseListener implements ClassLoaderListener { 42 private static final L10N L = new L10N(CloseListener.class); 43 private static final Logger log = Log.open(CloseListener.class); 44 45 private Object _resource; 46 47 52 public CloseListener(Object resource) 53 { 54 _resource = resource; 55 } 56 57 60 public void classLoaderInit(DynamicClassLoader loader) 61 { 62 } 63 64 67 public void classLoaderDestroy(DynamicClassLoader loader) 68 { 69 Method destroy = getDestroyMethod(_resource.getClass()); 70 71 if (destroy == null) 72 return; 73 74 try { 75 destroy.invoke(_resource, (Object []) null); 76 } catch (Throwable e) { 77 log.log(Level.WARNING, e.toString(), e); 78 } 79 } 80 81 public static Method getDestroyMethod(Class cl) 82 { 83 try { 84 return cl.getMethod("destroy", new Class [0]); 85 } catch (Throwable e) { 86 } 87 88 try { 89 return cl.getMethod("close", new Class [0]); 90 } catch (Throwable e) { 91 } 92 93 try { 94 return cl.getMethod("stop", new Class [0]); 95 } catch (Throwable e) { 96 } 97 98 return null; 99 } 100 101 public String toString() 102 { 103 return "CloseListener[" + _resource + "]"; 104 } 105 } 106 107 | Popular Tags |