1 22 package org.jboss.ejb3; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 27 import javax.ejb.TimerService ; 28 29 import org.jboss.ejb3.statistics.InvocationStatistics; 30 31 import org.jboss.system.ServiceMBeanSupport; 32 33 39 public class ServiceDelegateWrapper extends ServiceMBeanSupport implements ServiceDelegateWrapperMBean 40 { 41 private Object delegate; 42 private Method createMethod; 43 private Method startMethod; 44 private Method stopMethod; 45 private Method destroyMethod; 46 47 48 public ServiceDelegateWrapper(Object delegate) 49 { 50 this.delegate = delegate; 51 try 52 { 53 createMethod = delegate.getClass().getMethod("create"); 54 } 55 catch (NoSuchMethodException ignored) 56 { 57 } 58 try 59 { 60 startMethod = delegate.getClass().getMethod("start"); 61 } 62 catch (NoSuchMethodException ignored) 63 { 64 } 65 try 66 { 67 stopMethod = delegate.getClass().getMethod("stop"); 68 } 69 catch (NoSuchMethodException ignored) 70 { 71 } 72 try 73 { 74 destroyMethod = delegate.getClass().getMethod("destroy"); 75 } 76 catch (NoSuchMethodException ignored) 77 { 78 } 79 80 } 81 82 @Override 83 protected void createService() throws Exception 84 { 85 super.createService(); 86 try 87 { 88 if (createMethod != null) createMethod.invoke(delegate); 89 } 90 catch (InvocationTargetException e) 91 { 92 Throwable t = e.getCause(); 93 if (t instanceof Exception ) throw (Exception )t; 94 else throw new RuntimeException (t); 95 } 96 } 97 98 @Override 99 protected void startService() throws Exception 100 { 101 super.startService(); 102 try 103 { 104 if (startMethod != null) startMethod.invoke(delegate); 105 } 106 catch (InvocationTargetException e) 107 { 108 Throwable t = e.getCause(); 109 if (t instanceof Exception ) throw (Exception )t; 110 else throw new RuntimeException (t); 111 } 112 } 113 114 @Override 115 protected void stopService() throws Exception 116 { 117 super.stopService(); 118 try 119 { 120 if (stopMethod != null) stopMethod.invoke(delegate); 121 } 122 catch (InvocationTargetException e) 123 { 124 Throwable t = e.getCause(); 125 if (t instanceof Exception ) throw (Exception )t; 126 else throw new RuntimeException (t); 127 } 128 129 } 130 131 @Override 132 protected void destroyService() throws Exception 133 { 134 super.destroyService(); 135 try 136 { 137 if (destroyMethod != null) destroyMethod.invoke(delegate); 138 } 139 catch (InvocationTargetException e) 140 { 141 Throwable t = e.getCause(); 142 if (t instanceof Exception ) throw (Exception )t; 143 else throw new RuntimeException (t); 144 } 145 } 146 147 public TimerService getTimerService(Object pKey) 149 { 150 return ((Container) delegate).getTimerService(pKey); 151 } 152 153 public InvocationStatistics getInvokeStats() 154 { 155 return ((Container) delegate).getInvokeStats(); 156 } 157 } 158 | Popular Tags |