View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.messaging.quartz;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
20  import org.kuali.rice.ksb.messaging.PersistedMessageBO;
21  import org.kuali.rice.ksb.messaging.threadpool.KSBThreadPool;
22  import org.kuali.rice.ksb.service.KSBServiceLocator;
23  import org.kuali.rice.ksb.util.KSBConstants;
24  import org.quartz.Job;
25  import org.quartz.JobExecutionContext;
26  import org.quartz.JobExecutionException;
27  
28  import java.io.Serializable;
29  
30  
31  /**
32   * Job saves a {@link org.kuali.rice.ksb.messaging.PersistedMessageBO} to the message queue in the state of 'R' and then puts into a
33   * {@link MessageServiceInvoker} for execution in {@link KSBThreadPool}.
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   * 
37   */
38  public class MessageServiceExecutorJob implements Job, Serializable {
39  
40      private static final Logger LOG = Logger.getLogger(MessageServiceExecutorJob.class);
41  
42      private static final long serialVersionUID = 6702139047380618522L;
43  
44      public static final String MESSAGE_KEY = "message";
45  
46      public void execute(JobExecutionContext jec) throws JobExecutionException {
47  	try {
48  	    PersistedMessageBO message = (PersistedMessageBO) jec.getJobDetail().getJobDataMap().get(MESSAGE_KEY);
49   	    message.setQueueStatus(KSBConstants.ROUTE_QUEUE_ROUTING);
50          message.setLockVerNbr(null);
51  	    message = KSBServiceLocator.getMessageQueueService().save(message);
52  	    KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message));
53  	} catch (Throwable t) {
54  	    LOG.error("Caught throwable attempting to process message in exception messaging queue.", t);
55  	    throw new JobExecutionException(new Exception(t));
56  	}
57      }
58  }