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.job;
16  
17  import com.liferay.portal.kernel.json.JSONFactoryUtil;
18  import com.liferay.portal.kernel.json.JSONObject;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.messaging.MessageBusUtil;
22  import com.liferay.portal.kernel.scheduler.SchedulerEngine;
23  
24  import java.util.Date;
25  
26  import org.quartz.Job;
27  import org.quartz.JobDataMap;
28  import org.quartz.JobDetail;
29  import org.quartz.JobExecutionContext;
30  
31  /**
32   * <a href="MessageSenderJob.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Michael C. Han
35   * @author Bruno Farache
36   */
37  public class MessageSenderJob implements Job {
38  
39      public void execute(JobExecutionContext jobExecutionContext) {
40          try {
41              JobDetail jobDetail = jobExecutionContext.getJobDetail();
42  
43              JobDataMap jobDataMap = jobDetail.getJobDataMap();
44  
45              String destination = jobDataMap.getString(
46                  SchedulerEngine.DESTINATION);
47              String messageBody = jobDataMap.getString(
48                  SchedulerEngine.MESSAGE_BODY);
49  
50              Date scheduledFireTime = jobExecutionContext.getScheduledFireTime();
51  
52              JSONObject jsonObj = JSONFactoryUtil.createJSONObject(messageBody);
53  
54              jsonObj.put(
55                  "scheduledFireTime",
56                  JSONFactoryUtil.createJSONObject(
57                      JSONFactoryUtil.serialize(scheduledFireTime)));
58  
59              MessageBusUtil.sendMessage(destination, jsonObj.toString());
60          }
61          catch (Exception e) {
62              _log.error("Unable to execute job", e);
63          }
64      }
65  
66      private static Log _log = LogFactoryUtil.getLog(MessageSenderJob.class);
67  
68  }