Source code: org/activemq/transport/activeio/ActiveIOTransportChannelFactory.java
1 /**
2 *
3 * Copyright 2004 Hiram Chirino
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.activemq.transport.activeio;
19
20 import java.io.IOException;
21 import java.net.URI;
22 import java.net.URISyntaxException;
23
24 import javax.jms.JMSException;
25
26 import org.activeio.AsynchChannel;
27 import org.activeio.ChannelFactory;
28 import org.activemq.io.WireFormat;
29 import org.activemq.transport.TransportChannel;
30 import org.activemq.transport.TransportChannelFactorySupport;
31 import org.activemq.util.JMSExceptionHelper;
32
33 /**
34 * A tcp implementation of a TransportChannelFactory
35 *
36 * @version $Revision: 1.1.1.1 $
37 */
38 public class ActiveIOTransportChannelFactory extends TransportChannelFactorySupport {
39
40 /**
41 * Create a Channel to a remote Node - e.g. a Broker
42 *
43 * @param wireFormat
44 * @param remoteLocation
45 * @return the TransportChannel bound to the remote node
46 * @throws JMSException
47 */
48 public TransportChannel create(WireFormat wireFormat, URI remoteLocation) throws JMSException {
49 AsynchChannel asynchChannel = createAsynchChannel(remoteLocation);
50 ActiveIOTransportChannel channel = new ActiveIOTransportChannel(wireFormat, asynchChannel);
51 return populateProperties(channel, remoteLocation);
52 }
53
54 /**
55 * Create a Channel to a remote Node - e.g. a Broker
56 *
57 * @param wireFormat
58 * @param remoteLocation
59 * @param localLocation -
60 * e.g. local InetAddress and local port
61 * @return the TransportChannel bound to the remote node
62 * @throws JMSException
63 */
64 public TransportChannel create(WireFormat wireFormat, URI remoteLocation, URI localLocation) throws JMSException {
65 AsynchChannel asynchChannel = createAsynchChannel(remoteLocation);
66 ActiveIOTransportChannel channel = new ActiveIOTransportChannel(wireFormat, asynchChannel);
67 return populateProperties(channel, remoteLocation);
68 }
69
70 public boolean requiresEmbeddedBroker() {
71 return false;
72 }
73
74 /**
75 * @param remoteLocation
76 * @return
77 * @throws JMSException
78 */
79 private AsynchChannel createAsynchChannel(URI remoteLocation) throws JMSException {
80 try {
81 remoteLocation = URIConverter.convert(remoteLocation);
82 AsynchChannel channel = new ChannelFactory().openAsynchChannel(remoteLocation);
83 // If the channel is not allready buffered.. lets buffer it.
84 //if( channel.narrow(WriteBufferedAsynchChannel.class)==null && channel.narrow(WriteBufferedSynchChannel.class)==null ) {
85 // channel = new WriteBufferedAsynchChannel(channel);
86 //}
87 return channel;
88 } catch (IOException e) {
89 throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
90 } catch (URISyntaxException e) {
91 throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
92 }
93 }
94
95 }