View Javadoc

1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.geronimo.timer;
19  
20  import java.util.Date;
21  
22  import org.apache.geronimo.timer.ExecutorFeedingTimerTask;
23  import org.apache.geronimo.timer.ExecutorTask;
24  
25  /**
26   *
27   *
28   * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
29   *
30   * */
31  public class WorkInfo {
32      //these should be persistent.
33      private long id = -1;
34  
35      //typically object name of ejb.
36      private final String key;
37      //typically entity pk
38      private final Object userId;
39      //typically serializable object ejb timer service supplies to users.
40      private final Object userInfo;
41      //next firing
42      private Date time;
43      //time between firings
44      private final Long period;
45  
46      private final boolean atFixedRate;
47  
48      //these should not be persistent.
49      private ExecutorFeedingTimerTask worker;
50      private ExecutorTask taskWrapper;
51  
52      //wrappers to this timer service can store the wrapper here.
53      private Object clientHandle;
54  
55  
56      public WorkInfo(String key, Object userId, Object userInfo, Date time, Long period, boolean atFixedRate) {
57          this.key = key;
58          this.userId = userId;
59          this.userInfo = userInfo;
60          this.time = time;
61          this.period = period;
62          this.atFixedRate = atFixedRate;
63      }
64  
65      public String getKey() {
66          return key;
67      }
68  
69      public long getId() {
70          return id;
71      }
72  
73      public void setId(long id) {
74          if (this.id != -1) {
75              throw new IllegalStateException("Id can be set only once!");
76          }
77          this.id = id;
78      }
79  
80      public Object getUserId() {
81          return userId;
82      }
83  
84      public Object getUserInfo() {
85          return userInfo;
86      }
87  
88      public Date getTime() {
89          return time;
90      }
91  
92      public Long getPeriod() {
93          return period;
94      }
95  
96      public boolean getAtFixedRate() {
97          return atFixedRate;
98      }
99  
100     public void initialize(ExecutorFeedingTimerTask worker, ExecutorTask taskWrapper) {
101         this.worker = worker;
102         this.taskWrapper = taskWrapper;
103     }
104 
105     public ExecutorFeedingTimerTask getExecutorFeedingTimerTask() {
106         return worker;
107     }
108 
109     public Runnable getExecutorTask() {
110         return taskWrapper;
111     }
112 
113     public Object getClientHandle() {
114         return clientHandle;
115     }
116 
117     public void setClientHandle(Object clientHandle) {
118         this.clientHandle = clientHandle;
119     }
120 
121     public boolean isOneTime() {
122         return period == null;
123     }
124 
125     void nextTime() {
126         if (period == null) {
127             throw new IllegalStateException("This is a one-time timerTask");
128         }
129         time = new Date(time.getTime() + period.longValue());
130     }
131 
132     public void nextInterval() {
133         if (period == null) {
134             throw new IllegalStateException("This is a one-time timerTask");
135         }
136         time = new Date(System.currentTimeMillis() + period.longValue());
137     }
138 }