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.io;
29  
30  import java.io.IOException;
31  
32  import org.apache.hc.core5.http.HttpConnection;
33  
34  /**
35   * Abstract blocking HTTP connection interface.
36   *
37   * @since 5.0
38   */
39  public interface BHttpConnection extends HttpConnection {
40  
41      /**
42       * Checks if inout data is available from the connection. May wait for
43       * the specified time until some data becomes available. Note that some
44       * implementations may completely ignore the timeout parameter.
45       *
46       * @param timeout the maximum time in milliseconds to wait for data
47       * @return true if data is available; false if there was no data available
48       *         even after waiting for {@code timeout} milliseconds.
49       * @throws IOException if an error happens on the connection
50       */
51      boolean isDataAvailable(int timeout) throws IOException;
52  
53      /**
54       * Checks whether this connection has gone down.
55       * Network connections may get closed during some time of inactivity
56       * for several reasons. The next time a read is attempted on such a
57       * connection it will throw an IOException.
58       * This method tries to alleviate this inconvenience by trying to
59       * find out if a connection is still usable. Implementations may do
60       * that by attempting a read with a very small timeout. Thus this
61       * method may block for a small amount of time before returning a result.
62       * It is therefore an <i>expensive</i> operation.
63       *
64       * @return  {@code true} if attempts to use this connection are
65       *          likely to succeed, or {@code false} if they are likely
66       *          to fail and this connection should be closed
67       */
68      boolean isStale() throws IOException;
69  
70      /**
71       * Writes out all pending buffered data over the open connection.
72       *
73       * @throws java.io.IOException in case of an I/O error
74       */
75      void flush() throws IOException;
76  
77  }