View Javadoc

1   /*
2    * $Id: MuleClientDispatchJob.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.extras.client.MuleClient;
14  import org.mule.providers.NullPayload;
15  import org.mule.providers.quartz.QuartzConnector;
16  import org.mule.providers.quartz.i18n.QuartzMessages;
17  import org.mule.umo.UMOException;
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 to a Mule endpoint using the Mule client.
28   */
29  public class MuleClientDispatchJob implements Job
30  {
31      /**
32       * The logger used for this class
33       */
34      protected transient Log logger = LogFactory.getLog(getClass());
35  
36      public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
37      {
38          JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
39          Object payload = jobDataMap.get(QuartzConnector.PROPERTY_PAYLOAD);
40  
41          if (payload == null)
42          {
43              payload = NullPayload.getInstance();
44          }
45  
46          String dispatchEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT);
47          if (dispatchEndpoint == null)
48          {
49              throw new JobExecutionException(
50                  QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT).getMessage());
51          }
52  
53          try
54          {
55              MuleClient client = new MuleClient();
56              logger.debug("Dispatching payload on: " + dispatchEndpoint);
57              client.dispatch(dispatchEndpoint, payload, jobDataMap);
58          }
59          catch (UMOException e)
60          {
61              throw new JobExecutionException(e);
62          }
63      }
64  }