-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public final class Http2Connection implements Closeable
A socket connection to a remote peer. A connection hosts streams which can send and receive data.
Many methods in this API are synchronous: the call is completed before the method returns. This is typical for Java but atypical for HTTP/2. This is motivated by exception transparency: an IOException that was triggered by a certain caller can be caught and handled by that caller.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classHttp2Connection.Builderpublic abstract classHttp2Connection.ListenerListener of streams and settings initiated by the peer.
-
Method Summary
Modifier and Type Method Description ProtocolgetProtocol()The protocol as selected using ALPN. synchronized intopenStreamCount()Returns the number of open streams on this connection. synchronized intmaxConcurrentStreams()Http2StreampushStream(int associatedStreamId, List<Header> requestHeaders, boolean out)Returns a new server-initiated stream. Http2StreamnewStream(List<Header> requestHeaders, boolean out)Returns a new locally-initiated stream. voidwriteData(int streamId, boolean outFinished, Buffer buffer, long byteCount)Callers of this method are not thread safe, and sometimes on application threads. voidflush()voidshutdown(ErrorCode statusCode)Degrades this connection such that new streams can neither be created locally, nor acceptedfrom the remote peer. voidclose()Closes this connection. voidstart()Sends any initial frames and starts reading frames from the remote peer. voidsetSettings(Settings settings)Merges {@code settings}into this peer's settings and sends them to the remote peer.synchronized booleanisShutdown()-
-
Method Detail
-
getProtocol
Protocol getProtocol()
The protocol as selected using ALPN.
-
openStreamCount
synchronized int openStreamCount()
Returns the number of open streams on this connection.
-
maxConcurrentStreams
synchronized int maxConcurrentStreams()
-
pushStream
Http2Stream pushStream(int associatedStreamId, List<Header> requestHeaders, boolean out)
Returns a new server-initiated stream.
- Parameters:
associatedStreamId- the stream that triggered the sender to create this stream.out- true to create an output stream that we can use to send data to the remote peer.
-
newStream
Http2Stream newStream(List<Header> requestHeaders, boolean out)
Returns a new locally-initiated stream.
- Parameters:
out- true to create an output stream that we can use to send data to the remote peer.
-
writeData
void writeData(int streamId, boolean outFinished, Buffer buffer, long byteCount)
Callers of this method are not thread safe, and sometimes on application threads. Most often,this method will be called to send a buffer worth of data to the peer.
Writes are subject to the write window of the stream and the connection. Until there is awindow sufficient to send
{@code byteCount}, the caller will block. For example, a user of{@code HttpURLConnection}who flushes more bytes to the output stream than the connection'swrite window will block.Zero
{@code byteCount}writes are not subject to flow control and will not block. The onlyuse case for zero{@code byteCount}is closing a flushed output stream.
-
flush
void flush()
-
shutdown
void shutdown(ErrorCode statusCode)
Degrades this connection such that new streams can neither be created locally, nor acceptedfrom the remote peer. Existing streams are not impacted. This is intended to permit an endpointto gracefully stop accepting new requests without harming previously established streams.
-
close
void close()
Closes this connection. This cancels all open streams and unanswered pings. It closes theunderlying input and output streams and shuts down internal executor services.
-
start
void start()
Sends any initial frames and starts reading frames from the remote peer. This should be calledafter build for all new connections.
-
setSettings
void setSettings(Settings settings)
Merges
{@code settings}into this peer's settings and sends them to the remote peer.
-
isShutdown
synchronized boolean isShutdown()
-
-
-
-