1 22 package org.jboss.ejb.txtimer; 23 24 26 import javax.ejb.TimerService ; 27 import javax.management.MBeanServer ; 28 import javax.management.ObjectName ; 29 30 import org.jboss.ejb.Container; 31 import org.jboss.logging.Logger; 32 import org.jboss.mx.util.MBeanProxyExt; 33 import org.jboss.mx.util.MBeanServerLocator; 34 35 46 public class EJBTimerServiceLocator 47 { 48 private static Logger log = Logger.getLogger(EJBTimerServiceLocator.class); 50 51 private static EJBTimerService ejbTimerService; 52 53 56 public static EJBTimerService getEjbTimerService() 57 { 58 try 59 { 60 MBeanServer server = MBeanServerLocator.locateJBoss(); 62 if (server != null && server.isRegistered(EJBTimerService.OBJECT_NAME)) 63 ejbTimerService = new MBeanDelegate(server); 64 } 65 catch (Exception ignore) 66 { 67 } 68 69 if (ejbTimerService == null) 71 { 72 EJBTimerServiceImpl ejbTimerServiceImpl = new EJBTimerServiceImpl(); 73 ejbTimerService = ejbTimerServiceImpl; 74 try 75 { 76 ejbTimerServiceImpl.create(); 77 ejbTimerServiceImpl.start(); 78 } 79 catch (Exception e) 80 { 81 throw new RuntimeException ("Cannot start EJBTimerService", e); 82 } 83 } 84 return ejbTimerService; 85 } 86 87 90 public static class MBeanDelegate implements EJBTimerService 91 { 92 private EJBTimerService mbeanEjbTimerService; 93 94 public MBeanDelegate(MBeanServer server) 95 { 96 try 97 { 98 mbeanEjbTimerService = (EJBTimerService)MBeanProxyExt.create(EJBTimerService.class, EJBTimerService.OBJECT_NAME, server); 99 } 100 catch (Exception e) 101 { 102 throw new IllegalStateException ("Cannot create EJBTimerService proxy: " + e.getMessage()); 103 } 104 } 105 106 public TimerService createTimerService(ObjectName containerId, Object instancePk, Container container) 107 throws IllegalStateException 108 { 109 try 110 { 111 TimerService timerService = mbeanEjbTimerService.createTimerService(containerId, instancePk, container); 112 return timerService; 113 } 114 catch (Exception e) 115 { 116 log.error("Cannot createTimerService", e); 117 return null; 118 } 119 } 120 121 public TimerService createTimerService(ObjectName containerId, Object instancePk, TimedObjectInvoker invoker) 122 throws IllegalStateException 123 { 124 try 125 { 126 TimerService timerService = mbeanEjbTimerService.createTimerService(containerId, instancePk, invoker); 127 return timerService; 128 } 129 catch (Exception e) 130 { 131 log.error("Cannot createTimerService", e); 132 return null; 133 } 134 } 135 136 public TimerService getTimerService(ObjectName containerId, Object instancePk) 137 throws IllegalStateException 138 { 139 try 140 { 141 TimerService timerService = mbeanEjbTimerService.getTimerService(containerId, instancePk); 142 return timerService; 143 } 144 catch (Exception e) 145 { 146 log.error("Cannot getTimerService", e); 147 return null; 148 } 149 } 150 151 public void removeTimerService(ObjectName containerId, Object instancePk) 152 throws IllegalStateException 153 { 154 try 155 { 156 mbeanEjbTimerService.removeTimerService(containerId, instancePk); 157 } 158 catch (Exception e) 159 { 160 log.error("Cannot removeTimerService", e); 161 } 162 } 163 164 public void removeTimerService(ObjectName containerId, boolean keepState) throws IllegalStateException 165 { 166 try 167 { 168 mbeanEjbTimerService.removeTimerService(containerId, keepState); 169 } 170 catch (Exception e) 171 { 172 log.error("Cannot removeTimerService", e); 173 } 174 } 175 176 public void restoreTimers(ObjectName containerId, ClassLoader loader) throws IllegalStateException 177 { 178 try 179 { 180 mbeanEjbTimerService.restoreTimers(containerId, loader); 181 } 182 catch (Exception e) 183 { 184 log.error("Cannot restoreTimer", e); 185 } 186 } 187 } 188 } 189 | Popular Tags |