Class DefaultHttp2Connection
java.lang.Object
io.netty.handler.codec.http2.DefaultHttp2Connection
- All Implemented Interfaces:
Http2Connection
Simple implementation of
Http2Connection.-
Nested Class Summary
Nested classes/interfaces inherited from interface Http2Connection
Http2Connection.Endpoint<F>, Http2Connection.Listener, Http2Connection.PropertyKey -
Constructor Summary
ConstructorsConstructorDescriptionDefaultHttp2Connection(boolean server) Creates a new connection with the given settings.DefaultHttp2Connection(boolean server, int maxReservedStreams) Creates a new connection with the given settings. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Http2Connection.Listener listener) Adds a listener of stream life-cycle events.Close this connection.Gets the stream object representing the connection, itself (i.e. stream zero).forEachActiveStream(Http2StreamVisitor visitor) Provide a means of iterating over the collection of active streams.booleanIndicates whether or not aGOAWAYwas received from the remote endpoint.voidgoAwayReceived(int lastKnownStream, long errorCode, ByteBuf debugData) Indicates that aGOAWAYwas received from the remote endpoint and sets the last known stream.booleanIndicates whether or not aGOAWAYwas sent to the remote endpoint.booleangoAwaySent(int lastKnownStream, long errorCode, ByteBuf debugData) Updates the local state of thisHttp2Connectionas a result of aGOAWAYto send to the remote endpoint.booleanisServer()Indicates whether or not the local endpoint for this connection is the server.local()Gets a view of this connection from the localHttp2Connection.Endpoint.newKey()Creates a new key that is unique within thisHttp2Connection.intGets the number of streams that are actively in use (i.e.remote()Gets a view of this connection from the remoteHttp2Connection.Endpoint.voidremoveListener(Http2Connection.Listener listener) Removes a listener of stream life-cycle events.stream(int streamId) Gets the stream if it exists.booleanstreamMayHaveExisted(int streamId) Indicates whether or not the given stream may have existed within this connection.
-
Constructor Details
-
DefaultHttp2Connection
public DefaultHttp2Connection(boolean server) Creates a new connection with the given settings.- Parameters:
server- whether or not this end-point is the server-side of the HTTP/2 connection.
-
DefaultHttp2Connection
public DefaultHttp2Connection(boolean server, int maxReservedStreams) Creates a new connection with the given settings.- Parameters:
server- whether or not this end-point is the server-side of the HTTP/2 connection.maxReservedStreams- The maximum amount of streams which can exist in the reserved state for each endpoint.
-
-
Method Details
-
close
Description copied from interface:Http2ConnectionClose this connection. No more new streams can be created after this point and all streams that exists (active or otherwise) will be closed and removed.Note if iterating active streams via
Http2Connection.forEachActiveStream(Http2StreamVisitor)and an exception is thrown it is necessary to call this method again to ensure the close completes.- Specified by:
closein interfaceHttp2Connection- Parameters:
promise- Will be completed when all streams have been removed, and listeners have been notified.- Returns:
- A future that will be completed when all streams have been removed, and listeners have been notified.
-
addListener
Description copied from interface:Http2ConnectionAdds a listener of stream life-cycle events.- Specified by:
addListenerin interfaceHttp2Connection
-
removeListener
Description copied from interface:Http2ConnectionRemoves a listener of stream life-cycle events. If the same listener was added multiple times then only the first occurrence gets removed.- Specified by:
removeListenerin interfaceHttp2Connection
-
isServer
public boolean isServer()Description copied from interface:Http2ConnectionIndicates whether or not the local endpoint for this connection is the server.- Specified by:
isServerin interfaceHttp2Connection
-
connectionStream
Description copied from interface:Http2ConnectionGets the stream object representing the connection, itself (i.e. stream zero). This object always exists.- Specified by:
connectionStreamin interfaceHttp2Connection
-
stream
Description copied from interface:Http2ConnectionGets the stream if it exists. If not, returnsnull.- Specified by:
streamin interfaceHttp2Connection
-
streamMayHaveExisted
public boolean streamMayHaveExisted(int streamId) Description copied from interface:Http2ConnectionIndicates whether or not the given stream may have existed within this connection. This is a short form for callingHttp2Connection.Endpoint.mayHaveCreatedStream(int)on both endpoints.- Specified by:
streamMayHaveExistedin interfaceHttp2Connection
-
numActiveStreams
public int numActiveStreams()Description copied from interface:Http2ConnectionGets the number of streams that are actively in use (i.e.OPENorHALF CLOSED).- Specified by:
numActiveStreamsin interfaceHttp2Connection
-
forEachActiveStream
Description copied from interface:Http2ConnectionProvide a means of iterating over the collection of active streams.- Specified by:
forEachActiveStreamin interfaceHttp2Connection- Parameters:
visitor- The visitor which will visit each active stream.- Returns:
- The stream before iteration stopped or
nullif iteration went past the end. - Throws:
Http2Exception
-
local
Description copied from interface:Http2ConnectionGets a view of this connection from the localHttp2Connection.Endpoint.- Specified by:
localin interfaceHttp2Connection
-
remote
Description copied from interface:Http2ConnectionGets a view of this connection from the remoteHttp2Connection.Endpoint.- Specified by:
remotein interfaceHttp2Connection
-
goAwayReceived
public boolean goAwayReceived()Description copied from interface:Http2ConnectionIndicates whether or not aGOAWAYwas received from the remote endpoint.- Specified by:
goAwayReceivedin interfaceHttp2Connection
-
goAwayReceived
public void goAwayReceived(int lastKnownStream, long errorCode, ByteBuf debugData) throws Http2Exception Description copied from interface:Http2ConnectionIndicates that aGOAWAYwas received from the remote endpoint and sets the last known stream.- Specified by:
goAwayReceivedin interfaceHttp2Connection- Parameters:
lastKnownStream- The Last-Stream-ID in the GOAWAY frame.errorCode- the Error Code in the GOAWAY frame.debugData- The Additional Debug Data in the GOAWAY frame. Note that reference count ownership belongs to the caller (ownership is not transferred to this method).- Throws:
Http2Exception
-
goAwaySent
public boolean goAwaySent()Description copied from interface:Http2ConnectionIndicates whether or not aGOAWAYwas sent to the remote endpoint.- Specified by:
goAwaySentin interfaceHttp2Connection
-
goAwaySent
public boolean goAwaySent(int lastKnownStream, long errorCode, ByteBuf debugData) throws Http2Exception Description copied from interface:Http2ConnectionUpdates the local state of thisHttp2Connectionas a result of aGOAWAYto send to the remote endpoint.- Specified by:
goAwaySentin interfaceHttp2Connection- Parameters:
lastKnownStream- The Last-Stream-ID in the GOAWAY frame.errorCode- the Error Code in the GOAWAY frame. GOAWAY frame. Note that reference count ownership belongs to the caller (ownership is not transferred to this method).- Returns:
trueif the correspondingGOAWAYframe should be sent to the remote endpoint.- Throws:
Http2Exception
-
newKey
Description copied from interface:Http2ConnectionCreates a new key that is unique within thisHttp2Connection.- Specified by:
newKeyin interfaceHttp2Connection
-