KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > jbi > JbiMessageDispatcher


1 /*
2  * $Id: JbiMessageDispatcher.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.jbi;
12
13 import org.mule.impl.MuleMessage;
14 import org.mule.providers.AbstractMessageDispatcher;
15 import org.mule.umo.UMOEvent;
16 import org.mule.umo.UMOException;
17 import org.mule.umo.UMOMessage;
18 import org.mule.umo.endpoint.UMOImmutableEndpoint;
19
20 import javax.jbi.messaging.ExchangeStatus;
21 import javax.jbi.messaging.Fault;
22 import javax.jbi.messaging.InOnly;
23 import javax.jbi.messaging.InOut;
24 import javax.jbi.messaging.MessageExchange;
25 import javax.jbi.messaging.MessagingException;
26 import javax.jbi.messaging.NormalizedMessage;
27
28 /**
29  * <code>TcpMessageDispatcher</code> will send transformed mule events over tcp.
30  *
31  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
32  * @version $Revision: 3798 $
33  */

34
35 public class JbiMessageDispatcher extends AbstractMessageDispatcher
36 {
37     private JbiConnector connector;
38
39     public JbiMessageDispatcher(UMOImmutableEndpoint endpoint)
40     {
41         super(endpoint);
42         this.connector = (JbiConnector)endpoint.getConnector();
43     }
44
45     protected void doDispose()
46     {
47         // nothing to do
48
}
49
50     protected void doDispatch(UMOEvent event) throws Exception JavaDoc
51     {
52         InOnly exchange = connector.getExchangeFactory().createInOnlyExchange();
53         NormalizedMessage message = exchange.createMessage();
54         exchange.setInMessage(message);
55         JbiUtils.populateNormalizedMessage(event.getMessage(), message);
56         done(exchange);
57     }
58
59     protected UMOMessage doSend(UMOEvent event) throws Exception JavaDoc
60     {
61         InOut exchange = connector.getExchangeFactory().createInOutExchange();
62         NormalizedMessage message = exchange.createMessage();
63         exchange.setInMessage(message);
64         JbiUtils.populateNormalizedMessage(event.getMessage(), message);
65         NormalizedMessage nm = exchange.getOutMessage();
66         UMOMessage response = null;
67         if (nm != null)
68         {
69             response = new MuleMessage(connector.getMessageAdapter(nm));
70         }
71         done(exchange);
72         return response;
73     }
74
75     /**
76      * Make a specific request to the underlying transport
77      *
78      * @param endpoint the endpoint to use when connecting to the resource
79      * @param timeout the maximum time the operation should block before returning.
80      * The call should return immediately if there is data available. If
81      * no data becomes available before the timeout elapses, null will be
82      * returned
83      * @return the result of the request wrapped in a UMOMessage object. Null will be
84      * returned if no data was avaialable
85      * @throws Exception if the call to the underlying protocal cuases an exception
86      */

87     protected UMOMessage doReceive(UMOImmutableEndpoint endpoint, long timeout) throws Exception JavaDoc
88     {
89         throw new UnsupportedOperationException JavaDoc("doReceive");
90     }
91
92     public Object JavaDoc getDelegateSession() throws UMOException
93     {
94         return null;
95     }
96
97     protected void error(MessageExchange me, Fault fault) throws MessagingException
98     {
99         me.setFault(fault);
100         me.setStatus(ExchangeStatus.ERROR);
101         connector.getDeliveryChannel().send(me);
102     }
103
104     protected void done(MessageExchange me) throws MessagingException
105     {
106         me.setStatus(ExchangeStatus.DONE);
107         connector.getDeliveryChannel().send(me);
108     }
109
110     protected void doConnect(UMOImmutableEndpoint endpoint) throws Exception JavaDoc
111     {
112         // no op
113
}
114
115     protected void doDisconnect() throws Exception JavaDoc
116     {
117         // no op
118
}
119
120 }
121
Popular Tags