01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License"); you may not use this file except in
05: * compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.opensource.org/licenses/ecl1.php
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
10: * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: */
13: package edu.iu.uis.eden.messaging.quartz;
14:
15: import java.io.Serializable;
16:
17: import org.apache.log4j.Logger;
18: import org.kuali.bus.services.KSBServiceLocator;
19: import org.kuali.rice.RiceConstants;
20: import org.quartz.Job;
21: import org.quartz.JobExecutionContext;
22: import org.quartz.JobExecutionException;
23:
24: import edu.iu.uis.eden.messaging.MessageServiceInvoker;
25: import edu.iu.uis.eden.messaging.PersistedMessage;
26: import edu.iu.uis.eden.messaging.threadpool.KSBThreadPool;
27:
28: /**
29: * Job saves a {@link PersistedMessage} to the message queue in the state of 'R' and then puts into a
30: * {@link MessageServiceInvoker} for execution in {@link KSBThreadPool}.
31: *
32: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
33: *
34: */
35: public class MessageServiceExecutorJob implements Job, Serializable {
36:
37: private static final Logger LOG = Logger
38: .getLogger(MessageServiceExecutorJob.class);
39:
40: private static final long serialVersionUID = 6702139047380618522L;
41:
42: public static final String MESSAGE_KEY = "message";
43:
44: public void execute(JobExecutionContext jec)
45: throws JobExecutionException {
46: try {
47: PersistedMessage message = (PersistedMessage) jec
48: .getJobDetail().getJobDataMap().get(MESSAGE_KEY);
49: message.setQueueStatus(RiceConstants.ROUTE_QUEUE_ROUTING);
50: KSBServiceLocator.getRouteQueueService().save(message);
51: KSBServiceLocator.getThreadPool().execute(
52: new MessageServiceInvoker(message));
53: } catch (Throwable t) {
54: LOG
55: .error(
56: "Caught throwable attempting to process message in exception messaging queue.",
57: t);
58: throw new JobExecutionException(new Exception(t));
59: }
60: }
61: }
|