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.nio;
29  
30  import java.net.SocketAddress;
31  import java.util.concurrent.Future;
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.concurrent.FutureCallback;
37  import org.apache.hc.core5.http.HttpHost;
38  import org.apache.hc.core5.http.protocol.HttpContext;
39  import org.apache.hc.core5.reactor.ConnectionInitiator;
40  import org.apache.hc.core5.util.Timeout;
41  
42  /**
43   * Connection operator that performs connection connect and upgrade operations.
44   *
45   * @since 5.0
46   */
47  @Contract(threading = ThreadingBehavior.STATELESS)
48  @Internal
49  public interface AsyncClientConnectionOperator {
50  
51      /**
52       * Initiates operation to create a connection to the remote endpoint using
53       * the provided {@link ConnectionInitiator}.
54       *
55       * @param connectionInitiator the connection initiator.
56       * @param host the address of the opposite endpoint.
57       * @param localAddress the address of the local endpoint.
58       * @param connectTimeout the timeout of the connect operation.
59       * @param attachment the attachment, which can be any object representing custom parameter
60       *                    of the operation.
61       * @param callback the future result callback.
62       */
63      Future<ManagedAsyncClientConnection> connect(
64              ConnectionInitiator connectionInitiator,
65              HttpHost host,
66              SocketAddress localAddress,
67              Timeout connectTimeout,
68              Object attachment,
69              FutureCallback<ManagedAsyncClientConnection> callback);
70  
71      /**
72       * Initiates operation to create a connection to the remote endpoint using
73       * the provided {@link ConnectionInitiator}.
74       *
75       * @param connectionInitiator the connection initiator.
76       * @param host the address of the opposite endpoint.
77       * @param localAddress the address of the local endpoint.
78       * @param connectTimeout the timeout of the connect operation.
79       * @param attachment the attachment, which can be any object representing custom parameter
80       *                    of the operation.
81       * @param context the execution context.
82       * @param callback the future result callback.
83       * @since 5.2
84       */
85      default Future<ManagedAsyncClientConnection> connect(
86              ConnectionInitiator connectionInitiator,
87              HttpHost host,
88              SocketAddress localAddress,
89              Timeout connectTimeout,
90              Object attachment,
91              HttpContext context,
92              FutureCallback<ManagedAsyncClientConnection> callback) {
93          return connect(connectionInitiator, host, localAddress, connectTimeout,
94              attachment, callback);
95      }
96  
97      /**
98       * Upgrades transport security of the given managed connection
99       * by using the TLS security protocol.
100      *
101      * @param conn the managed connection.
102      * @param host the address of the opposite endpoint with TLS security.
103      * @param attachment the attachment, which can be any object representing custom parameter
104      *                    of the operation.
105      */
106     void upgrade(ManagedAsyncClientConnection conn, HttpHost host, Object attachment);
107 
108     /**
109      * Upgrades transport security of the given managed connection
110      * by using the TLS security protocol.
111      *
112      * @param conn the managed connection.
113      * @param host the address of the opposite endpoint with TLS security.
114      * @param attachment the attachment, which can be any object representing custom parameter
115      *                    of the operation.
116      * @param context the execution context.
117      * @param callback the future result callback.
118      * @since 5.2
119      */
120     default void upgrade(
121             ManagedAsyncClientConnection conn,
122             HttpHost host,
123             Object attachment,
124             HttpContext context,
125             FutureCallback<ManagedAsyncClientConnection> callback) {
126         upgrade(conn, host, attachment, context);
127         if (callback != null) {
128             callback.completed(conn);
129         }
130     }
131 
132     /**
133      * Upgrades transport security of the given managed connection
134      * by using the TLS security protocol.
135      *
136      * @param conn the managed connection.
137      * @param host the address of the opposite endpoint with TLS security.
138      * @param attachment the attachment, which can be any object representing custom parameter
139      *                    of the operation.
140      * @param context the execution context.
141      * @since 5.2
142      */
143     default void upgrade(ManagedAsyncClientConnection conn, HttpHost host, Object attachment, HttpContext context) {
144         upgrade(conn, host, attachment);
145     }
146 
147 }