View Javadoc

1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java,v 1.10 2004/05/13 04:01:22 mbecke Exp $
3    * $Revision: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5    *
6    * ====================================================================
7    *
8    *  Copyright 2002-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   */
29  
30  package org.apache.commons.httpclient.protocol;
31  
32  import java.io.IOException;
33  import java.net.InetAddress;
34  import java.net.Socket;
35  import java.net.UnknownHostException;
36  
37  import org.apache.commons.httpclient.ConnectTimeoutException;
38  import org.apache.commons.httpclient.params.HttpConnectionParams;
39  
40  /***
41   * A factory for creating Sockets.
42   * 
43   * <p>Both {@link java.lang.Object#equals(java.lang.Object) Object.equals()} and 
44   * {@link java.lang.Object#hashCode() Object.hashCode()} should be overridden appropriately.  
45   * Protocol socket factories are used to uniquely identify <code>Protocol</code>s and 
46   * <code>HostConfiguration</code>s, and <code>equals()</code> and <code>hashCode()</code> are 
47   * required for the correct operation of some connection managers.</p>
48   * 
49   * @see Protocol
50   * 
51   * @author Michael Becke
52   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
53   * 
54   * @since 2.0
55   */
56  public interface ProtocolSocketFactory {
57  
58      /***
59       * Gets a new socket connection to the given host.
60       * 
61       * @param host the host name/IP
62       * @param port the port on the host
63       * @param localAddress the local host name/IP to bind the socket to
64       * @param localPort the port on the local machine
65       * 
66       * @return Socket a new socket
67       * 
68       * @throws IOException if an I/O error occurs while creating the socket
69       * @throws UnknownHostException if the IP address of the host cannot be
70       * determined
71       */
72      Socket createSocket(
73          String host, 
74          int port, 
75          InetAddress localAddress, 
76          int localPort
77      ) throws IOException, UnknownHostException;
78  
79      /***
80       * Gets a new socket connection to the given host.
81       * 
82       * @param host the host name/IP
83       * @param port the port on the host
84       * @param localAddress the local host name/IP to bind the socket to
85       * @param localPort the port on the local machine
86       * @param params {@link HttpConnectionParams Http connection parameters}
87       * 
88       * @return Socket a new socket
89       * 
90       * @throws IOException if an I/O error occurs while creating the socket
91       * @throws UnknownHostException if the IP address of the host cannot be
92       * determined
93       * @throws ConnectTimeoutException if socket cannot be connected within the
94       *  given time limit
95       * 
96       * @since 3.0
97       */
98      Socket createSocket(
99          String host, 
100         int port, 
101         InetAddress localAddress, 
102         int localPort,
103         HttpConnectionParams params
104     ) throws IOException, UnknownHostException, ConnectTimeoutException;
105 
106     /***
107      * Gets a new socket connection to the given host.
108      *
109      * @param host the host name/IP
110      * @param port the port on the host
111      *
112      * @return Socket a new socket
113      *
114      * @throws IOException if an I/O error occurs while creating the socket
115      * @throws UnknownHostException if the IP address of the host cannot be
116      * determined
117      */
118     Socket createSocket(
119         String host, 
120         int port
121     ) throws IOException, UnknownHostException;
122 
123 }