001/**
002 * Copyright 2005-2017 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.messaging.quartz;
017
018import org.kuali.rice.ksb.messaging.PersistedMessageBO;
019import org.kuali.rice.ksb.service.KSBServiceLocator;
020import org.kuali.rice.ksb.util.KSBConstants;
021import org.quartz.JobExecutionContext;
022import org.quartz.JobExecutionException;
023import org.quartz.JobListener;
024
025
026/**
027 * This is a description of what this class does - rkirkend don't forget to fill this in. 
028 * 
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 *
031 */
032public class MessageServiceExecutorJobListener implements JobListener {
033
034    public static final String NAME = "MessageServiceExecutorJobListener";
035    
036    /**
037     * This overridden method ...
038     * 
039     * @see org.quartz.JobListener#getName()
040     */
041    public String getName() {
042        return NAME;
043    }
044
045    /**
046     * This overridden method ...
047     * 
048     * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
049     */
050    public void jobExecutionVetoed(JobExecutionContext context) {
051    }
052
053    /**
054     * This overridden method ...
055     * 
056     * @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
057     */
058    public void jobToBeExecuted(JobExecutionContext context) {
059    }
060
061    /**
062     * This overridden method ...
063     * 
064     * @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
065     */
066    public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
067        if (context.getJobInstance() instanceof MessageServiceExecutorJob && exception != null) {
068            PersistedMessageBO message = (PersistedMessageBO)context.getJobDetail().getJobDataMap().get(MessageServiceExecutorJob.MESSAGE_KEY);
069            message.setQueueStatus(KSBConstants.ROUTE_QUEUE_EXCEPTION);
070            message = KSBServiceLocator.getMessageQueueService().save(message);
071        }
072
073    }
074
075}