Package org.apache.http
Interface HttpConnection
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
- All Known Subinterfaces:
HttpClientConnection
,HttpInetConnection
,HttpRoutedConnection
,HttpServerConnection
,ManagedClientConnection
,ManagedHttpClientConnection
,NHttpClientConnection
,NHttpClientIOTarget
,NHttpConnection
,NHttpServerConnection
,NHttpServerIOTarget
,OperatedClientConnection
- All Known Implementing Classes:
AbstractClientConnAdapter
,AbstractHttpClientConnection
,AbstractHttpServerConnection
,AbstractPooledConnAdapter
,BasicPooledConnAdapter
,BHttpConnectionBase
,DefaultBHttpClientConnection
,DefaultBHttpServerConnection
,DefaultClientConnection
,DefaultHttpClientConnection
,DefaultHttpServerConnection
,DefaultManagedHttpClientConnection
,DefaultNHttpClientConnection
,DefaultNHttpServerConnection
,NHttpConnectionBase
,SocketHttpClientConnection
,SocketHttpServerConnection
public interface HttpConnection extends java.io.Closeable
A generic HTTP connection, useful on client and server side.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes this connection gracefully.HttpConnectionMetrics
getMetrics()
Returns a collection of connection metrics.int
getSocketTimeout()
Returns the socket timeout value.boolean
isOpen()
Checks if this connection is open.boolean
isStale()
Checks whether this connection has gone down.void
setSocketTimeout(int timeout)
Sets the socket timeout value.void
shutdown()
Force-closes this connection.
-
-
-
Method Detail
-
close
void close() throws java.io.IOException
Closes this connection gracefully. This method will attempt to flush the internal output buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Useshutdown
instead.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
isOpen
boolean isOpen()
Checks if this connection is open.- Returns:
- true if it is open, false if it is closed.
-
isStale
boolean isStale()
Checks whether this connection has gone down. Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small amount of time before returning a result. It is therefore an expensive operation.- Returns:
true
if attempts to use this connection are likely to succeed, orfalse
if they are likely to fail and this connection should be closed
-
setSocketTimeout
void setSocketTimeout(int timeout)
Sets the socket timeout value.- Parameters:
timeout
- timeout value in milliseconds
-
getSocketTimeout
int getSocketTimeout()
Returns the socket timeout value.- Returns:
- positive value in milliseconds if a timeout is set,
0
if timeout is disabled or-1
if timeout is undefined.
-
shutdown
void shutdown() throws java.io.IOException
Force-closes this connection. This is the only method of a connection which may be called from a different thread to terminate the connection. This method will not attempt to flush the transmitter's internal buffer prior to closing the underlying socket.- Throws:
java.io.IOException
-
getMetrics
HttpConnectionMetrics getMetrics()
Returns a collection of connection metrics.- Returns:
- HttpConnectionMetrics
-
-