KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > quartz > jobs > MuleClientDispatchJob


1 /*
2  * $Id: MuleClientDispatchJob.java 3982 2006-11-22 14:28:01Z lajos $
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 MuleSource MPL
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.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.config.i18n.Message;
16 import org.mule.extras.client.MuleClient;
17 import org.mule.providers.NullPayload;
18 import org.mule.providers.quartz.QuartzConnector;
19 import org.mule.umo.UMOException;
20 import org.quartz.Job;
21 import org.quartz.JobDataMap;
22 import org.quartz.JobExecutionContext;
23 import org.quartz.JobExecutionException;
24
25 /**
26  * Will dispatch to a Mule endpoint using the Mule client.
27  */

28 public class MuleClientDispatchJob implements Job
29 {
30     /**
31      * The logger used for this class
32      */

33     protected transient Log logger = LogFactory.getLog(getClass());
34
35     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
36     {
37         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
38         Object JavaDoc payload = jobDataMap.get(QuartzConnector.PROPERTY_PAYLOAD);
39         if (payload == null)
40         {
41             payload = new NullPayload();
42         }
43         String JavaDoc dispatchEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT);
44         if (dispatchEndpoint == null)
45         {
46             throw new JobExecutionException(new Message("quartz", 4,
47                 QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT).getMessage());
48         }
49         try
50         {
51             MuleClient client = new MuleClient();
52             logger.debug("Dispatching payload on: " + dispatchEndpoint);
53             client.dispatch(dispatchEndpoint, payload, jobDataMap);
54         }
55         catch (UMOException e)
56         {
57             throw new JobExecutionException(e);
58         }
59     }
60 }
61
Popular Tags