1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.scheduler;
24  
25  import com.liferay.portal.kernel.scheduler.messaging.SchedulerRequest;
26  
27  import java.util.Date;
28  import java.util.List;
29  
30  /**
31   * <a href="SchedulerEngineUtil.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Bruno Farache
34   */
35  public class SchedulerEngineUtil {
36  
37      public static List<SchedulerRequest> getScheduledJobs(String groupName)
38          throws SchedulerException {
39  
40          return _instance._getScheduledJobs(groupName);
41      }
42  
43      public static void init(SchedulerEngine defaultScheduler) {
44          _instance._init(defaultScheduler);
45      }
46  
47      public static void schedule(
48              String groupName, long interval, Date startDate, Date endDate,
49              String description, String destinationName, String messageBody)
50          throws SchedulerException {
51  
52          _instance._schedule(
53              groupName, interval, startDate, endDate, description,
54              destinationName, messageBody);
55      }
56  
57      public static void schedule(
58              String groupName, String cronText, Date startDate, Date endDate,
59              String description, String destinationName, String messageBody)
60          throws SchedulerException {
61  
62          _instance._schedule(
63              groupName, cronText, startDate, endDate, description,
64              destinationName, messageBody);
65      }
66  
67      public static void schedule(
68              String jobName, String groupName, long interval, Date startDate,
69              Date endDate, String description, String destinationName,
70              String messageBody)
71          throws SchedulerException {
72  
73          _instance._schedule(
74              jobName, groupName, interval, startDate, endDate, description,
75              destinationName, messageBody);
76      }
77  
78      public static void schedule(
79              String jobName, String groupName, String cronText, Date startDate,
80              Date endDate, String description, String destinationName,
81              String messageBody)
82          throws SchedulerException {
83  
84          _instance._schedule(
85              jobName, groupName, cronText, startDate, endDate, description,
86              destinationName, messageBody);
87      }
88  
89      public static void shutdown() throws SchedulerException {
90          _instance._shutdown();
91      }
92  
93      public static void start() throws SchedulerException {
94          _instance._start();
95      }
96  
97      public static void unschedule(String jobName, String groupName)
98          throws SchedulerException {
99  
100         _instance._unschedule(jobName, groupName);
101     }
102 
103     private SchedulerEngine _schedulerEngine;
104 
105     private List<SchedulerRequest> _getScheduledJobs(String groupName)
106         throws SchedulerException {
107 
108         return _schedulerEngine.getScheduledJobs(groupName);
109     }
110 
111     private void _init(SchedulerEngine schedulerEngine) {
112         _schedulerEngine = schedulerEngine;
113     }
114 
115     private void _schedule(
116             String groupName, long interval, Date startDate, Date endDate,
117             String description, String destinationName, String messageBody)
118         throws SchedulerException {
119 
120         _schedulerEngine.schedule(
121             groupName, interval, startDate, endDate, description,
122             destinationName, messageBody);
123     }
124 
125     private void _schedule(
126             String groupName, String cronText, Date startDate, Date endDate,
127             String description, String destinationName, String messageBody)
128         throws SchedulerException {
129 
130         _schedulerEngine.schedule(
131             groupName, cronText, startDate, endDate, description,
132             destinationName, messageBody);
133     }
134 
135     private void _schedule(
136             String jobName, String groupName, long interval, Date startDate,
137             Date endDate, String description, String destinationName,
138             String messageBody)
139         throws SchedulerException {
140 
141         _schedulerEngine.schedule(
142             jobName, groupName, interval, startDate, endDate, description,
143             destinationName, messageBody);
144     }
145 
146     private void _schedule(
147             String jobName, String groupName, String cronText, Date startDate,
148             Date endDate, String description, String destinationName,
149             String messageBody)
150         throws SchedulerException {
151 
152         _schedulerEngine.schedule(
153             jobName, groupName, cronText, startDate, endDate, description,
154             destinationName, messageBody);
155     }
156 
157     private void _shutdown() throws SchedulerException {
158         _schedulerEngine.shutdown();
159     }
160 
161     private void _start() throws SchedulerException {
162         _schedulerEngine.start();
163     }
164 
165     private void _unschedule(String jobName, String groupName)
166         throws SchedulerException {
167 
168         _schedulerEngine.unschedule(jobName, groupName);
169     }
170 
171     private static SchedulerEngineUtil _instance = new SchedulerEngineUtil();
172 
173 }