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