1
22
23 package com.liferay.portal.scheduler.quartz;
24
25 import com.liferay.portal.kernel.json.JSONFactoryUtil;
26 import com.liferay.portal.kernel.json.JSONObject;
27 import com.liferay.portal.kernel.messaging.MessageBusUtil;
28 import com.liferay.portal.kernel.scheduler.SchedulerEngine;
29
30 import java.util.Date;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 import org.quartz.Job;
36 import org.quartz.JobDataMap;
37 import org.quartz.JobDetail;
38 import org.quartz.JobExecutionContext;
39
40
47 public class MessageSenderJob implements Job {
48
49 public void execute(JobExecutionContext jobExecutionContext) {
50 try {
51 JobDetail jobDetail = jobExecutionContext.getJobDetail();
52
53 JobDataMap jobDataMap = jobDetail.getJobDataMap();
54
55 String destination = jobDataMap.getString(
56 SchedulerEngine.DESTINATION);
57 String messageBody = jobDataMap.getString(
58 SchedulerEngine.MESSAGE_BODY);
59
60 Date scheduledFireTime = jobExecutionContext.getScheduledFireTime();
61
62 JSONObject jsonObj = JSONFactoryUtil.createJSONObject(messageBody);
63
64 jsonObj.put(
65 "scheduledFireTime",
66 JSONFactoryUtil.createJSONObject(
67 JSONFactoryUtil.serialize(scheduledFireTime)));
68
69 MessageBusUtil.sendMessage(destination, jsonObj.toString());
70 }
71 catch (Exception e) {
72 _log.error(e, e);
73 }
74 }
75
76 private static Log _log = LogFactory.getLog(MessageSenderJob.class);
77
78 }