Coverage Report - org.mule.providers.quartz.jobs.MuleClientReceiveJob
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleClientReceiveJob
0%
0/25
0%
0/4
9
 
 1  
 /*
 2  
  * $Id: MuleClientReceiveJob.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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.providers.quartz.jobs;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.extras.client.MuleClient;
 15  
 import org.mule.providers.quartz.QuartzConnector;
 16  
 import org.mule.providers.quartz.i18n.QuartzMessages;
 17  
 import org.mule.umo.UMOException;
 18  
 import org.mule.umo.UMOMessage;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 import org.quartz.Job;
 23  
 import org.quartz.JobDataMap;
 24  
 import org.quartz.JobExecutionContext;
 25  
 import org.quartz.JobExecutionException;
 26  
 
 27  
 /**
 28  
  * Will receive on an endpoint and dispatch the result on another.
 29  
  */
 30  0
 public class MuleClientReceiveJob implements Job
 31  
 {
 32  
     /**
 33  
      * The logger used for this class
 34  
      */
 35  0
     protected transient Log logger = LogFactory.getLog(getClass());
 36  
 
 37  
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
 38  
     {
 39  0
         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
 40  
 
 41  0
         String dispatchEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT);
 42  0
         if (dispatchEndpoint == null)
 43  
         {
 44  0
             throw new JobExecutionException(
 45  
                 QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT).getMessage());
 46  
         }
 47  
 
 48  0
         String receiveEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT);
 49  0
         if (receiveEndpoint == null)
 50  
         {
 51  0
             throw new JobExecutionException(
 52  
                 QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT).getMessage());
 53  
         }
 54  0
         long timeout = MuleManager.getConfiguration().getSynchronousEventTimeout();
 55  0
         String timeoutString = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_TIMEOUT);
 56  0
         if (timeoutString != null)
 57  
         {
 58  0
             timeout = Long.parseLong(timeoutString);
 59  
         }
 60  
         try
 61  
         {
 62  0
             MuleClient client = new MuleClient();
 63  0
             logger.debug("Attempting to receive event on: " + receiveEndpoint);
 64  0
             UMOMessage result = client.receive(receiveEndpoint, timeout);
 65  0
             if (result != null)
 66  
             {
 67  0
                 logger.debug("Received event on: " + receiveEndpoint);
 68  0
                 logger.debug("Dispatching result on: " + dispatchEndpoint);
 69  0
                 result.addProperties(jobDataMap);
 70  0
                 client.dispatch(dispatchEndpoint, result);
 71  
             }
 72  
         }
 73  0
         catch (UMOException e)
 74  
         {
 75  0
             throw new JobExecutionException(e);
 76  0
         }
 77  0
     }
 78  
 }