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