KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > timer > WorkInfo


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21
22 import org.apache.geronimo.timer.ExecutorFeedingTimerTask;
23 import org.apache.geronimo.timer.ExecutorTask;
24
25 /**
26  *
27  *
28  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
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 JavaDoc key;
37     //typically entity pk
38
private final Object JavaDoc userId;
39     //typically serializable object ejb timer service supplies to users.
40
private final Object JavaDoc userInfo;
41     //next firing
42
private Date JavaDoc time;
43     //time between firings
44
private final Long JavaDoc 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 JavaDoc clientHandle;
54
55
56     public WorkInfo(String JavaDoc key, Object JavaDoc userId, Object JavaDoc userInfo, Date JavaDoc time, Long JavaDoc 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 JavaDoc 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 JavaDoc("Id can be set only once!");
76         }
77         this.id = id;
78     }
79
80     public Object JavaDoc getUserId() {
81         return userId;
82     }
83
84     public Object JavaDoc getUserInfo() {
85         return userInfo;
86     }
87
88     public Date JavaDoc getTime() {
89         return time;
90     }
91
92     public Long JavaDoc 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 JavaDoc getExecutorTask() {
110         return taskWrapper;
111     }
112
113     public Object JavaDoc getClientHandle() {
114         return clientHandle;
115     }
116
117     public void setClientHandle(Object JavaDoc 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 JavaDoc("This is a one-time timerTask");
128         }
129         time = new Date JavaDoc(time.getTime() + period.longValue());
130     }
131
132     public void nextInterval() {
133         if (period == null) {
134             throw new IllegalStateException JavaDoc("This is a one-time timerTask");
135         }
136         time = new Date JavaDoc(System.currentTimeMillis() + period.longValue());
137     }
138 }
139
Popular Tags