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.TcpTransportServerChannel;
    24  import org.p2psockets.P2PInetAddress;
    25  import org.p2psockets.P2PServerSocket;
    26
    27  import javax.jms.JMSException;
    28  import java.io.IOException;
    29  import java.net.InetAddress;
    30  import java.net.ServerSocket;
    31  import java.net.URI;
    32  import java.net.UnknownHostException;
    33
    34  /***
    35   * Binds to a well known port and listens for Sockets ...
    36   *
    37   * @version $Revision: 1.6 $
    38   */
    39  public class JxtaTransportServerChannel extends TcpTransportServerChannel {
    40
    41      private static final Log log = LogFactory.getLog(JxtaTransportServerChannel.class);
    42
    43      /***
    44       * Default Constructor
    45       *
    46       * @param bindAddr
    47       * @throws JMSException
    48       */
    49      public JxtaTransportServerChannel(WireFormat wireFormat, URI bindAddr) throws JMSException {
    50          super(wireFormat, bindAddr);
    51      }
    52
    53      /***
    54       * @return pretty print of this
    55       */
    56      public String toString() {
    57          return "P2pTransportServerChannel@" + bindAddressURI;
    58      }
    59
    60      protected ServerSocket createServerSocket(URI bind) throws UnknownHostException, IOException {
    61          ServerSocket answer = null;
    62          String host = bind.getHost();
    63
    64
    65  //        host = (host == null || host.length() == 0) ? "localhost" : host;
    66  //
    67  //        System.out.println("About to lookup host: " + host);
    68
    69          if (host == null || host.length() == 0 || host.equals("localhost")) {
    70              InetAddress addr = P2PInetAddress.getLocalHost();
    71              answer = new P2PServerSocket(bind.getPort(), getBacklog(), addr);
    72          }
    73          else {
    74              InetAddress addr = P2PInetAddress.getByName(host);
    75              answer = new P2PServerSocket(bind.getPort(), getBacklog(), addr);
    76          }
    77          /*
    78          if (addr.equals(P2PInetAddress.getLocalHost())) {
    79              answer = new P2PServerSocket(bind.getPort(), BACKLOG);
    80          }
    81          else {
    82              answer = new P2PServerSocket(bind.getPort(), BACKLOG, addr);
    83          }
    84          */
    85          //answer = new P2PServerSocket(bind.toString(), BACKLOG);
    86          return answer;
    87      }
    88  }