1 25 26 package org.objectweb.jonas.jtests.beans.worker; 27 28 import java.rmi.RemoteException ; 29 30 import javax.ejb.CreateException ; 31 import javax.ejb.EJBException ; 32 import javax.ejb.SessionBean ; 33 import javax.ejb.SessionContext ; 34 import javax.resource.spi.work.Work ; 35 import javax.resource.spi.work.WorkEvent ; 36 import javax.resource.spi.work.WorkException ; 37 import javax.resource.spi.work.WorkListener ; 38 import javax.resource.spi.work.WorkManager ; 39 40 import org.objectweb.jonas.common.Log; 41 import org.objectweb.jonas_ejb.container.JSessionContext; 42 import org.objectweb.util.monolog.api.BasicLevel; 43 import org.objectweb.util.monolog.api.Logger; 44 45 51 public class WorkerSF implements SessionBean , Work , WorkListener { 52 53 private static final long serialVersionUID = 1L; 54 private static Logger logger = null; 55 private JSessionContext ejbContext; 56 private WorkManager workManager; 57 private int wcount; 58 private int notifyAccepted = 0; 59 private int notifyStarted = 0; 60 private int notifyRejected = 0; 61 private int notifyCompleted = 0; 62 63 67 78 public void setSessionContext(SessionContext ctx) { 79 if (logger == null) { 80 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 81 } 82 logger.log(BasicLevel.DEBUG, ""); 83 ejbContext = (JSessionContext) ctx; 84 } 85 86 95 public void ejbRemove() { 96 logger.log(BasicLevel.DEBUG, ""); 97 } 98 99 103 public void ejbCreate() throws CreateException { 104 logger.log(BasicLevel.DEBUG, ""); 105 wcount = 0; 106 } 107 108 112 public void ejbPassivate() { 113 logger.log(BasicLevel.DEBUG, ""); 114 } 115 116 121 public void ejbActivate() { 122 logger.log(BasicLevel.DEBUG, ""); 123 } 124 125 129 public void release() { 130 logger.log(BasicLevel.DEBUG, ""); 131 } 132 133 public void run() { 134 logger.log(BasicLevel.DEBUG, ""); 135 wcount++; 136 } 137 138 142 145 public void setwcount(int c) throws RemoteException { 146 wcount = c; 147 } 148 149 152 public int getwcount() throws RemoteException { 153 return wcount; 154 } 155 156 159 public int getNotifyAccepted() { 160 return notifyAccepted; 161 } 162 163 166 public int getNotifyRejected() { 167 return notifyRejected; 168 } 169 170 173 public int getNotifyCompleted() { 174 return notifyCompleted; 175 } 176 177 180 public int getNotifyStarted() { 181 return notifyStarted; 182 } 183 184 187 public void doWorks(int n) throws RemoteException { 188 logger.log(BasicLevel.DEBUG, ""); 189 for (int i = 0; i < n; i++) { 190 try { 191 getWM().doWork(this); 192 } catch (WorkException e) { 193 throw new RemoteException ("doWork failed:" + e); 194 } 195 } 196 } 197 198 201 public void startWorks(int n) throws RemoteException { 202 logger.log(BasicLevel.DEBUG, ""); 203 for (int i = 0; i < n; i++) { 204 try { 205 getWM().startWork(this); 206 } catch (WorkException e) { 207 throw new RemoteException ("doWork failed:" + e); 208 } 209 } 210 } 211 212 215 public void scheduleWorks(int n, long timeout) throws RemoteException { 216 logger.log(BasicLevel.DEBUG, ""); 217 for (int i = 0; i < n; i++) { 218 try { 219 getWM().scheduleWork(this, timeout, null, this); 220 } catch (WorkException e) { 221 throw new RemoteException ("doWork failed:" + e); 222 } 223 } 224 } 225 226 230 public void doWorkInTx() throws RemoteException { 231 logger.log(BasicLevel.DEBUG, ""); 232 try { 233 getWM().doWork(this); 234 } catch (WorkException e) { 235 throw new RemoteException ("doWork failed:" + e); 236 } 237 } 238 239 243 public void startWorkInTx() throws RemoteException { 244 logger.log(BasicLevel.DEBUG, ""); 245 try { 246 getWM().startWork(this); 247 } catch (WorkException e) { 248 throw new RemoteException ("doWork failed:" + e); 249 } 250 } 251 252 256 public void scheduleWorkInTx() throws RemoteException { 257 logger.log(BasicLevel.DEBUG, ""); 258 try { 259 getWM().scheduleWork(this); 260 } catch (WorkException e) { 261 throw new RemoteException ("doWork failed:" + e); 262 } 263 } 264 265 269 272 private WorkManager getWM() { 273 if (workManager == null) { 274 workManager = ejbContext.getWorkManager(); 275 } 276 return workManager; 277 } 278 279 283 private void sleep(int n) { 284 try { 285 Thread.sleep(1000 * n); 286 } catch (InterruptedException e) { 287 } 288 } 289 290 294 public void workAccepted(WorkEvent we) { 295 logger.log(BasicLevel.DEBUG, ""); 296 notifyAccepted++; 297 } 298 299 public void workRejected(WorkEvent we) { 300 logger.log(BasicLevel.DEBUG, ""); 301 notifyRejected++; 302 } 303 304 public void workStarted(WorkEvent we) { 305 logger.log(BasicLevel.DEBUG, ""); 306 notifyStarted++; 307 } 308 309 public void workCompleted(WorkEvent we) { 310 logger.log(BasicLevel.DEBUG, ""); 311 notifyCompleted++; 312 } 313 314 } 315 | Popular Tags |