1. /*
  2. * $Header: /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: 1.10 $
  4. * $Date: 2004/05/13 04:01:22 $
  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. package org.apache.commons.httpclient.protocol;
  30. import java.io.IOException;
  31. import java.net.InetAddress;
  32. import java.net.Socket;
  33. import java.net.UnknownHostException;
  34. import org.apache.commons.httpclient.ConnectTimeoutException;
  35. import org.apache.commons.httpclient.params.HttpConnectionParams;
  36. /**
  37. * A factory for creating Sockets.
  38. *
  39. * <p>Both {@link java.lang.Object#equals(java.lang.Object) Object.equals()} and
  40. * {@link java.lang.Object#hashCode() Object.hashCode()} should be overridden appropriately.
  41. * Protocol socket factories are used to uniquely identify <code>Protocol</code>s and
  42. * <code>HostConfiguration</code>s, and <code>equals()</code> and <code>hashCode()</code> are
  43. * required for the correct operation of some connection managers.</p>
  44. *
  45. * @see Protocol
  46. *
  47. * @author Michael Becke
  48. * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  49. *
  50. * @since 2.0
  51. */
  52. public interface ProtocolSocketFactory {
  53. /**
  54. * Gets a new socket connection to the given host.
  55. *
  56. * @param host the host name/IP
  57. * @param port the port on the host
  58. * @param localAddress the local host name/IP to bind the socket to
  59. * @param localPort the port on the local machine
  60. *
  61. * @return Socket a new socket
  62. *
  63. * @throws IOException if an I/O error occurs while creating the socket
  64. * @throws UnknownHostException if the IP address of the host cannot be
  65. * determined
  66. */
  67. Socket createSocket(
  68. String host,
  69. int port,
  70. InetAddress localAddress,
  71. int localPort
  72. ) throws IOException, UnknownHostException;
  73. /**
  74. * Gets a new socket connection to the given host.
  75. *
  76. * @param host the host name/IP
  77. * @param port the port on the host
  78. * @param localAddress the local host name/IP to bind the socket to
  79. * @param localPort the port on the local machine
  80. * @param params {@link HttpConnectionParams Http connection parameters}
  81. *
  82. * @return Socket a new socket
  83. *
  84. * @throws IOException if an I/O error occurs while creating the socket
  85. * @throws UnknownHostException if the IP address of the host cannot be
  86. * determined
  87. * @throws ConnectTimeoutException if socket cannot be connected within the
  88. * given time limit
  89. *
  90. * @since 3.0
  91. */
  92. Socket createSocket(
  93. String host,
  94. int port,
  95. InetAddress localAddress,
  96. int localPort,
  97. HttpConnectionParams params
  98. ) throws IOException, UnknownHostException, ConnectTimeoutException;
  99. /**
  100. * Gets a new socket connection to the given host.
  101. *
  102. * @param host the host name/IP
  103. * @param port the port on the host
  104. *
  105. * @return Socket a new socket
  106. *
  107. * @throws IOException if an I/O error occurs while creating the socket
  108. * @throws UnknownHostException if the IP address of the host cannot be
  109. * determined
  110. */
  111. Socket createSocket(
  112. String host,
  113. int port
  114. ) throws IOException, UnknownHostException;
  115. }