1 25 26 package org.objectweb.jonas.jtests.beans.transacted; 27 28 import java.rmi.RemoteException ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 32 import javax.ejb.EJBException ; 33 import javax.ejb.SessionBean ; 34 import javax.ejb.SessionContext ; 35 import javax.ejb.TimedObject ; 36 import javax.ejb.Timer ; 37 import javax.ejb.TimerHandle ; 38 import javax.ejb.TimerService ; 39 import javax.naming.InitialContext ; 40 import javax.naming.NamingException ; 41 42 import org.objectweb.util.monolog.api.BasicLevel; 43 44 public class SimpleSL extends SimpleCommon implements SessionBean , TimedObject { 45 46 protected SessionContext sessionContext; 47 static protected int timercount = 0; 48 49 public void setSessionContext(SessionContext sessionContext) { 50 initLogger(); 51 logger.log(BasicLevel.DEBUG, ""); 52 this.sessionContext = sessionContext; 53 } 54 55 public void ejbActivate() { 56 logger.log(BasicLevel.DEBUG, ""); 57 } 58 59 public void ejbPassivate() { 60 logger.log(BasicLevel.DEBUG, ""); 61 } 62 63 public void ejbRemove() { 64 logger.log(BasicLevel.DEBUG, ""); 65 } 66 67 public void ejbCreate() { 68 logger.log(BasicLevel.DEBUG, ""); 69 try { 70 InitialContext ictx = new InitialContext (); 71 } catch(NamingException e) { 72 throw new EJBException (e); 73 } 74 } 75 76 public int setTimer(int dur, int period) { 77 logger.log(BasicLevel.DEBUG, ""); 78 TimerService timerservice = sessionContext.getTimerService(); 79 int ret = dur * 10 + period; 80 if (period > 0) { 81 timerservice.createTimer(dur * 1000, period * 1000, new Integer (ret)); 82 } else { 83 timerservice.createTimer(dur * 1000, new Integer (ret)); 84 } 85 return ret; 86 } 87 88 public int setTimerGetHandle(int dur, int period) { 89 logger.log(BasicLevel.DEBUG, ""); 90 TimerService timerservice = sessionContext.getTimerService(); 91 int ret = dur * 10 + period; 92 Timer t = null; 93 if (period > 0) { 94 t = timerservice.createTimer(dur * 1000, period * 1000, new Integer (ret)); 95 } else { 96 t = timerservice.createTimer(dur * 1000, new Integer (ret)); 97 } 98 TimerHandle hdl = t.getHandle(); 99 TimerHandle hdl2 = getDeserializedHandle(hdl); 100 if (! timersAreIdentical(hdl, hdl2)) { 101 logger.log(BasicLevel.ERROR, "Bad timer handle"); 102 throw new EJBException ("Bad timer handle"); 103 } 104 return ret; 105 } 106 107 public TimerHandle getTimerHandle(int ident) { 108 logger.log(BasicLevel.DEBUG, ""); 109 TimerHandle hdl = null; 110 TimerService timerservice = sessionContext.getTimerService(); 111 Collection timerList = timerservice.getTimers(); 112 for (Iterator i = timerList.iterator(); i.hasNext(); ) { 113 Timer t = (Timer ) i.next(); 114 Integer id = (Integer ) t.getInfo(); 115 if (id.intValue() == ident) { 116 hdl = t.getHandle(); 117 TimerHandle hdl2 = getDeserializedHandle(hdl); 118 if (! timersAreIdentical(hdl, hdl2)) { 119 logger.log(BasicLevel.ERROR, "Bad timer handle"); 120 throw new EJBException ("Bad timer handle"); 121 } 122 break; 123 } 124 } 125 return hdl; 126 } 127 128 public void cancelTimer(int ident) { 129 logger.log(BasicLevel.DEBUG, ""); 130 TimerService timerservice = sessionContext.getTimerService(); 131 Collection timerList = timerservice.getTimers(); 132 for (Iterator i = timerList.iterator(); i.hasNext(); ) { 133 Timer t = (Timer ) i.next(); 134 Integer id = (Integer ) t.getInfo(); 135 if (id.intValue() == ident) { 136 t.cancel(); 137 } 138 } 139 } 140 141 public long getTimeRemaining(int ident) { 142 logger.log(BasicLevel.DEBUG, ""); 143 TimerService timerservice = sessionContext.getTimerService(); 144 Collection timerList = timerservice.getTimers(); 145 long ret = -1; 146 for (Iterator i = timerList.iterator(); i.hasNext(); ) { 147 Timer t = (Timer ) i.next(); 148 Integer id = (Integer ) t.getInfo(); 149 if (id.intValue() == ident) { 150 ret = t.getTimeRemaining(); 151 } 152 } 153 return ret; 154 } 155 156 public int getTimerNumber() { 157 logger.log(BasicLevel.DEBUG, ""); 158 TimerService timerservice = sessionContext.getTimerService(); 159 Collection timerList = timerservice.getTimers(); 160 return timerList.size(); 161 } 162 163 public int getTimerCount() { 164 logger.log(BasicLevel.DEBUG, ""); 165 return timercount; 166 } 167 168 171 public boolean supports_call_required() throws RemoteException { 172 logger.log(BasicLevel.DEBUG, ""); 173 Simple mysession = (Simple) sessionContext.getEJBObject(); 174 return mysession.opwith_required(); 175 } 176 177 181 184 public void ejbTimeout(Timer timer) { 185 logger.log(BasicLevel.DEBUG, ""); 186 timercount++; 187 TimerService timerservice = sessionContext.getTimerService(); 188 Collection timerList = timerservice.getTimers(); 189 TimerHandle hdl = timer.getHandle(); 190 TimerHandle hdl2 = getDeserializedHandle(hdl); 191 if (! timersAreIdentical(hdl, hdl2)) { 192 logger.log(BasicLevel.ERROR, "Bad timer handle"); 193 throw new EJBException ("Bad timer handle"); 194 } 195 } 196 } 197 | Popular Tags |