Coverage Report - org.mule.transport.quartz.jobs.ScheduledDispatchJob
 
Classes in this File Line Coverage Branch Coverage Complexity
ScheduledDispatchJob
75%
12/16
50%
2/4
6
 
 1  
 /*
 2  
  * $Id: ScheduledDispatchJob.java 11613 2008-04-20 20:30:10Z rossmason $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.quartz.jobs;
 12  
 
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.module.client.MuleClient;
 15  
 import org.mule.transport.NullPayload;
 16  
 import org.mule.transport.quartz.QuartzConnector;
 17  
 import org.mule.transport.quartz.i18n.QuartzMessages;
 18  
 
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 import org.quartz.Job;
 22  
 import org.quartz.JobDataMap;
 23  
 import org.quartz.JobExecutionContext;
 24  
 import org.quartz.JobExecutionException;
 25  
 
 26  
 /**
 27  
  * Will dispatch the current message to a Mule endpoint at a leter time.
 28  
  * This job can be used to fire timebased events.
 29  
  */
 30  10
 public class ScheduledDispatchJob implements Job
 31  
 {
 32  
     /**
 33  
      * The logger used for this class
 34  
      */
 35  10
     protected transient Log logger = LogFactory.getLog(getClass());
 36  
 
 37  
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
 38  
     {
 39  10
         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
 40  10
         Object payload = jobDataMap.get(QuartzConnector.PROPERTY_PAYLOAD);
 41  
 
 42  10
         if (payload == null)
 43  
         {
 44  0
             payload = NullPayload.getInstance();
 45  
         }
 46  
 
 47  10
         ScheduledDispatchJobConfig config = (ScheduledDispatchJobConfig)jobDataMap.get(QuartzConnector.PROPERTY_JOB_CONFIG);
 48  10
         if (config == null)
 49  
         {
 50  0
             throw new JobExecutionException(
 51  
                 QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_CONFIG).getMessage());
 52  
         }
 53  
 
 54  
         try
 55  
         {
 56  10
             MuleClient client = new MuleClient();
 57  10
             logger.debug("Dispatching payload on: " + config.getEndpointRef());
 58  10
             client.dispatch(config.getEndpointRef(), payload, jobDataMap);
 59  
         }
 60  0
         catch (MuleException e)
 61  
         {
 62  0
             throw new JobExecutionException(e);
 63  10
         }
 64  10
     }
 65  
 }