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 StartListener implements EnvironmentListener { 42 private static final L10N L = new L10N(StartListener.class); 43 private static final Logger log = Log.open(StartListener.class); 44 45 private Object _resource; 46 47 52 public StartListener(Object resource) 53 { 54 _resource = resource; 55 } 56 57 60 public void environmentStart(EnvironmentClassLoader loader) 61 { 62 Method start = getStartMethod(_resource.getClass()); 63 64 if (start == null) 65 return; 66 67 try { 68 start.invoke(_resource); 69 } catch (Throwable e) { 70 log.log(Level.WARNING, e.toString(), e); 71 } 72 } 73 74 77 public void environmentStop(EnvironmentClassLoader loader) 78 { 79 Method stop = getStopMethod(_resource.getClass()); 80 81 if (stop == null) 82 return; 83 84 try { 85 stop.invoke(_resource); 86 } catch (Throwable e) { 87 log.log(Level.WARNING, e.toString(), e); 88 } 89 } 90 91 public static Method getStartMethod(Class cl) 92 { 93 try { 94 return cl.getMethod("start", new Class [0]); 95 } catch (Throwable e) { 96 } 97 98 return null; 99 } 100 101 public static Method getStopMethod(Class cl) 102 { 103 try { 104 return cl.getMethod("stop", new Class [0]); 105 } catch (Throwable e) { 106 } 107 108 return null; 109 } 110 } 111 112 | Popular Tags |