/[projects]/miscJava/Test3/src/dk/thoerup/schedulesamples/TimedEjb.java
ViewVC logotype

Diff of /miscJava/Test3/src/dk/thoerup/schedulesamples/TimedEjb.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1300 by torben, Mon Apr 18 14:07:49 2011 UTC revision 1301 by torben, Mon Apr 18 14:39:01 2011 UTC
# Line 10  import javax.ejb.ScheduleExpression; Line 10  import javax.ejb.ScheduleExpression;
10  import javax.ejb.SessionContext;  import javax.ejb.SessionContext;
11  import javax.ejb.Stateless;  import javax.ejb.Stateless;
12  import javax.ejb.TimedObject;  import javax.ejb.TimedObject;
13    import javax.ejb.Timeout;
14  import javax.ejb.Timer;  import javax.ejb.Timer;
15  import javax.ejb.TimerService;  import javax.ejb.TimerService;
16    
# Line 23  import javax.ejb.TimerService; Line 24  import javax.ejb.TimerService;
24   * */   * */
25    
26  @Stateless  @Stateless
27  public class TimedEjb implements TimedObject {  public class TimedEjb /*implements TimedObject*/ {
28    
29            public static class TimerInfo implements Serializable {
30                    static final long serialVersionUID = 1L;
31    
32                    private long start = System.currentTimeMillis();
33    
34                    public long getStart() {
35                            return start;
36                    }
37    
         class TimerInfo implements Serializable {  
                 public int count;  
38          }          }
39    
40            private int count; //storing shared data like this is not recommended !!!
41    
42          @Resource          @Resource
43          private SessionContext sessionCtx;          private SessionContext sessionCtx;
44                    
# Line 46  public class TimedEjb implements TimedOb Line 56  public class TimedEjb implements TimedOb
56                  //ScheduleExpression se = new ScheduleExpression().second(10).minute("*").hour("*");                              //ScheduleExpression se = new ScheduleExpression().second(10).minute("*").hour("*");            
57                  //System.out.println(se.toString());                  //System.out.println(se.toString());
58                  //timerService.createCalendarTimer( se );                  //timerService.createCalendarTimer( se );
59    
60                    count = 0;
61                                    
62          }          }
63                    
64          @Override          //@Override if we used TimedObject interface
65          public void ejbTimeout(Timer timer) {          //public void ejbTimeout(Timer timer) {
66    
67            @Timeout
68            public void myEjbTimeout(Timer timer) {
69    
70                  TimerInfo info = (TimerInfo) timer.getInfo();                  TimerInfo info = (TimerInfo) timer.getInfo();
71                                    
72                  info.count++;                  //any updates to the info object is not pushed back to the timer services
                   
                 System.out.print("timeout .... " + info.count);  
73                                    
74                    System.out.print("timeout .... " + count + " / " + info.getStart() );
75                    count++;
76                                    
77                  if (info.count >= 10) {                  if (count >= 10) {
78                          timer.cancel();                          timer.cancel();
79                  }                  }
80          }          }

Legend:
Removed from v.1300  
changed lines
  Added in v.1301

  ViewVC Help
Powered by ViewVC 1.1.20