View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.conn.socket;
29  
30  import java.io.IOException;
31  import java.net.InetSocketAddress;
32  import java.net.Socket;
33  
34  import org.apache.http.HttpHost;
35  import org.apache.http.protocol.HttpContext;
36  
37  /**
38   * A factory for creating and connecting connection sockets.
39   *
40   * @since 4.3
41   */
42  public interface ConnectionSocketFactory {
43  
44      /**
45       * Creates new, unconnected socket. The socket should subsequently be passed to
46       * {@link #connectSocket(int, Socket, HttpHost, InetSocketAddress, InetSocketAddress,
47       *    HttpContext) connectSocket} method.
48       *
49       * @return  a new socket
50       *
51       * @throws IOException if an I/O error occurs while creating the socket
52       */
53      Socket createSocket(HttpContext context) throws IOException;
54  
55      /**
56       * Connects the socket to the target host with the given resolved remote address.
57       *
58       * @param connectTimeout connect timeout.
59       * @param sock the socket to connect, as obtained from {@link #createSocket(HttpContext)}.
60       * {@code null} indicates that a new socket should be created and connected.
61       * @param host target host as specified by the caller (end user).
62       * @param remoteAddress the resolved remote address to connect to.
63       * @param localAddress the local address to bind the socket to, or {@code null} for any.
64       * @param context the actual HTTP context.
65       *
66       * @return  the connected socket. The returned object may be different
67       *          from the {@code sock} argument if this factory supports
68       *          a layered protocol.
69       *
70       * @throws IOException if an I/O error occurs
71       */
72      Socket connectSocket(
73          int connectTimeout,
74          Socket sock,
75          HttpHost host,
76          InetSocketAddress remoteAddress,
77          InetSocketAddress localAddress,
78          HttpContext context) throws IOException;
79  
80  }