/lib/src/org/apache/http/conn/OperatedClientConnection.java

http://github.com/onedanshow/Screen-Courter · Java · 152 lines · 19 code · 11 blank · 122 comment · 0 complexity · 557485bd39bc50142ecb5760aa1d9775 MD5 · raw file

  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. package org.apache.http.conn;
  28. import java.io.IOException;
  29. import java.net.Socket;
  30. import org.apache.http.HttpClientConnection;
  31. import org.apache.http.HttpHost;
  32. import org.apache.http.HttpInetConnection;
  33. import org.apache.http.params.HttpParams;
  34. /**
  35. * A client-side connection that relies on outside logic to connect sockets to the
  36. * appropriate hosts. It can be operated directly by an application, or through an
  37. * {@link ClientConnectionOperator operator}.
  38. *
  39. * @since 4.0
  40. */
  41. public interface OperatedClientConnection extends HttpClientConnection, HttpInetConnection {
  42. /**
  43. * Obtains the target host for this connection.
  44. * If the connection is to a proxy but not tunnelled, this is
  45. * the proxy. If the connection is tunnelled through a proxy,
  46. * this is the target of the tunnel.
  47. * <br/>
  48. * The return value is well-defined only while the connection is open.
  49. * It may change even while the connection is open,
  50. * because of an {@link #update update}.
  51. *
  52. * @return the host to which this connection is opened
  53. */
  54. HttpHost getTargetHost();
  55. /**
  56. * Indicates whether this connection is secure.
  57. * The return value is well-defined only while the connection is open.
  58. * It may change even while the connection is open,
  59. * because of an {@link #update update}.
  60. *
  61. * @return <code>true</code> if this connection is secure,
  62. * <code>false</code> otherwise
  63. */
  64. boolean isSecure();
  65. /**
  66. * Obtains the socket for this connection.
  67. * The return value is well-defined only while the connection is open.
  68. * It may change even while the connection is open,
  69. * because of an {@link #update update}.
  70. *
  71. * @return the socket for communicating with the
  72. * {@link #getTargetHost target host}
  73. */
  74. Socket getSocket();
  75. /**
  76. * Signals that this connection is in the process of being open.
  77. * <p>
  78. * By calling this method, the connection can be re-initialized
  79. * with a new Socket instance before {@link #openCompleted} is called.
  80. * This enabled the connection to close that socket if
  81. * {@link org.apache.http.HttpConnection#shutdown shutdown}
  82. * is called before it is fully open. Closing an unconnected socket
  83. * will interrupt a thread that is blocked on the connect.
  84. * Otherwise, that thread will either time out on the connect,
  85. * or it returns successfully and then opens this connection
  86. * which was just shut down.
  87. * <p>
  88. * This method can be called multiple times if the connection
  89. * is layered over another protocol. <b>Note:</b> This method
  90. * will <i>not</i> close the previously used socket. It is
  91. * the caller's responsibility to close that socket if it is
  92. * no longer required.
  93. * <p>
  94. * The caller must invoke {@link #openCompleted} in order to complete
  95. * the process.
  96. *
  97. * @param sock the unconnected socket which is about to
  98. * be connected.
  99. * @param target the target host of this connection
  100. */
  101. void opening(Socket sock, HttpHost target)
  102. throws IOException;
  103. /**
  104. * Signals that the connection has been successfully open.
  105. * An attempt to call this method on an open connection will cause
  106. * an exception.
  107. *
  108. * @param secure <code>true</code> if this connection is secure, for
  109. * example if an <code>SSLSocket</code> is used, or
  110. * <code>false</code> if it is not secure
  111. * @param params parameters for this connection. The parameters will
  112. * be used when creating dependent objects, for example
  113. * to determine buffer sizes.
  114. */
  115. void openCompleted(boolean secure, HttpParams params)
  116. throws IOException;
  117. /**
  118. * Updates this connection.
  119. * A connection can be updated only while it is open.
  120. * Updates are used for example when a tunnel has been established,
  121. * or when a TLS/SSL connection has been layered on top of a plain
  122. * socket connection.
  123. * <br/>
  124. * <b>Note:</b> Updating the connection will <i>not</i> close the
  125. * previously used socket. It is the caller's responsibility to close
  126. * that socket if it is no longer required.
  127. *
  128. * @param sock the new socket for communicating with the target host,
  129. * or <code>null</code> to continue using the old socket.
  130. * If <code>null</code> is passed, helper objects that
  131. * depend on the socket should be re-used. In that case,
  132. * some changes in the parameters will not take effect.
  133. * @param target the new target host of this connection
  134. * @param secure <code>true</code> if this connection is now secure,
  135. * <code>false</code> if it is not secure
  136. * @param params new parameters for this connection
  137. */
  138. void update(Socket sock, HttpHost target,
  139. boolean secure, HttpParams params)
  140. throws IOException;
  141. }