1
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
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 }