View Javadoc

1   /*** 
2    * 
3    * Copyright 2004 Protique Ltd
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.codehaus.activemq.transport.jxta;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.codehaus.activemq.message.WireFormat;
23  import org.codehaus.activemq.transport.tcp.TcpTransportChannel;
24  import org.p2psockets.P2PInetAddress;
25  import org.p2psockets.P2PSocket;
26  
27  import javax.jms.JMSException;
28  import java.io.IOException;
29  import java.net.Socket;
30  import java.net.URI;
31  import java.net.UnknownHostException;
32  
33  /***
34   * A JXTA implementation of a TransportChannel
35   * 
36   * @version $Revision: 1.5 $
37   */
38  public class JxtaTransportChannel extends TcpTransportChannel {
39  
40      private static final Log log = LogFactory.getLog(JxtaTransportChannel.class);
41  
42      /***
43       * Connect to a remote Node - e.g. a Broker
44       *
45       * @param remoteLocation
46       * @throws JMSException
47       */
48      public JxtaTransportChannel(WireFormat wireFormat, URI remoteLocation) throws JMSException {
49          super(wireFormat, remoteLocation);
50      }
51  
52      /***
53       * Connect to a remote Node - e.g. a Broker
54       *
55       * @param remoteLocation
56       * @param localLocation  -
57       *                       e.g. local InetAddress and local port
58       * @throws JMSException
59       */
60      public JxtaTransportChannel(WireFormat wireFormat, URI remoteLocation, URI localLocation) throws JMSException {
61          super(wireFormat, localLocation, remoteLocation);
62      }
63  
64      /***
65       * pretty print for object
66       * 
67       * @return String representation of this object
68       */
69      public String toString() {
70          return "P2pTransportChannel: " + socket;
71      }
72  
73      protected Socket createSocket(URI remoteLocation) throws UnknownHostException, IOException {
74          return new P2PSocket(remoteLocation.getHost(), remoteLocation.getPort());
75      }
76  
77      protected Socket createSocket(URI remoteLocation, URI localLocation) throws IOException, UnknownHostException {
78          return new P2PSocket(remoteLocation.getHost(), remoteLocation.getPort(), P2PInetAddress
79                  .getByName(localLocation.getHost()), localLocation.getPort());
80      }
81  
82  }