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.Socket; 32 33 import javax.net.ssl.SSLSession; 34 import javax.net.ssl.SSLSocket; 35 36 import org.apache.hc.core5.annotation.Internal; 37 import org.apache.hc.core5.http.io.HttpClientConnection; 38 39 /** 40 * Represents a managed connection whose state and life cycle is managed by 41 * a connection manager. This interface extends {@link HttpClientConnection} 42 * with methods to bind the connection to an arbitrary socket and 43 * to obtain SSL session details. 44 * 45 * @since 4.3 46 */ 47 @Internal 48 public interface ManagedHttpClientConnection extends HttpClientConnection { 49 50 /** 51 * Binds this connection to the given socket. The connection 52 * is considered open if it is bound and the underlying socket 53 * is connection to a remote host. 54 * 55 * @param socket the socket to bind the connection to. 56 */ 57 void bind(Socket socket) throws IOException; 58 59 /** 60 * Binds this connection to the SSL given socket and the underlying network 61 * socket. The connection is considered open if it is bound, the underlying 62 * network socket is connection to a remote host and the SSL socket is 63 * fully initialized (TLS handshake has been successfully executed). 64 * 65 * @param sslSocket the SSL socket to bind the connection to. 66 * @param socket the underlying network socket of the SSL socket. 67 * 68 * @since 5.4 69 */ 70 default void bind(SSLSocket sslSocket, Socket socket) throws IOException { 71 bind(sslSocket); 72 } 73 74 /** 75 * Returns the underlying socket. 76 */ 77 Socket getSocket(); 78 79 /** 80 * Obtains the SSL session of the underlying connection, if any. 81 * If this connection is open, and the underlying socket is an 82 * {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of 83 * that socket is obtained. This is a potentially blocking operation. 84 * 85 * @return the underlying SSL session if available, 86 * {@code null} otherwise 87 */ 88 @Override 89 SSLSession getSSLSession(); 90 91 /** 92 * Puts the connection into idle mode. 93 * 94 * @since 5.0 95 */ 96 void passivate(); 97 98 /** 99 * Restores the connection from idle mode. 100 * 101 * @since 5.0 102 */ 103 void activate(); 104 105 }