View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
5    * compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.opensource.org/licenses/ecl2.php
8    * 
9    * 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 org.kuali.rice.ksb.messaging.quartz;
14  
15  import java.io.Serializable;
16  
17  import org.apache.log4j.Logger;
18  import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
19  import org.kuali.rice.ksb.messaging.PersistedMessage;
20  import org.kuali.rice.ksb.messaging.threadpool.KSBThreadPool;
21  import org.kuali.rice.ksb.service.KSBServiceLocator;
22  import org.kuali.rice.ksb.util.KSBConstants;
23  import org.quartz.Job;
24  import org.quartz.JobExecutionContext;
25  import org.quartz.JobExecutionException;
26  
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 (rice.collab@kuali.org)
33   * 
34   */
35  public class MessageServiceExecutorJob implements Job, Serializable {
36  
37      private static final Logger LOG = Logger.getLogger(MessageServiceExecutorJob.class);
38  
39      private static final long serialVersionUID = 6702139047380618522L;
40  
41      public static final String MESSAGE_KEY = "message";
42  
43      public void execute(JobExecutionContext jec) throws JobExecutionException {
44  	try {
45  	    PersistedMessage message = (PersistedMessage) jec.getJobDetail().getJobDataMap().get(MESSAGE_KEY);
46  	    message.setQueueStatus(KSBConstants.ROUTE_QUEUE_ROUTING);
47  	    KSBServiceLocator.getRouteQueueService().save(message);
48  	    KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message));
49  	} catch (Throwable t) {
50  	    LOG.error("Caught throwable attempting to process message in exception messaging queue.", t);
51  	    throw new JobExecutionException(new Exception(t));
52  	}
53      }
54  }