001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.timer;
017:
018: import java.util.Date;
019:
020: import org.apache.geronimo.timer.ExecutorFeedingTimerTask;
021: import org.apache.geronimo.timer.ExecutorTask;
022:
023: /**
024: *
025: *
026: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
027: *
028: * */
029: public class WorkInfo {
030: //these should be persistent.
031: private long id = -1;
032:
033: //typically object name of ejb.
034: private final String key;
035: //typically entity pk
036: private final Object userId;
037: //typically serializable object ejb timer service supplies to users.
038: private final Object userInfo;
039: //next firing
040: private Date time;
041: //time between firings
042: private final Long period;
043:
044: private final boolean atFixedRate;
045:
046: //these should not be persistent.
047: private ExecutorFeedingTimerTask worker;
048: private ExecutorTask taskWrapper;
049:
050: //wrappers to this timer service can store the wrapper here.
051: private Object clientHandle;
052:
053: public WorkInfo(String key, Object userId, Object userInfo,
054: Date time, Long period, boolean atFixedRate) {
055: this .key = key;
056: this .userId = userId;
057: this .userInfo = userInfo;
058: this .time = time;
059: this .period = period;
060: this .atFixedRate = atFixedRate;
061: }
062:
063: public String getKey() {
064: return key;
065: }
066:
067: public long getId() {
068: return id;
069: }
070:
071: public void setId(long id) {
072: if (this .id != -1) {
073: throw new IllegalStateException("Id can be set only once!");
074: }
075: this .id = id;
076: }
077:
078: public Object getUserId() {
079: return userId;
080: }
081:
082: public Object getUserInfo() {
083: return userInfo;
084: }
085:
086: public Date getTime() {
087: return time;
088: }
089:
090: public Long getPeriod() {
091: return period;
092: }
093:
094: public boolean getAtFixedRate() {
095: return atFixedRate;
096: }
097:
098: public void initialize(ExecutorFeedingTimerTask worker,
099: ExecutorTask taskWrapper) {
100: this .worker = worker;
101: this .taskWrapper = taskWrapper;
102: }
103:
104: public ExecutorFeedingTimerTask getExecutorFeedingTimerTask() {
105: return worker;
106: }
107:
108: public Runnable getExecutorTask() {
109: return taskWrapper;
110: }
111:
112: public Object getClientHandle() {
113: return clientHandle;
114: }
115:
116: public void setClientHandle(Object clientHandle) {
117: this .clientHandle = clientHandle;
118: }
119:
120: public boolean isOneTime() {
121: return period == null;
122: }
123:
124: void nextTime() {
125: if (period == null) {
126: throw new IllegalStateException(
127: "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(
135: "This is a one-time timerTask");
136: }
137: time = new Date(System.currentTimeMillis() + period.longValue());
138: }
139: }
|