JxtaSocketSynchChannelFactory xref

View Javadoc

    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.activeio.net;
    19
    20  import java.io.IOException;
    21  import java.net.InetAddress;
    22  import java.net.ServerSocket;
    23  import java.net.Socket;
    24  import java.net.UnknownHostException;
    25
    26  import javax.net.ServerSocketFactory;
    27  import javax.net.SocketFactory;
    28
    29  import org.p2psockets.P2PServerSocket;
    30  import org.p2psockets.P2PSocket;
    31
    32  /***
    33   * A SslSynchChannelFactory creates {@see org.activeio.net.TcpSynchChannel}
    34   * and {@see org.activeio.net.TcpSynchChannelServer} objects that use SSL.
    35   *
    36   * @version $Revision$
    37   */
    38  public class JxtaSocketSynchChannelFactory extends SocketSynchChannelFactory {
    39
    40      static public final class JxtaServerSocketFactory extends ServerSocketFactory {
    41
    42          private static JxtaServerSocketFactory defaultJxtaServerSocketFactory = new JxtaServerSocketFactory();
    43          public static ServerSocketFactory getDefault() {
    44              return defaultJxtaServerSocketFactory;
    45          }
    46
    47          private JxtaServerSocketFactory() {}
    48
    49          public ServerSocket createServerSocket(int localPort) throws IOException {
    50              return new P2PServerSocket(localPort);
    51          }
    52
    53          public ServerSocket createServerSocket(int localPort, int backlog) throws IOException {
    54              return new P2PServerSocket(localPort, backlog);
    55          }
    56
    57          public ServerSocket createServerSocket(int localPort, int backlog, InetAddress localHost) throws IOException {
    58              return new P2PServerSocket(localPort, backlog, localHost);
    59          }
    60      }
    61
    62      static public final class JxtaSocketFactory extends SocketFactory {
    63
    64          private static JxtaSocketFactory defaultJxtaSocketFactory = new JxtaSocketFactory();
    65          public static SocketFactory getDefault() {
    66              return defaultJxtaSocketFactory;
    67          }
    68          private JxtaSocketFactory() {}
    69
    70          public Socket createSocket(String remoteHost, int remotePort) throws IOException, UnknownHostException {
    71              return new P2PSocket(remoteHost, remotePort);
    72          }
    73
    74          public Socket createSocket(String remoteHost, int remotePort, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
    75              return new P2PSocket(remoteHost, remotePort, localHost, localPort);
    76          }
    77
    78          public Socket createSocket(InetAddress remoteHost, int remotePort) throws IOException {
    79              return new P2PSocket(remoteHost, remotePort);
    80          }
    81
    82          public Socket createSocket(InetAddress remoteHost, int remotePort, InetAddress localHost, int localPort) throws IOException {
    83              return new P2PSocket(remoteHost, remotePort, localHost, localPort);
    84          }
    85      }
    86
    87      public JxtaSocketSynchChannelFactory() {
    88          super(JxtaSocketFactory.getDefault(), JxtaServerSocketFactory.getDefault());
    89      }
    90  }