Package org.apache.http.impl
Class BHttpConnectionBase
- java.lang.Object
-
- org.apache.http.impl.BHttpConnectionBase
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,HttpConnection
,HttpInetConnection
- Direct Known Subclasses:
DefaultBHttpClientConnection
,DefaultBHttpServerConnection
public class BHttpConnectionBase extends java.lang.Object implements HttpConnection, HttpInetConnection
This class serves as a base for allHttpConnection
implementations and provides functionality common to both client and server HTTP connections.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this connection gracefully.java.net.InetAddress
getLocalAddress()
int
getLocalPort()
HttpConnectionMetrics
getMetrics()
Returns a collection of connection metrics.java.net.InetAddress
getRemoteAddress()
int
getRemotePort()
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.java.lang.String
toString()
-
-
-
Method Detail
-
isOpen
public boolean isOpen()
Description copied from interface:HttpConnection
Checks if this connection is open.- Specified by:
isOpen
in interfaceHttpConnection
- Returns:
- true if it is open, false if it is closed.
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
- Specified by:
getLocalAddress
in interfaceHttpInetConnection
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPort
in interfaceHttpInetConnection
-
getRemoteAddress
public java.net.InetAddress getRemoteAddress()
- Specified by:
getRemoteAddress
in interfaceHttpInetConnection
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePort
in interfaceHttpInetConnection
-
setSocketTimeout
public void setSocketTimeout(int timeout)
Description copied from interface:HttpConnection
Sets the socket timeout value.- Specified by:
setSocketTimeout
in interfaceHttpConnection
- Parameters:
timeout
- timeout value in milliseconds
-
getSocketTimeout
public int getSocketTimeout()
Description copied from interface:HttpConnection
Returns the socket timeout value.- Specified by:
getSocketTimeout
in interfaceHttpConnection
- Returns:
- positive value in milliseconds if a timeout is set,
0
if timeout is disabled or-1
if timeout is undefined.
-
shutdown
public void shutdown() throws java.io.IOException
Description copied from interface:HttpConnection
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.- Specified by:
shutdown
in interfaceHttpConnection
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Description copied from interface:HttpConnection
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
- Specified by:
close
in interfaceHttpConnection
- Throws:
java.io.IOException
-
isStale
public boolean isStale()
Description copied from interface:HttpConnection
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.- Specified by:
isStale
in interfaceHttpConnection
- 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
-
getMetrics
public HttpConnectionMetrics getMetrics()
Description copied from interface:HttpConnection
Returns a collection of connection metrics.- Specified by:
getMetrics
in interfaceHttpConnection
- Returns:
- HttpConnectionMetrics
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-