Package org.apache.hc.core5.http.impl.io
Class BHttpConnectionBase
- java.lang.Object
-
- org.apache.hc.core5.http.impl.io.BHttpConnectionBase
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,HttpConnection
,BHttpConnection
,SocketModalCloseable
,ModalCloseable
- Direct Known Subclasses:
DefaultBHttpClientConnection
,DefaultBHttpServerConnection
class BHttpConnectionBase extends java.lang.Object implements BHttpConnection
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
chunkedRequestBuffer
(package private) BasicHttpConnectionMetrics
connMetrics
(package private) EndpointDetails
endpointDetails
(package private) Http1Config
http1Config
(package private) SessionInputBufferImpl
inBuffer
(package private) SessionOutputBufferImpl
outbuffer
(package private) java.util.concurrent.atomic.AtomicReference<SocketHolder>
socketHolderRef
private static Timeout
STALE_CHECK_TIMEOUT
(package private) ProtocolVersion
version
-
Constructor Summary
Constructors Constructor Description BHttpConnectionBase(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
awaitInput(Timeout timeout)
protected void
bind(java.net.Socket socket)
Binds this connection to the givenSocket
.protected void
bind(SocketHolder socketHolder)
void
close()
Closes this connection gracefully.void
close(CloseMode closeMode)
Closes this process or endpoint and releases any system resources associated with it.protected java.io.InputStream
createContentInputStream(long len, SessionInputBuffer buffer, java.io.InputStream inputStream)
protected java.io.OutputStream
createContentOutputStream(long len, SessionOutputBuffer buffer, java.io.OutputStream outputStream, Supplier<java.util.List<? extends Header>> trailers)
(package private) HttpEntity
createIncomingEntity(HttpMessage message, SessionInputBuffer inBuffer, java.io.InputStream inputStream, long len)
protected SocketHolder
ensureOpen()
private int
fillInputBuffer(Timeout timeout)
void
flush()
Writes out all pending buffered data over the open connection.private byte[]
getChunkedRequestBuffer()
EndpointDetails
getEndpointDetails()
Returns this connection's endpoint details.java.net.SocketAddress
getLocalAddress()
Returns this connection's local address ornull
if it is not bound yet.ProtocolVersion
getProtocolVersion()
Returns this connection's protocol version ornull
if unknown.java.net.SocketAddress
getRemoteAddress()
Returns this connection's remote address ornull
if it is not connected yet or unconnected.protected SocketHolder
getSocketHolder()
Timeout
getSocketTimeout()
Returns the socket timeout value.javax.net.ssl.SSLSession
getSSLSession()
Returns this connection's SSL session ornull
if TLS has not been activated.protected void
incrementRequestCount()
protected void
incrementResponseCount()
boolean
isDataAvailable(Timeout timeout)
Checks if input data is available from the connection.boolean
isOpen()
Checks if this connection is open.boolean
isStale()
Checks whether this connection has gone down.void
setSocketTimeout(Timeout timeout)
Sets the socket timeout value.java.lang.String
toString()
-
-
-
Field Detail
-
STALE_CHECK_TIMEOUT
private static final Timeout STALE_CHECK_TIMEOUT
-
http1Config
final Http1Config http1Config
-
inBuffer
final SessionInputBufferImpl inBuffer
-
outbuffer
final SessionOutputBufferImpl outbuffer
-
connMetrics
final BasicHttpConnectionMetrics connMetrics
-
socketHolderRef
final java.util.concurrent.atomic.AtomicReference<SocketHolder> socketHolderRef
-
chunkedRequestBuffer
private byte[] chunkedRequestBuffer
-
version
volatile ProtocolVersion version
-
endpointDetails
volatile EndpointDetails endpointDetails
-
-
Constructor Detail
-
BHttpConnectionBase
BHttpConnectionBase(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder)
-
-
Method Detail
-
ensureOpen
protected SocketHolder ensureOpen() throws java.io.IOException
- Throws:
java.io.IOException
-
bind
protected void bind(java.net.Socket socket) throws java.io.IOException
Binds this connection to the givenSocket
. This socket will be used by the connection to send and receive data.After this method's execution the connection status will be reported as open and the
isOpen()
will returntrue
.- Parameters:
socket
- the socket.- Throws:
java.io.IOException
- in case of an I/O error.
-
bind
protected void bind(SocketHolder socketHolder) throws java.io.IOException
- Throws:
java.io.IOException
-
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.
-
getProtocolVersion
public ProtocolVersion getProtocolVersion()
Description copied from interface:HttpConnection
Returns this connection's protocol version ornull
if unknown.- Specified by:
getProtocolVersion
in interfaceHttpConnection
- Returns:
- this connection's protocol version or
null
if unknown. - Since:
- 5.0
-
getSocketHolder
protected SocketHolder getSocketHolder()
-
createContentOutputStream
protected java.io.OutputStream createContentOutputStream(long len, SessionOutputBuffer buffer, java.io.OutputStream outputStream, Supplier<java.util.List<? extends Header>> trailers)
-
getChunkedRequestBuffer
private byte[] getChunkedRequestBuffer()
-
createContentInputStream
protected java.io.InputStream createContentInputStream(long len, SessionInputBuffer buffer, java.io.InputStream inputStream)
-
createIncomingEntity
HttpEntity createIncomingEntity(HttpMessage message, SessionInputBuffer inBuffer, java.io.InputStream inputStream, long len)
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress()
Description copied from interface:HttpConnection
Returns this connection's remote address ornull
if it is not connected yet or unconnected.- Specified by:
getRemoteAddress
in interfaceHttpConnection
- Returns:
- this connection's remote address or
null
if it is not connected yet or unconnected.
-
getLocalAddress
public java.net.SocketAddress getLocalAddress()
Description copied from interface:HttpConnection
Returns this connection's local address ornull
if it is not bound yet.- Specified by:
getLocalAddress
in interfaceHttpConnection
- Returns:
- this connection's local address or
null
if it is not bound yet.
-
setSocketTimeout
public void setSocketTimeout(Timeout timeout)
Description copied from interface:SocketModalCloseable
Sets the socket timeout value.- Specified by:
setSocketTimeout
in interfaceSocketModalCloseable
- Parameters:
timeout
- timeout value
-
getSocketTimeout
public Timeout getSocketTimeout()
Description copied from interface:SocketModalCloseable
Returns the socket timeout value.- Specified by:
getSocketTimeout
in interfaceSocketModalCloseable
- Returns:
- timeout value.
-
close
public void close(CloseMode closeMode)
Description copied from interface:ModalCloseable
Closes this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.- Specified by:
close
in interfaceModalCloseable
- Parameters:
closeMode
- How to close the receiver.
-
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
-
fillInputBuffer
private int fillInputBuffer(Timeout timeout) throws java.io.IOException
- Throws:
java.io.IOException
-
awaitInput
protected boolean awaitInput(Timeout timeout) throws java.io.IOException
- Throws:
java.io.IOException
-
isDataAvailable
public boolean isDataAvailable(Timeout timeout) throws java.io.IOException
Description copied from interface:BHttpConnection
Checks if input data is available from the connection. May wait for the specified time until some data becomes available. Note that some implementations may completely ignore the timeout parameter.- Specified by:
isDataAvailable
in interfaceBHttpConnection
- Parameters:
timeout
- the maximum time to wait for data- Returns:
- true if data is available; false if there was no data available
even after waiting for
timeout
. - Throws:
java.io.IOException
- if an error happens on the connection
-
isStale
public boolean isStale() throws java.io.IOException
Description copied from interface:BHttpConnection
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 interfaceBHttpConnection
- Returns:
true
if attempts to use this connection are likely to fail and this connection should be closed, orfalse
if they are likely to succeed- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Description copied from interface:BHttpConnection
Writes out all pending buffered data over the open connection.- Specified by:
flush
in interfaceBHttpConnection
- Throws:
java.io.IOException
- in case of an I/O error
-
incrementRequestCount
protected void incrementRequestCount()
-
incrementResponseCount
protected void incrementResponseCount()
-
getSSLSession
public javax.net.ssl.SSLSession getSSLSession()
Description copied from interface:HttpConnection
Returns this connection's SSL session ornull
if TLS has not been activated.- Specified by:
getSSLSession
in interfaceHttpConnection
- Returns:
- this connection's SSL session or
null
if TLS has not been activated.
-
getEndpointDetails
public EndpointDetails getEndpointDetails()
Description copied from interface:HttpConnection
Returns this connection's endpoint details.- Specified by:
getEndpointDetails
in interfaceHttpConnection
- Returns:
- this connection's endpoint details.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-