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.hc.client5.http.io;
29  
30  import java.io.IOException;
31  import java.net.InetSocketAddress;
32  
33  import org.apache.hc.core5.annotation.Contract;
34  import org.apache.hc.core5.annotation.Internal;
35  import org.apache.hc.core5.annotation.ThreadingBehavior;
36  import org.apache.hc.core5.http.HttpHost;
37  import org.apache.hc.core5.http.io.SocketConfig;
38  import org.apache.hc.core5.http.protocol.HttpContext;
39  import org.apache.hc.core5.util.TimeValue;
40  import org.apache.hc.core5.util.Timeout;
41  
42  /**
43   * Connection operator that performs connection connect and upgrade operations.
44   *
45   * @since 4.4
46   */
47  @Contract(threading = ThreadingBehavior.STATELESS)
48  @Internal
49  public interface HttpClientConnectionOperator {
50  
51      /**
52       * Connect the given managed connection to the remote endpoint.
53       *
54       * @param conn the managed connection.
55       * @param host the address of the opposite endpoint.
56       * @param localAddress the address of the local endpoint.
57       * @param connectTimeout the timeout of the connect operation.
58       * @param socketConfig the socket configuration.
59       * @param context the execution context.
60       */
61      void connect(
62              ManagedHttpClientConnection conn,
63              HttpHost host,
64              InetSocketAddress localAddress,
65              TimeValue connectTimeout,
66              SocketConfig socketConfig,
67              HttpContext context) throws IOException;
68  
69      /**
70       * Connect the given managed connection to the remote endpoint.
71       *
72       * @param conn the managed connection.
73       * @param host the address of the opposite endpoint.
74       * @param localAddress the address of the local endpoint.
75       * @param connectTimeout the timeout of the connect operation.
76       * @param socketConfig the socket configuration.
77       * @param attachment connect request attachment.
78       * @param context the execution context.
79       *
80       * @since 5.2
81       */
82      default void connect(
83              ManagedHttpClientConnection conn,
84              HttpHost host,
85              InetSocketAddress localAddress,
86              Timeout connectTimeout,
87              SocketConfig socketConfig,
88              Object attachment,
89              HttpContext context) throws IOException {
90          connect(conn, host, localAddress, connectTimeout, socketConfig, context);
91      }
92  
93      /**
94       * Upgrades transport security of the given managed connection
95       * by using the TLS security protocol.
96       *
97       * @param conn the managed connection.
98       * @param host the address of the opposite endpoint with TLS security.
99       * @param context the execution context.
100      */
101     void upgrade(
102             ManagedHttpClientConnection conn,
103             HttpHost host,
104             HttpContext context) throws IOException;
105 
106     /**
107      * Upgrades transport security of the given managed connection
108      * by using the TLS security protocol.
109      *
110      * @param conn the managed connection.
111      * @param host the address of the opposite endpoint with TLS security.
112      * @param attachment connect request attachment.
113      * @param context the execution context.
114      *
115      * @since 5.2
116      */
117     default void upgrade(
118             ManagedHttpClientConnection conn,
119             HttpHost host,
120             Object attachment,
121             HttpContext context) throws IOException {
122         upgrade(conn, host, context);
123     }
124 
125 }