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;
29  
30  import java.io.IOException;
31  import java.util.concurrent.TimeUnit;
32  
33  import javax.net.ssl.SSLSession;
34  
35  import org.apache.http.HttpClientConnection;
36  import org.apache.http.HttpHost;
37  import org.apache.http.conn.routing.HttpRoute;
38  import org.apache.http.params.HttpParams;
39  import org.apache.http.protocol.HttpContext;
40  
41  /**
42   * A client-side connection with advanced connection logic.
43   * Instances are typically obtained from a connection manager.
44   *
45   * @since 4.0
46   *
47   * @deprecated (4.3) replaced by {@link HttpClientConnectionManager}.
48   */
49  @Deprecated
50  public interface ManagedClientConnection extends
51      HttpClientConnection, HttpRoutedConnection, ManagedHttpClientConnection, ConnectionReleaseTrigger {
52  
53      /**
54       * Indicates whether this connection is secure.
55       * The return value is well-defined only while the connection is open.
56       * It may change even while the connection is open.
57       *
58       * @return  <code>true</code> if this connection is secure,
59       *          <code>false</code> otherwise
60       */
61      @Override
62      boolean isSecure();
63  
64      /**
65       * Obtains the current route of this connection.
66       *
67       * @return  the route established so far, or
68       *          <code>null</code> if not connected
69       */
70      @Override
71      HttpRoute getRoute();
72  
73      /**
74       * Obtains the SSL session of the underlying connection, if any.
75       * If this connection is open, and the underlying socket is an
76       * {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of
77       * that socket is obtained. This is a potentially blocking operation.
78       * <br/>
79       * <b>Note:</b> Whether the underlying socket is an SSL socket
80       * can not necessarily be determined via {@link #isSecure}.
81       * Plain sockets may be considered secure, for example if they are
82       * connected to a known host in the same network segment.
83       * On the other hand, SSL sockets may be considered insecure,
84       * for example depending on the chosen cipher suite.
85       *
86       * @return  the underlying SSL session if available,
87       *          <code>null</code> otherwise
88       */
89      @Override
90      SSLSession getSSLSession();
91  
92      /**
93       * Opens this connection according to the given route.
94       *
95       * @param route     the route along which to open. It will be opened to
96       *                  the first proxy if present, or directly to the target.
97       * @param context   the context for opening this connection
98       * @param params    the parameters for opening this connection
99       *
100      * @throws IOException      in case of a problem
101      */
102     void open(HttpRoute route, HttpContext context, HttpParams params)
103         throws IOException;
104 
105     /**
106      * Indicates that a tunnel to the target has been established.
107      * The route is the one previously passed to {@link #open open}.
108      * Subsequently, {@link #layerProtocol layerProtocol} can be called
109      * to layer the TLS/SSL protocol on top of the tunnelled connection.
110      * <br/>
111      * <b>Note:</b> In HttpClient 3, a call to the corresponding method
112      * would automatically trigger the layering of the TLS/SSL protocol.
113      * This is not the case anymore, you can establish a tunnel without
114      * layering a new protocol over the connection.
115      *
116      * @param secure    <code>true</code> if the tunnel should be considered
117      *                  secure, <code>false</code> otherwise
118      * @param params    the parameters for tunnelling this connection
119      *
120      * @throws IOException  in case of a problem
121      */
122     void tunnelTarget(boolean secure, HttpParams params)
123         throws IOException;
124 
125     /**
126      * Indicates that a tunnel to an intermediate proxy has been established.
127      * This is used exclusively for so-called <i>proxy chains</i>, where
128      * a request has to pass through multiple proxies before reaching the
129      * target. In that case, all proxies but the last need to be tunnelled
130      * when establishing the connection. Tunnelling of the last proxy to the
131      * target is optional and would be indicated via {@link #tunnelTarget}.
132      *
133      * @param next      the proxy to which the tunnel was established.
134      *                  This is <i>not</i> the proxy <i>through</i> which
135      *                  the tunnel was established, but the new end point
136      *                  of the tunnel. The tunnel does <i>not</i> yet
137      *                  reach to the target, use {@link #tunnelTarget}
138      *                  to indicate an end-to-end tunnel.
139      * @param secure    <code>true</code> if the connection should be
140      *                  considered secure, <code>false</code> otherwise
141      * @param params    the parameters for tunnelling this connection
142      *
143      * @throws IOException  in case of a problem
144      */
145     void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
146         throws IOException;
147 
148     /**
149      * Layers a new protocol on top of a {@link #tunnelTarget tunnelled}
150      * connection. This is typically used to create a TLS/SSL connection
151      * through a proxy.
152      * The route is the one previously passed to {@link #open open}.
153      * It is not guaranteed that the layered connection is
154      * {@link #isSecure secure}.
155      *
156      * @param context   the context for layering on top of this connection
157      * @param params    the parameters for layering on top of this connection
158      *
159      * @throws IOException      in case of a problem
160      */
161     void layerProtocol(HttpContext context, HttpParams params)
162         throws IOException;
163 
164     /**
165      * Marks this connection as being in a reusable communication state.
166      * The checkpoints for reuseable communication states (in the absence
167      * of pipelining) are before sending a request and after receiving
168      * the response in its entirety.
169      * The connection will automatically clear the checkpoint when
170      * used for communication. A call to this method indicates that
171      * the next checkpoint has been reached.
172      * <br/>
173      * A reusable communication state is necessary but not sufficient
174      * for the connection to be reused.
175      * A {@link #getRoute route} mismatch, the connection being closed,
176      * or other circumstances might prevent reuse.
177      */
178     void markReusable();
179 
180     /**
181      * Marks this connection as not being in a reusable state.
182      * This can be used immediately before releasing this connection
183      * to prevent its reuse. Reasons for preventing reuse include
184      * error conditions and the evaluation of a
185      * {@link org.apache.http.ConnectionReuseStrategy reuse strategy}.
186      * <br/>
187      * <b>Note:</b>
188      * It is <i>not</i> necessary to call here before writing to
189      * or reading from this connection. Communication attempts will
190      * automatically unmark the state as non-reusable. It can then
191      * be switched back using {@link #markReusable markReusable}.
192      */
193     void unmarkReusable();
194 
195     /**
196      * Indicates whether this connection is in a reusable communication state.
197      * See {@link #markReusable markReusable} and
198      * {@link #unmarkReusable unmarkReusable} for details.
199      *
200      * @return  <code>true</code> if this connection is marked as being in
201      *          a reusable communication state,
202      *          <code>false</code> otherwise
203      */
204     boolean isMarkedReusable();
205 
206     /**
207      * Assigns a state object to this connection. Connection managers may make
208      * use of the connection state when allocating persistent connections.
209      *
210      * @param state The state object
211      */
212     void setState(Object state);
213 
214     /**
215      * Returns the state object associated with this connection.
216      *
217      * @return The state object
218      */
219     Object getState();
220 
221     /**
222      * Sets the duration that this connection can remain idle before it is
223      * reused. The connection should not be used again if this time elapses. The
224      * idle duration must be reset after each request sent over this connection.
225      * The elapsed time starts counting when the connection is released, which
226      * is typically after the headers (and any response body, if present) is
227      * fully consumed.
228      */
229     void setIdleDuration(long duration, TimeUnit unit);
230 
231 }