DefaultHttp2Connection Class — netty Architecture
Architecture documentation for the DefaultHttp2Connection class in DefaultHttp2Connection.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 05fa194d_d048_a70f_6ef9_91439d2abc10["DefaultHttp2Connection"] c1b91a38_3d50_98cc_116d_1d9e5bc49432["DefaultHttp2Connection.java"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|defined in| c1b91a38_3d50_98cc_116d_1d9e5bc49432 2436e3ea_cdfd_653a_db9a_c3f266950da5["DefaultHttp2Connection()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 2436e3ea_cdfd_653a_db9a_c3f266950da5 be7f7706_f416_b2e7_a91c_8e2ec0829253["isClosed()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| be7f7706_f416_b2e7_a91c_8e2ec0829253 4e51c63f_9d46_ed86_5c89_3ee5a0e03ae9["close()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 4e51c63f_9d46_ed86_5c89_3ee5a0e03ae9 29d6508f_3e95_1be9_00cc_bfabefbab70c["addListener()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 29d6508f_3e95_1be9_00cc_bfabefbab70c 4b28fd29_29b8_104c_be94_f5b0cc4b47ea["removeListener()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 4b28fd29_29b8_104c_be94_f5b0cc4b47ea a580cbc2_9c9d_ec2c_6735_cc96a539fca5["isServer()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| a580cbc2_9c9d_ec2c_6735_cc96a539fca5 44148398_82d0_dc3f_4727_8cae8b166c75["Http2Stream()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 44148398_82d0_dc3f_4727_8cae8b166c75 2738ebb0_9cab_ba0b_f25e_11e52ef556a5["streamMayHaveExisted()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 2738ebb0_9cab_ba0b_f25e_11e52ef556a5 fbbdac70_9db5_fbe3_bbb9_fc7c48584cb7["numActiveStreams()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| fbbdac70_9db5_fbe3_bbb9_fc7c48584cb7 da939bd5_95cc_763a_14fc_e44ec32d1d2c["local()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| da939bd5_95cc_763a_14fc_e44ec32d1d2c 95426b94_8450_7e3d_2129_005a78fbde7a["remote()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 95426b94_8450_7e3d_2129_005a78fbde7a d2c4802b_d5e8_0e21_bf51_3cc80a0fd776["goAwayReceived()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| d2c4802b_d5e8_0e21_bf51_3cc80a0fd776 990a08db_3c9e_b13d_affb_e97936d9daed["goAwaySent()"] 05fa194d_d048_a70f_6ef9_91439d2abc10 -->|method| 990a08db_3c9e_b13d_affb_e97936d9daed
Relationship Graph
Source Code
codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java lines 63–1116
public class DefaultHttp2Connection implements Http2Connection {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultHttp2Connection.class);
// Fields accessed by inner classes
final IntObjectMap<Http2Stream> streamMap = new IntObjectHashMap<Http2Stream>();
final PropertyKeyRegistry propertyKeyRegistry = new PropertyKeyRegistry();
final ConnectionStream connectionStream = new ConnectionStream();
final DefaultEndpoint<Http2LocalFlowController> localEndpoint;
final DefaultEndpoint<Http2RemoteFlowController> remoteEndpoint;
/**
* We chose a {@link List} over a {@link Set} to avoid allocating an {@link Iterator} objects when iterating over
* the listeners.
* <p>
* Initial size of 4 because the default configuration currently has 3 listeners
* (local/remote flow controller and {@link 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 List<Listener> listeners = new ArrayList<Listener>(4);
final ActiveStreams activeStreams;
Promise<Void> closePromise;
/**
* Creates a new connection with the given settings.
* @param server whether or not this end-point is the server-side of the HTTP/2 connection.
*/
public DefaultHttp2Connection(boolean server) {
this(server, DEFAULT_MAX_RESERVED_STREAMS);
}
/**
* Creates a new connection with the given settings.
* @param server whether or not this end-point is the server-side of the HTTP/2 connection.
* @param maxReservedStreams The maximum amount of streams which can exist in the reserved state for each endpoint.
*/
public DefaultHttp2Connection(boolean server, int maxReservedStreams) {
activeStreams = new ActiveStreams(listeners);
// Reserved streams are excluded from the SETTINGS_MAX_CONCURRENT_STREAMS limit according to [1] and the RFC
// doesn't define a way to communicate the limit on reserved streams. We rely upon the peer to send RST_STREAM
// in response to any locally enforced limits being exceeded [2].
// [1] https://tools.ietf.org/html/rfc7540#section-5.1.2
// [2] https://tools.ietf.org/html/rfc7540#section-8.2.2
localEndpoint = new DefaultEndpoint<Http2LocalFlowController>(server, server ? MAX_VALUE : maxReservedStreams);
remoteEndpoint = new DefaultEndpoint<Http2RemoteFlowController>(!server, maxReservedStreams);
// Add the connection stream to the map.
streamMap.put(connectionStream.id(), connectionStream);
}
/**
* Determine if {@link #close(Promise)} has been called and no more streams are allowed to be created.
*/
final boolean isClosed() {
return closePromise != null;
}
@Override
public Future<Void> close(final Promise<Void> promise) {
checkNotNull(promise, "promise");
// Since we allow this method to be called multiple times, we must make sure that all the promises are notified
// when all streams are removed and the close operation completes.
if (closePromise != null) {
if (closePromise == promise) {
// Do nothing
} else if (promise instanceof ChannelPromise && ((ChannelFuture) closePromise).isVoid()) {
closePromise = promise;
} else {
PromiseNotifier.cascade(closePromise, promise);
}
} else {
closePromise = promise;
}
if (isStreamMapEmpty()) {
promise.trySuccess(null);
return promise;
}
Iterator<PrimitiveEntry<Http2Stream>> itr = streamMap.entries().iterator();
// We must take care while iterating the streamMap as to not modify while iterating in case there are other code
// paths iterating over the active streams.
if (activeStreams.allowModifications()) {
activeStreams.incrementPendingIterations();
Source
Frequently Asked Questions
What is the DefaultHttp2Connection class?
DefaultHttp2Connection is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java.
Where is DefaultHttp2Connection defined?
DefaultHttp2Connection is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java at line 63.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free