@UnstableApi public class DefaultHttp2Connection extends java.lang.Object implements Http2Connection
Http2Connection
.Modifier and Type | Class and Description |
---|---|
private class |
DefaultHttp2Connection.ActiveStreams
Manages the list of currently active streams.
|
private class |
DefaultHttp2Connection.ConnectionStream
Stream class representing the connection, itself.
|
private class |
DefaultHttp2Connection.DefaultEndpoint<F extends Http2FlowController>
Simple endpoint implementation.
|
(package private) class |
DefaultHttp2Connection.DefaultPropertyKey
Implementation of
PropertyKey that specifies the index position of the property. |
private class |
DefaultHttp2Connection.DefaultStream
Simple stream implementation.
|
(package private) static interface |
DefaultHttp2Connection.Event
Allows events which would modify the collection of active streams to be queued while iterating via
forEachActiveStream(Http2StreamVisitor) . |
private class |
DefaultHttp2Connection.PropertyKeyRegistry
A registry of all stream property keys known by this connection.
|
Http2Connection.Endpoint<F extends Http2FlowController>, Http2Connection.Listener, Http2Connection.PropertyKey
Modifier and Type | Field and Description |
---|---|
(package private) DefaultHttp2Connection.ActiveStreams |
activeStreams |
(package private) Promise<java.lang.Void> |
closePromise |
(package private) DefaultHttp2Connection.ConnectionStream |
connectionStream |
(package private) java.util.List<Http2Connection.Listener> |
listeners
We chose a
List over a Set to avoid allocating an Iterator objects when iterating over
the listeners. |
(package private) DefaultHttp2Connection.DefaultEndpoint<Http2LocalFlowController> |
localEndpoint |
private static InternalLogger |
logger |
(package private) DefaultHttp2Connection.PropertyKeyRegistry |
propertyKeyRegistry |
(package private) DefaultHttp2Connection.DefaultEndpoint<Http2RemoteFlowController> |
remoteEndpoint |
(package private) IntObjectMap<Http2Stream> |
streamMap |
Constructor and Description |
---|
DefaultHttp2Connection(boolean server)
Creates a new connection with the given settings.
|
DefaultHttp2Connection(boolean server,
int maxReservedStreams)
Creates a new connection with the given settings.
|
Modifier and Type | Method and Description |
---|---|
(package private) static Http2Stream.State |
activeState(int streamId,
Http2Stream.State initialState,
boolean isLocal,
boolean halfClosed) |
void |
addListener(Http2Connection.Listener listener)
Adds a listener of stream life-cycle events.
|
Future<java.lang.Void> |
close(Promise<java.lang.Void> promise)
Close this connection.
|
Http2Stream |
connectionStream()
Gets the stream object representing the connection, itself (i.e.
|
Http2Stream |
forEachActiveStream(Http2StreamVisitor visitor)
Provide a means of iterating over the collection of active streams.
|
boolean |
goAwayReceived()
Indicates whether or not a
GOAWAY was received from the remote endpoint. |
void |
goAwayReceived(int lastKnownStream,
long errorCode,
ByteBuf debugData)
Indicates that a
GOAWAY was received from the remote endpoint and sets the last known stream. |
boolean |
goAwaySent()
Indicates whether or not a
GOAWAY was sent to the remote endpoint. |
void |
goAwaySent(int lastKnownStream,
long errorCode,
ByteBuf debugData)
Indicates that a
GOAWAY was sent to the remote endpoint and sets the last known stream. |
(package private) boolean |
isClosed()
Determine if
close(Promise) has been called and no more streams are allowed to be created. |
boolean |
isServer()
Indicates whether or not the local endpoint for this connection is the server.
|
private boolean |
isStreamMapEmpty()
Determine if
streamMap only contains the connection stream. |
Http2Connection.Endpoint<Http2LocalFlowController> |
local()
Gets a view of this connection from the local
Http2Connection.Endpoint . |
Http2Connection.PropertyKey |
newKey()
Creates a new key that is unique within this
Http2Connection . |
(package private) void |
notifyClosed(Http2Stream stream) |
(package private) void |
notifyHalfClosed(Http2Stream stream) |
int |
numActiveStreams()
Gets the number of streams that are actively in use (i.e.
|
Http2Connection.Endpoint<Http2RemoteFlowController> |
remote()
Gets a view of this connection from the remote
Http2Connection.Endpoint . |
void |
removeListener(Http2Connection.Listener listener)
Removes a listener of stream life-cycle events.
|
(package private) void |
removeStream(DefaultHttp2Connection.DefaultStream stream,
java.util.Iterator<?> itr)
Remove a stream from the
streamMap . |
Http2Stream |
stream(int streamId)
Gets the stream if it exists.
|
boolean |
streamMayHaveExisted(int streamId)
Indicates whether or not the given stream may have existed within this connection.
|
(package private) DefaultHttp2Connection.DefaultPropertyKey |
verifyKey(Http2Connection.PropertyKey key)
Verifies that the key is valid and returns it as the internal
DefaultHttp2Connection.DefaultPropertyKey type. |
private static final InternalLogger logger
final IntObjectMap<Http2Stream> streamMap
final DefaultHttp2Connection.PropertyKeyRegistry propertyKeyRegistry
final DefaultHttp2Connection.ConnectionStream connectionStream
final DefaultHttp2Connection.DefaultEndpoint<Http2LocalFlowController> localEndpoint
final DefaultHttp2Connection.DefaultEndpoint<Http2RemoteFlowController> remoteEndpoint
final java.util.List<Http2Connection.Listener> listeners
List
over a Set
to avoid allocating an Iterator
objects when iterating over
the listeners.
Initial size of 4 because the default configuration currently has 3 listeners
(local/remote flow controller and StreamByteDistributor
) and we leave room for 1 extra.
We could be more aggressive but the ArrayList resize will double the size if we are too small.
final DefaultHttp2Connection.ActiveStreams activeStreams
Promise<java.lang.Void> closePromise
public DefaultHttp2Connection(boolean server)
server
- whether or not this end-point is the server-side of the HTTP/2 connection.public DefaultHttp2Connection(boolean server, int maxReservedStreams)
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.final boolean isClosed()
close(Promise)
has been called and no more streams are allowed to be created.public Future<java.lang.Void> close(Promise<java.lang.Void> promise)
Http2Connection
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.
close
in interface Http2Connection
promise
- Will be completed when all streams have been removed, and listeners have been notified.public void addListener(Http2Connection.Listener listener)
Http2Connection
addListener
in interface Http2Connection
public void removeListener(Http2Connection.Listener listener)
Http2Connection
removeListener
in interface Http2Connection
public boolean isServer()
Http2Connection
isServer
in interface Http2Connection
public Http2Stream connectionStream()
Http2Connection
connectionStream
in interface Http2Connection
public Http2Stream stream(int streamId)
Http2Connection
null
.stream
in interface Http2Connection
public boolean streamMayHaveExisted(int streamId)
Http2Connection
Http2Connection.Endpoint.mayHaveCreatedStream(int)
on both endpoints.streamMayHaveExisted
in interface Http2Connection
public int numActiveStreams()
Http2Connection
OPEN
or HALF CLOSED
).numActiveStreams
in interface Http2Connection
public Http2Stream forEachActiveStream(Http2StreamVisitor visitor) throws Http2Exception
Http2Connection
forEachActiveStream
in interface Http2Connection
visitor
- The visitor which will visit each active stream.null
if iteration went past the end.Http2Exception
public Http2Connection.Endpoint<Http2LocalFlowController> local()
Http2Connection
Http2Connection.Endpoint
.local
in interface Http2Connection
public Http2Connection.Endpoint<Http2RemoteFlowController> remote()
Http2Connection
Http2Connection.Endpoint
.remote
in interface Http2Connection
public boolean goAwayReceived()
Http2Connection
GOAWAY
was received from the remote endpoint.goAwayReceived
in interface Http2Connection
public void goAwayReceived(int lastKnownStream, long errorCode, ByteBuf debugData)
Http2Connection
GOAWAY
was received from the remote endpoint and sets the last known stream.goAwayReceived
in interface Http2Connection
public boolean goAwaySent()
Http2Connection
GOAWAY
was sent to the remote endpoint.goAwaySent
in interface Http2Connection
public void goAwaySent(int lastKnownStream, long errorCode, ByteBuf debugData)
Http2Connection
GOAWAY
was sent to the remote endpoint and sets the last known stream.goAwaySent
in interface Http2Connection
private boolean isStreamMapEmpty()
streamMap
only contains the connection stream.void removeStream(DefaultHttp2Connection.DefaultStream stream, java.util.Iterator<?> itr)
streamMap
.stream
- the stream to remove.itr
- an iterator that may be pointing to the stream during iteration and Iterator.remove()
will be
used if non-null
.static Http2Stream.State activeState(int streamId, Http2Stream.State initialState, boolean isLocal, boolean halfClosed) throws Http2Exception
Http2Exception
void notifyHalfClosed(Http2Stream stream)
void notifyClosed(Http2Stream stream)
public Http2Connection.PropertyKey newKey()
Http2Connection
Http2Connection
.newKey
in interface Http2Connection
final DefaultHttp2Connection.DefaultPropertyKey verifyKey(Http2Connection.PropertyKey key)
DefaultHttp2Connection.DefaultPropertyKey
type.java.lang.NullPointerException
- if the key is null
.java.lang.ClassCastException
- if the key is not of type DefaultHttp2Connection.DefaultPropertyKey
.java.lang.IllegalArgumentException
- if the key was not created by this connection.