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.scheduler;
16  
17  import com.liferay.portal.kernel.messaging.DestinationNames;
18  import com.liferay.portal.kernel.messaging.MessageBusUtil;
19  import com.liferay.portal.kernel.scheduler.SchedulerEngine;
20  import com.liferay.portal.kernel.scheduler.SchedulerException;
21  import com.liferay.portal.kernel.scheduler.messaging.SchedulerRequest;
22  
23  import java.util.Date;
24  import java.util.List;
25  
26  /**
27   * <a href="SchedulerEngineProxy.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Bruno Farache
30   */
31  public class SchedulerEngineProxy implements SchedulerEngine {
32  
33      public List<SchedulerRequest> getScheduledJobs(String groupName)
34          throws SchedulerException {
35  
36          try {
37              SchedulerRequest schedulerRequest =
38                  SchedulerRequest.createRetrieveRequest(groupName);
39  
40              List<SchedulerRequest> schedulerRequests =
41                  (List<SchedulerRequest>)MessageBusUtil.sendSynchronousMessage(
42                      DestinationNames.SCHEDULER, schedulerRequest,
43                      DestinationNames.SCHEDULER_RESPONSE);
44  
45              return schedulerRequests;
46          }
47          catch (Exception e) {
48              throw new SchedulerException(e);
49          }
50      }
51  
52      public void schedule(
53          String groupName, long interval, Date startDate, Date endDate,
54          String description, String destinationName, String messageBody) {
55  
56          SchedulerRequest schedulerRequest =
57              SchedulerRequest.createRegisterRequest(
58                  groupName, interval, startDate, endDate, description,
59                  destinationName, messageBody);
60  
61          MessageBusUtil.sendMessage(
62              DestinationNames.SCHEDULER, schedulerRequest);
63      }
64  
65      public void schedule(
66          String groupName, String cronText, Date startDate, Date endDate,
67          String description, String destinationName, String messageBody) {
68  
69          SchedulerRequest schedulerRequest =
70              SchedulerRequest.createRegisterRequest(
71                  groupName, cronText, startDate, endDate, description,
72                  destinationName, messageBody);
73  
74          MessageBusUtil.sendMessage(
75              DestinationNames.SCHEDULER, schedulerRequest);
76      }
77  
78      public void schedule(
79          String jobName, String groupName, long interval, Date startDate,
80          Date endDate, String description, String destinationName,
81          String messageBody) {
82  
83          SchedulerRequest schedulerRequest =
84              SchedulerRequest.createRegisterRequest(
85                  jobName, groupName, interval, startDate, endDate, description,
86                  destinationName, messageBody);
87  
88          MessageBusUtil.sendMessage(
89              DestinationNames.SCHEDULER, schedulerRequest);
90      }
91  
92      public void schedule(
93          String jobName, String groupName, String cronText, Date startDate,
94          Date endDate, String description, String destinationName,
95          String messageBody) {
96  
97          SchedulerRequest schedulerRequest =
98              SchedulerRequest.createRegisterRequest(
99                  jobName, groupName, cronText, startDate, endDate, description,
100                 destinationName, messageBody);
101 
102         MessageBusUtil.sendMessage(
103             DestinationNames.SCHEDULER, schedulerRequest);
104     }
105 
106     public void shutdown() {
107         MessageBusUtil.sendMessage(
108             DestinationNames.SCHEDULER,
109             SchedulerRequest.createShutdownRequest());
110     }
111 
112     public void start() {
113         MessageBusUtil.sendMessage(
114             DestinationNames.SCHEDULER,
115             SchedulerRequest.createStartupRequest());
116     }
117 
118     public void unschedule(String jobName, String groupName) {
119         SchedulerRequest schedulerRequest =
120             SchedulerRequest.createUnregisterRequest(jobName, groupName);
121 
122         MessageBusUtil.sendMessage(
123             DestinationNames.SCHEDULER, schedulerRequest);
124     }
125 
126 }