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 shutdown() throws SchedulerException {
68          _instance._shutdown();
69      }
70  
71      public static void start() throws SchedulerException {
72          _instance._start();
73      }
74  
75      public static void unschedule(String jobName, String groupName)
76          throws SchedulerException {
77  
78          _instance._unschedule(jobName, groupName);
79      }
80  
81      private List<SchedulerRequest> _getScheduledJobs(String groupName)
82          throws SchedulerException {
83  
84          return _schedulerEngine.getScheduledJobs(groupName);
85      }
86  
87      private void _init(SchedulerEngine schedulerEngine) {
88          _schedulerEngine = schedulerEngine;
89      }
90  
91      private void _schedule(
92              String groupName, long interval, Date startDate, Date endDate,
93              String description, String destinationName, String messageBody)
94          throws SchedulerException {
95  
96          _schedulerEngine.schedule(
97              groupName, interval, startDate, endDate, description,
98              destinationName, messageBody);
99      }
100 
101     private void _schedule(
102             String groupName, String cronText, Date startDate, Date endDate,
103             String description, String destinationName, String messageBody)
104         throws SchedulerException {
105 
106         _schedulerEngine.schedule(
107             groupName, cronText, startDate, endDate, description,
108             destinationName, messageBody);
109     }
110 
111     private void _shutdown() throws SchedulerException {
112         _schedulerEngine.shutdown();
113     }
114 
115     private void _start() throws SchedulerException {
116         _schedulerEngine.start();
117     }
118 
119     private void _unschedule(String jobName, String groupName)
120         throws SchedulerException {
121 
122         _schedulerEngine.unschedule(jobName, groupName);
123     }
124 
125     private static SchedulerEngineUtil _instance = new SchedulerEngineUtil();
126 
127     private SchedulerEngine _schedulerEngine;
128 
129 }