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.core5.http;
29  
30  import java.io.IOException;
31  import java.net.SocketAddress;
32  
33  import javax.net.ssl.SSLSession;
34  
35  import org.apache.hc.core5.io.ModalCloseable;
36  
37  /**
38   * A generic HTTP connection, useful on client and server side.
39   *
40   * @since 4.0
41   */
42  public interface HttpConnection extends ModalCloseable {
43  
44      /**
45       * Returns connection endpoint details.
46       */
47      EndpointDetails getEndpointDetails();
48  
49      /**
50       * Returns SSL session or {@code null} if TLS has not been activated.
51       */
52      SSLSession getSSLSession();
53  
54      /**
55       * Closes this connection gracefully.
56       * This method will attempt to flush the internal output
57       * buffer prior to closing the underlying socket.
58       * This method MUST NOT be called from a different thread to force
59       * shutdown of the connection. Use {@link #close shutdown} instead.
60       */
61      @Override
62      void close() throws IOException;
63  
64      /**
65       * Checks if this connection is open.
66       * @return true if it is open, false if it is closed.
67       */
68      boolean isOpen();
69  
70      /**
71       * Sets the socket timeout value.
72       *
73       * @param timeout timeout value in milliseconds
74       */
75      void setSocketTimeoutMillis(int timeout);
76  
77      /**
78       * Returns the socket timeout value.
79       *
80       * @return positive value in milliseconds if a timeout is set,
81       * {@code 0} if timeout is disabled or {@code -1} if
82       * timeout is undefined.
83       */
84      int getSocketTimeoutMillis();
85  
86      /**
87       * Returns protocol version used by this connection or {@code null} if unknown.
88       *
89       * @since 5.0
90       */
91      ProtocolVersion getProtocolVersion();
92  
93      /**
94       * @since 5.0
95       */
96      SocketAddress getRemoteAddress();
97  
98      /**
99       * @since 5.0
100      */
101     SocketAddress getLocalAddress();
102 
103 }