1 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 31 public class WorkInfo { 32 private long id = -1; 34 35 private final String key; 37 private final Object userId; 39 private final Object userInfo; 41 private Date time; 43 private final Long period; 45 46 private final boolean atFixedRate; 47 48 private ExecutorFeedingTimerTask worker; 50 private ExecutorTask taskWrapper; 51 52 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 } 139 | Popular Tags |