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.scheduler;
16  
17  import com.liferay.portal.kernel.messaging.DestinationNames;
18  import com.liferay.portal.kernel.messaging.Message;
19  import com.liferay.portal.kernel.messaging.MessageBusUtil;
20  import com.liferay.portal.kernel.scheduler.CronTrigger;
21  import com.liferay.portal.kernel.scheduler.SchedulerEngine;
22  import com.liferay.portal.kernel.scheduler.SchedulerException;
23  import com.liferay.portal.kernel.scheduler.Trigger;
24  import com.liferay.portal.kernel.scheduler.messaging.SchedulerRequest;
25  
26  import java.util.List;
27  
28  /**
29   * <a href="SchedulerEngineProxy.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Bruno Farache
32   * @author Shuyang Zhou
33   */
34  public class SchedulerEngineProxy implements SchedulerEngine {
35  
36      public List<SchedulerRequest> getScheduledJobs(String groupName)
37          throws SchedulerException {
38  
39          try {
40              SchedulerRequest schedulerRequest =
41                  SchedulerRequest.createRetrieveRequest(
42                      new CronTrigger(groupName, groupName, null));
43  
44              List<SchedulerRequest> schedulerRequests =
45                  (List<SchedulerRequest>)MessageBusUtil.sendSynchronousMessage(
46                      DestinationNames.SCHEDULER_ENGINE, schedulerRequest,
47                      DestinationNames.SCHEDULER_ENGINE_RESPONSE);
48  
49              return schedulerRequests;
50          }
51          catch (Exception e) {
52              throw new SchedulerException(e);
53          }
54      }
55  
56      public void schedule(
57          Trigger trigger, String description, String destinationName,
58          Message message) {
59  
60          SchedulerRequest schedulerRequest =
61              SchedulerRequest.createRegisterRequest(
62                  trigger, description, destinationName, message);
63  
64          MessageBusUtil.sendMessage(
65              DestinationNames.SCHEDULER_ENGINE, schedulerRequest);
66      }
67  
68      public void shutdown() {
69          MessageBusUtil.sendMessage(
70              DestinationNames.SCHEDULER_ENGINE,
71              SchedulerRequest.createShutdownRequest());
72      }
73  
74      public void start() {
75          MessageBusUtil.sendMessage(
76              DestinationNames.SCHEDULER_ENGINE,
77              SchedulerRequest.createStartupRequest());
78      }
79  
80      public void unschedule(Trigger trigger) {
81          SchedulerRequest schedulerRequest =
82              SchedulerRequest.createUnregisterRequest(trigger);
83  
84          MessageBusUtil.sendMessage(
85              DestinationNames.SCHEDULER_ENGINE, schedulerRequest);
86      }
87  
88  }