KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > jms > JmsMessageReceiver


1 /*
2  * $Id: JmsMessageReceiver.java 3798 2006-11-04 04:07:14Z aperepel $
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.jms;
12
13 import javax.jms.Message JavaDoc;
14 import javax.resource.spi.work.Work JavaDoc;
15
16 import org.mule.impl.MuleMessage;
17 import org.mule.umo.UMOComponent;
18 import org.mule.umo.endpoint.UMOEndpoint;
19 import org.mule.umo.lifecycle.InitialisationException;
20 import org.mule.umo.provider.UMOConnector;
21 import org.mule.umo.provider.UMOMessageAdapter;
22
23 /**
24  * Registers a single JmsMessage listener but uses a thread pool to process incoming
25  * messages
26  */

27 public class JmsMessageReceiver extends SingleJmsMessageReceiver
28 {
29
30     public JmsMessageReceiver(UMOConnector connector, UMOComponent component, UMOEndpoint endpoint)
31         throws InitialisationException
32     {
33         super(connector, component, endpoint);
34     }
35
36     public void onMessage(Message JavaDoc message)
37     {
38         try
39         {
40             if (logger.isDebugEnabled())
41             {
42                 logger.debug("Message received of type: " + message.getClass().getName());
43                 if (message.getJMSDestination() != null)
44                 {
45                     logger.debug("Message received on " + message.getJMSDestination() + " ("
46                                  + message.getJMSDestination().getClass().getName() + ")");
47                 }
48                 else
49                 {
50                     logger.debug("Message received on unknown destination");
51                 }
52                 logger.debug("Message CorrelationId is: " + message.getJMSCorrelationID());
53                 logger.debug("Jms Message Id is: " + message.getJMSMessageID());
54             }
55
56             if (message.getJMSRedelivered())
57             {
58                 if (logger.isDebugEnabled())
59                 {
60                     logger.debug("Message with correlationId: " + message.getJMSCorrelationID()
61                                  + " has redelivered flag set, handing off to Exception Handler");
62                 }
63                 redeliveryHandler.handleRedelivery(message);
64             }
65             getWorkManager().scheduleWork(new Worker(message));
66         }
67         catch (Exception JavaDoc e)
68         {
69             handleException(e);
70         }
71     }
72
73     private class Worker implements Work JavaDoc
74     {
75         private Message JavaDoc message;
76
77         public Worker(Message JavaDoc message)
78         {
79             this.message = message;
80         }
81
82         /*
83          * (non-Javadoc)
84          *
85          * @see java.lang.Runnable#run()
86          */

87         public void run()
88         {
89             try
90             {
91                 UMOMessageAdapter adapter = connector.getMessageAdapter(message);
92                 routeMessage(new MuleMessage(adapter));
93             }
94             catch (Exception JavaDoc e)
95             {
96                 getConnector().handleException(e);
97             }
98         }
99
100         public void release()
101         {
102             // no op
103
}
104     }
105 }
106
Popular Tags