1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 }