1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.scheduler.messaging;
16  
17  import com.liferay.portal.kernel.scheduler.TriggerType;
18  
19  import java.io.Serializable;
20  
21  import java.util.Date;
22  
23  /**
24   * <a href="SchedulerRequest.java.html"><b><i>View Source</i></b></a>
25   *
26   * <p>
27   * A request to schedule a job for the scheduling engine. You may specify the
28   * timing of the job via the cron syntax. See
29   * http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html for a
30   * description of the syntax.
31   * </p>
32   *
33   * @author Michael C. Han
34   * @author Bruno Farache
35   * @author Brian Wing Shun Chan
36   */
37  public class SchedulerRequest implements Serializable {
38  
39      public static final String COMMAND_REGISTER = "REGISTER";
40  
41      public static final String COMMAND_RETRIEVE = "RETRIEVE";
42  
43      public static final String COMMAND_SHUTDOWN = "SHUTDOWN";
44  
45      public static final String COMMAND_STARTUP = "STARTUP";
46  
47      public static final String COMMAND_UNREGISTER = "UNREGISTER";
48  
49      public static SchedulerRequest createRegisterRequest(
50          String groupName, long interval, Date startDate, Date endDate,
51          String description, String destination, String messageBody) {
52  
53          return new SchedulerRequest(
54              COMMAND_REGISTER, null, groupName, interval, startDate, endDate,
55              description, destination, messageBody);
56      }
57  
58      public static SchedulerRequest createRegisterRequest(
59          String groupName, String cronText, Date startDate, Date endDate,
60          String description, String destination, String messageBody) {
61  
62          return new SchedulerRequest(
63              COMMAND_REGISTER, null, groupName, cronText, startDate, endDate,
64              description, destination, messageBody);
65      }
66  
67      public static SchedulerRequest createRegisterRequest(
68              String jobName, String groupName, long interval, Date startDate,
69              Date endDate, String description, String destination,
70              String messageBody) {
71  
72          return new SchedulerRequest(
73              COMMAND_REGISTER, jobName, groupName, interval, startDate, endDate,
74              description, destination, messageBody);
75      }
76  
77      public static SchedulerRequest createRegisterRequest(
78          String jobName, String groupName, String cronText, Date startDate,
79          Date endDate, String description, String destination,
80          String messageBody) {
81  
82          return new SchedulerRequest(
83              COMMAND_REGISTER, jobName, groupName, cronText, startDate, endDate,
84              description, destination, messageBody);
85      }
86  
87      public static SchedulerRequest createRetrieveRequest(String groupName) {
88          return new SchedulerRequest(COMMAND_RETRIEVE, null, groupName);
89      }
90  
91      public static SchedulerRequest createRetrieveResponseRequest(
92          String jobName, String groupName, long interval, Date startDate,
93          Date endDate, String description, String messageBody) {
94  
95          return new SchedulerRequest(
96              null, jobName, groupName, interval, startDate, endDate, description,
97              null, messageBody);
98      }
99  
100     public static SchedulerRequest createRetrieveResponseRequest(
101         String jobName, String groupName, String cronText, Date startDate,
102         Date endDate, String description, String messageBody) {
103 
104         return new SchedulerRequest(
105             null, jobName, groupName, cronText, startDate, endDate, description,
106             null, messageBody);
107     }
108 
109     public static SchedulerRequest createShutdownRequest() {
110         return new SchedulerRequest(COMMAND_SHUTDOWN);
111     }
112 
113     public static SchedulerRequest createStartupRequest() {
114         return new SchedulerRequest(COMMAND_STARTUP);
115     }
116 
117     public static SchedulerRequest createUnregisterRequest(
118         String jobName, String groupName) {
119 
120         return new SchedulerRequest(COMMAND_UNREGISTER, jobName, groupName);
121     }
122 
123     /**
124      * @deprecated
125      */
126     public SchedulerRequest() {
127     }
128 
129     /**
130      * @deprecated
131      */
132     public SchedulerRequest(String command) {
133         _command = command;
134     }
135 
136     /**
137      * @deprecated
138      */
139     public SchedulerRequest(
140         String command, String jobName, String groupName) {
141 
142         _command = command;
143         _jobName = jobName;
144         _groupName = groupName;
145     }
146 
147     /**
148      * @deprecated
149      */
150     public SchedulerRequest(
151         String command, String jobName, String groupName, long interval,
152         Date startDate, Date endDate, String description, String destination,
153         String messageBody) {
154 
155         _command = command;
156         _jobName = jobName;
157         _groupName = groupName;
158         _triggerType = TriggerType.SIMPLE;
159         _interval = interval;
160         _startDate = startDate;
161         _endDate = endDate;
162         _description = description;
163         _destination = destination;
164         _messageBody = messageBody;
165     }
166 
167     /**
168      * @deprecated
169      */
170     public SchedulerRequest(
171         String command, String jobName, String groupName, String cronText,
172         Date startDate, Date endDate, String description, String destination,
173         String messageBody) {
174 
175         _command = command;
176         _jobName = jobName;
177         _groupName = groupName;
178         _triggerType = TriggerType.CRON;
179         _cronText = cronText;
180         _startDate = startDate;
181         _endDate = endDate;
182         _description = description;
183         _destination = destination;
184         _messageBody = messageBody;
185     }
186 
187     public String getCommand() {
188         return _command;
189     }
190 
191     public String getCronText() {
192         return _cronText;
193     }
194 
195     public String getDescription() {
196         return _description;
197     }
198 
199     public String getDestination() {
200         return _destination;
201     }
202 
203     public Date getEndDate() {
204         return _endDate;
205     }
206 
207     public String getGroupName() {
208         return _groupName;
209     }
210 
211     public long getInterval() {
212         return _interval;
213     }
214 
215     public String getJobName() {
216         return _jobName;
217     }
218 
219     public String getMessageBody() {
220         return _messageBody;
221     }
222 
223     public Date getStartDate() {
224         return _startDate;
225     }
226 
227     public TriggerType getTriggerType() {
228         return _triggerType;
229     }
230 
231     public void setCommand(String command) {
232         _command = command;
233     }
234 
235     public void setCronText(String cronText) {
236         _cronText = cronText;
237     }
238 
239     public void setDescription(String description) {
240         _description = description;
241     }
242 
243     public void setDestination(String destination) {
244         _destination = destination;
245     }
246 
247     public void setEndDate(Date endDate) {
248         _endDate = endDate;
249     }
250 
251     public void setGroupName(String groupName) {
252         _groupName = groupName;
253     }
254 
255     public void setInterval(long interval) {
256         this._interval = interval;
257     }
258 
259     public void setJobName(String jobName) {
260         _jobName = jobName;
261     }
262 
263     public void setMessageBody(String messageBody) {
264         _messageBody = messageBody;
265     }
266 
267     public void setStartDate(Date startDate) {
268         _startDate = startDate;
269     }
270 
271     public void setTriggerType(TriggerType triggerType) {
272         _triggerType = triggerType;
273     }
274 
275     private String _command;
276     private String _cronText;
277     private String _description;
278     private String _destination;
279     private Date _endDate;
280     private String _groupName;
281     private long _interval;
282     private String _jobName;
283     private String _messageBody;
284     private Date _startDate;
285     private TriggerType _triggerType;
286 
287 }