001 /**
002 *
003 * Copyright 2004 Hiram Chirino
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.transport.activeio;
019
020 import java.io.IOException;
021 import java.net.URI;
022 import java.net.URISyntaxException;
023
024 import javax.jms.JMSException;
025
026 import org.activeio.AsynchChannel;
027 import org.activeio.ChannelFactory;
028 import org.activemq.io.WireFormat;
029 import org.activemq.transport.TransportChannel;
030 import org.activemq.transport.TransportChannelFactorySupport;
031 import org.activemq.util.JMSExceptionHelper;
032
033 /**
034 * A tcp implementation of a TransportChannelFactory
035 *
036 * @version $Revision: 1.1.1.1 $
037 */
038 public class ActiveIOTransportChannelFactory extends TransportChannelFactorySupport {
039
040 /**
041 * Create a Channel to a remote Node - e.g. a Broker
042 *
043 * @param wireFormat
044 * @param remoteLocation
045 * @return the TransportChannel bound to the remote node
046 * @throws JMSException
047 */
048 public TransportChannel create(WireFormat wireFormat, URI remoteLocation) throws JMSException {
049 AsynchChannel asynchChannel = createAsynchChannel(remoteLocation);
050 ActiveIOTransportChannel channel = new ActiveIOTransportChannel(wireFormat, asynchChannel);
051 return populateProperties(channel, remoteLocation);
052 }
053
054 /**
055 * Create a Channel to a remote Node - e.g. a Broker
056 *
057 * @param wireFormat
058 * @param remoteLocation
059 * @param localLocation -
060 * e.g. local InetAddress and local port
061 * @return the TransportChannel bound to the remote node
062 * @throws JMSException
063 */
064 public TransportChannel create(WireFormat wireFormat, URI remoteLocation, URI localLocation) throws JMSException {
065 AsynchChannel asynchChannel = createAsynchChannel(remoteLocation);
066 ActiveIOTransportChannel channel = new ActiveIOTransportChannel(wireFormat, asynchChannel);
067 return populateProperties(channel, remoteLocation);
068 }
069
070 public boolean requiresEmbeddedBroker() {
071 return false;
072 }
073
074 /**
075 * @param remoteLocation
076 * @return
077 * @throws JMSException
078 */
079 private AsynchChannel createAsynchChannel(URI remoteLocation) throws JMSException {
080 try {
081 remoteLocation = URIConverter.convert(remoteLocation);
082 AsynchChannel channel = new ChannelFactory().openAsynchChannel(remoteLocation);
083 // If the channel is not allready buffered.. lets buffer it.
084 //if( channel.narrow(WriteBufferedAsynchChannel.class)==null && channel.narrow(WriteBufferedSynchChannel.class)==null ) {
085 // channel = new WriteBufferedAsynchChannel(channel);
086 //}
087 return channel;
088 } catch (IOException e) {
089 throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
090 } catch (URISyntaxException e) {
091 throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
092 }
093 }
094
095 }