1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.scheduler;
16  
17  import com.liferay.portal.kernel.messaging.Message;
18  import com.liferay.portal.kernel.scheduler.messaging.SchedulerRequest;
19  
20  import java.util.List;
21  
22  /**
23   * <a href="SchedulerEngineUtil.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Bruno Farache
26   * @author Shuyang Zhou
27   */
28  public class SchedulerEngineUtil {
29  
30      public static List<SchedulerRequest> getScheduledJobs(String groupName)
31          throws SchedulerException {
32  
33          return _instance._getScheduledJobs(groupName);
34      }
35  
36      public static void init(SchedulerEngine defaultScheduler) {
37          _instance._init(defaultScheduler);
38      }
39  
40      public static void schedule(
41              Trigger trigger, String description, String destinationName,
42              Message message)
43          throws SchedulerException {
44  
45          _instance._schedule(trigger, description, destinationName, message);
46      }
47  
48      public static void schedule(
49              Trigger trigger, String description, String destinationName,
50              Object payload)
51          throws SchedulerException {
52  
53          Message message = new Message();
54  
55          message.setPayload(payload);
56  
57          _instance._schedule(trigger, description, destinationName, message);
58      }
59  
60      public static void shutdown() throws SchedulerException {
61          _instance._shutdown();
62      }
63  
64      public static void start() throws SchedulerException {
65          _instance._start();
66      }
67  
68      public static void unschedule(Trigger trigger) throws SchedulerException {
69          _instance._unschedule(trigger);
70      }
71  
72      private List<SchedulerRequest> _getScheduledJobs(String groupName)
73          throws SchedulerException {
74  
75          return _schedulerEngine.getScheduledJobs(groupName);
76      }
77  
78      private void _init(SchedulerEngine schedulerEngine) {
79          _schedulerEngine = schedulerEngine;
80      }
81  
82      private void _schedule(
83              Trigger trigger, String description, String destinationName,
84              Message message)
85          throws SchedulerException {
86  
87          _schedulerEngine.schedule(
88              trigger, description, destinationName, message);
89      }
90  
91      private void _shutdown() throws SchedulerException {
92          _schedulerEngine.shutdown();
93      }
94  
95      private void _start() throws SchedulerException {
96          _schedulerEngine.start();
97      }
98  
99      private void _unschedule(Trigger trigger) throws SchedulerException {
100         _schedulerEngine.unschedule(trigger);
101     }
102 
103     private static SchedulerEngineUtil _instance = new SchedulerEngineUtil();
104 
105     private SchedulerEngine _schedulerEngine;
106 
107 }