KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: MuleClientReceiveJob.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.MuleManager;
16 import org.mule.config.i18n.Message;
17 import org.mule.extras.client.MuleClient;
18 import org.mule.providers.quartz.QuartzConnector;
19 import org.mule.umo.UMOException;
20 import org.mule.umo.UMOMessage;
21 import org.quartz.Job;
22 import org.quartz.JobDataMap;
23 import org.quartz.JobExecutionContext;
24 import org.quartz.JobExecutionException;
25
26 /**
27  * Will receive on an endpoint and dispatch the result on another.
28  */

29 public class MuleClientReceiveJob 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
40         String JavaDoc dispatchEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT);
41         if (dispatchEndpoint == null)
42         {
43             throw new JobExecutionException(new Message("quartz", 4,
44                 QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT).getMessage());
45         }
46
47         String JavaDoc receiveEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT);
48         if (receiveEndpoint == null)
49         {
50             throw new JobExecutionException(new Message("quartz", 4,
51                 QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT).getMessage());
52         }
53         long timeout = MuleManager.getConfiguration().getSynchronousEventTimeout();
54         String JavaDoc timeoutString = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_TIMEOUT);
55         if (timeoutString != null)
56         {
57             timeout = Long.parseLong(timeoutString);
58         }
59         try
60         {
61             MuleClient client = new MuleClient();
62             logger.debug("Attempting to receive event on: " + receiveEndpoint);
63             UMOMessage result = client.receive(receiveEndpoint, timeout);
64             if (result != null)
65             {
66                 logger.debug("Received event on: " + receiveEndpoint);
67                 logger.debug("Dispatching result on: " + dispatchEndpoint);
68                 result.addProperties(jobDataMap);
69                 client.dispatch(dispatchEndpoint, result);
70             }
71         }
72         catch (UMOException e)
73         {
74             throw new JobExecutionException(e);
75         }
76     }
77 }
78
Popular Tags