Class AbstractHttp2ConnectionHandlerBuilder<T extends Http2ConnectionHandler,B extends AbstractHttp2ConnectionHandlerBuilder<T,B>>

java.lang.Object
io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder<T,B>
Type Parameters:
T - The type of handler created by this builder.
B - The concrete type of this builder.
Direct Known Subclasses:
Http2ConnectionHandlerBuilder, Http2FrameCodecBuilder, Http2MultiplexCodecBuilder, HttpToHttp2ConnectionHandlerBuilder

public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2ConnectionHandler,B extends AbstractHttp2ConnectionHandlerBuilder<T,B>> extends Object
Abstract base class which defines commonly used features required to build Http2ConnectionHandler instances.

Three ways to build a Http2ConnectionHandler

Let the builder create a Http2ConnectionHandler

Simply call all the necessary setter methods, and then use build() to build a new Http2ConnectionHandler. Setting the following properties are prohibited because they are used for other ways of building a Http2ConnectionHandler. conflicts with this option:

Let the builder use the Http2ConnectionHandler you specified

Call connection(Http2Connection) to tell the builder that you want to build the handler from the Http2Connection you specified. Setting the following properties are prohibited and thus will trigger an IllegalStateException because they conflict with this option.

Let the builder use the Http2ConnectionDecoder and Http2ConnectionEncoder you specified

Call codec(Http2ConnectionDecoder, Http2ConnectionEncoder) to tell the builder that you want to built the handler from the Http2ConnectionDecoder and Http2ConnectionEncoder you specified. Setting the following properties are prohibited and thus will trigger an IllegalStateException because they conflict with this option:

Exposing necessary methods in a subclass

build() method and all property access methods are protected. Choose the methods to expose to the users of your builder implementation and make them public.
  • Field Details

    • DEFAULT_HEADER_SENSITIVITY_DETECTOR

      private static final Http2HeadersEncoder.SensitivityDetector DEFAULT_HEADER_SENSITIVITY_DETECTOR
    • DEFAULT_MAX_RST_FRAMES_PER_CONNECTION_FOR_SERVER

      private static final int DEFAULT_MAX_RST_FRAMES_PER_CONNECTION_FOR_SERVER
      See Also:
    • initialSettings

      private Http2Settings initialSettings
    • frameListener

      private Http2FrameListener frameListener
    • gracefulShutdownTimeoutMillis

      private long gracefulShutdownTimeoutMillis
    • decoupleCloseAndGoAway

      private boolean decoupleCloseAndGoAway
    • flushPreface

      private boolean flushPreface
    • isServer

      private Boolean isServer
    • maxReservedStreams

      private Integer maxReservedStreams
    • connection

      private Http2Connection connection
    • decoder

      private Http2ConnectionDecoder decoder
    • encoder

      private Http2ConnectionEncoder encoder
    • validateHeaders

      private Boolean validateHeaders
    • frameLogger

      private Http2FrameLogger frameLogger
    • headerSensitivityDetector

      private Http2HeadersEncoder.SensitivityDetector headerSensitivityDetector
    • encoderEnforceMaxConcurrentStreams

      private Boolean encoderEnforceMaxConcurrentStreams
    • encoderIgnoreMaxHeaderListSize

      private Boolean encoderIgnoreMaxHeaderListSize
    • promisedRequestVerifier

      private Http2PromisedRequestVerifier promisedRequestVerifier
    • autoAckSettingsFrame

      private boolean autoAckSettingsFrame
    • autoAckPingFrame

      private boolean autoAckPingFrame
    • maxQueuedControlFrames

      private int maxQueuedControlFrames
    • maxConsecutiveEmptyFrames

      private int maxConsecutiveEmptyFrames
    • maxRstFramesPerWindow

      private Integer maxRstFramesPerWindow
    • secondsPerWindow

      private int secondsPerWindow
  • Constructor Details

    • AbstractHttp2ConnectionHandlerBuilder

      public AbstractHttp2ConnectionHandlerBuilder()
  • Method Details

    • initialSettings

      protected Http2Settings initialSettings()
      Sets the Http2Settings to use for the initial connection settings exchange.
    • initialSettings

      protected B initialSettings(Http2Settings settings)
      Sets the Http2Settings to use for the initial connection settings exchange.
    • frameListener

      protected Http2FrameListener frameListener()
      Returns the listener of inbound frames.
      Returns:
      Http2FrameListener if set, or null if not set.
    • frameListener

      protected B frameListener(Http2FrameListener frameListener)
      Sets the listener of inbound frames. This listener will only be set if the decoder's listener is null.
    • gracefulShutdownTimeoutMillis

      protected long gracefulShutdownTimeoutMillis()
      Returns the graceful shutdown timeout of the Http2Connection in milliseconds. Returns -1 if the timeout is indefinite.
    • gracefulShutdownTimeoutMillis

      protected B gracefulShutdownTimeoutMillis(long gracefulShutdownTimeoutMillis)
      Sets the graceful shutdown timeout of the Http2Connection in milliseconds.
    • isServer

      protected boolean isServer()
      Returns if build() will to create a Http2Connection in server mode (true) or client mode (false).
    • server

      protected B server(boolean isServer)
      Sets if build() will to create a Http2Connection in server mode (true) or client mode (false).
    • maxReservedStreams

      protected int maxReservedStreams()
      Get the maximum number of streams which can be in the reserved state at any given time.

      By default this value will be ignored on the server for local endpoint. This is because the RFC provides no way to explicitly communicate a limit to how many states can be in the reserved state, and instead relies on the peer to send RST_STREAM frames when they will be rejected.

    • maxReservedStreams

      protected B maxReservedStreams(int maxReservedStreams)
      Set the maximum number of streams which can be in the reserved state at any given time.
    • connection

      protected Http2Connection connection()
      Returns the Http2Connection to use.
      Returns:
      Http2Connection if set, or null if not set.
    • connection

      protected B connection(Http2Connection connection)
      Sets the Http2Connection to use.
    • decoder

      protected Http2ConnectionDecoder decoder()
      Returns the Http2ConnectionDecoder to use.
      Returns:
      Http2ConnectionDecoder if set, or null if not set.
    • encoder

      protected Http2ConnectionEncoder encoder()
      Returns the Http2ConnectionEncoder to use.
      Returns:
      Http2ConnectionEncoder if set, or null if not set.
    • codec

      protected B codec(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder)
    • isValidateHeaders

      protected boolean isValidateHeaders()
      Returns if HTTP headers should be validated according to RFC 7540, 8.1.2.6.
    • validateHeaders

      protected B validateHeaders(boolean validateHeaders)
      Sets if HTTP headers should be validated according to RFC 7540, 8.1.2.6.
    • frameLogger

      protected Http2FrameLogger frameLogger()
      Returns the logger that is used for the encoder and decoder.
      Returns:
      Http2FrameLogger if set, or null if not set.
    • frameLogger

      protected B frameLogger(Http2FrameLogger frameLogger)
      Sets the logger that is used for the encoder and decoder.
    • encoderEnforceMaxConcurrentStreams

      protected boolean encoderEnforceMaxConcurrentStreams()
      Returns if the encoder should queue frames if the maximum number of concurrent streams would otherwise be exceeded.
    • encoderEnforceMaxConcurrentStreams

      protected B encoderEnforceMaxConcurrentStreams(boolean encoderEnforceMaxConcurrentStreams)
      Sets if the encoder should queue frames if the maximum number of concurrent streams would otherwise be exceeded.
    • encoderEnforceMaxQueuedControlFrames

      protected int encoderEnforceMaxQueuedControlFrames()
      Returns the maximum number of queued control frames that are allowed before the connection is closed. This allows to protected against various attacks that can lead to high CPU / memory usage if the remote-peer floods us with frames that would have us produce control frames, but stops to read from the underlying socket. 0 means no protection is in place.
    • encoderEnforceMaxQueuedControlFrames

      protected B encoderEnforceMaxQueuedControlFrames(int maxQueuedControlFrames)
      Sets the maximum number of queued control frames that are allowed before the connection is closed. This allows to protected against various attacks that can lead to high CPU / memory usage if the remote-peer floods us with frames that would have us produce control frames, but stops to read from the underlying socket. 0 means no protection should be applied.
    • headerSensitivityDetector

      protected Http2HeadersEncoder.SensitivityDetector headerSensitivityDetector()
    • headerSensitivityDetector

      protected B headerSensitivityDetector(Http2HeadersEncoder.SensitivityDetector headerSensitivityDetector)
    • encoderIgnoreMaxHeaderListSize

      protected B encoderIgnoreMaxHeaderListSize(boolean ignoreMaxHeaderListSize)
      Sets if the SETTINGS_MAX_HEADER_LIST_SIZE should be ignored when encoding headers.
      Parameters:
      ignoreMaxHeaderListSize - true to ignore SETTINGS_MAX_HEADER_LIST_SIZE.
      Returns:
      this.
    • initialHuffmanDecodeCapacity

      @Deprecated protected B initialHuffmanDecodeCapacity(int initialHuffmanDecodeCapacity)
      Deprecated.
      Huffman decoding no longer depends on having a decode capacity.
      Does nothing, do not call.
    • promisedRequestVerifier

      protected B promisedRequestVerifier(Http2PromisedRequestVerifier promisedRequestVerifier)
      Returns:
      this.
    • promisedRequestVerifier

      protected Http2PromisedRequestVerifier promisedRequestVerifier()
      Returns:
      the Http2PromisedRequestVerifier to use.
    • decoderEnforceMaxConsecutiveEmptyDataFrames

      protected int decoderEnforceMaxConsecutiveEmptyDataFrames()
      Returns the maximum number of consecutive empty DATA frames (without end_of_stream flag) that are allowed before the connection is closed. This allows to protect against the remote peer flooding us with such frames and so use up a lot of CPU. There is no valid use-case for empty DATA frames without end_of_stream flag. 0 means no protection is in place.
    • decoderEnforceMaxConsecutiveEmptyDataFrames

      protected B decoderEnforceMaxConsecutiveEmptyDataFrames(int maxConsecutiveEmptyFrames)
      Sets the maximum number of consecutive empty DATA frames (without end_of_stream flag) that are allowed before the connection is closed. This allows to protect against the remote peer flooding us with such frames and so use up a lot of CPU. There is no valid use-case for empty DATA frames without end_of_stream flag. 0 means no protection should be applied.
    • decoderEnforceMaxRstFramesPerWindow

      protected B decoderEnforceMaxRstFramesPerWindow(int maxRstFramesPerWindow, int secondsPerWindow)
      Sets the maximum number RST frames that are allowed per window before the connection is closed. This allows to protect against the remote peer flooding us with such frames and so use up a lot of CPU. 0 for any of the parameters means no protection should be applied.
    • autoAckSettingsFrame

      protected B autoAckSettingsFrame(boolean autoAckSettings)
      Determine if settings frame should automatically be acknowledged and applied.
      Returns:
      this.
    • isAutoAckSettingsFrame

      protected boolean isAutoAckSettingsFrame()
      Determine if the SETTINGS frames should be automatically acknowledged and applied.
      Returns:
      true if the SETTINGS frames should be automatically acknowledged and applied.
    • autoAckPingFrame

      protected B autoAckPingFrame(boolean autoAckPingFrame)
      Determine if PING frame should automatically be acknowledged or not.
      Returns:
      this.
    • isAutoAckPingFrame

      protected boolean isAutoAckPingFrame()
      Determine if the PING frames should be automatically acknowledged or not.
      Returns:
      true if the PING frames should be automatically acknowledged.
    • decoupleCloseAndGoAway

      protected B decoupleCloseAndGoAway(boolean decoupleCloseAndGoAway)
      Determine if the ChannelOutboundInvoker.close() should be coupled with goaway and graceful close.
      Parameters:
      decoupleCloseAndGoAway - true to make ChannelOutboundInvoker.close() directly close the underlying transport, and not attempt graceful closure via GOAWAY.
      Returns:
      this.
    • decoupleCloseAndGoAway

      protected boolean decoupleCloseAndGoAway()
      Determine if the ChannelOutboundInvoker.close() should be coupled with goaway and graceful close.
    • flushPreface

      protected B flushPreface(boolean flushPreface)
      Determine if the Preface should be automatically flushed when the Channel becomes active or not.

      Client may choose to opt-out from this automatic behavior and manage flush manually if it's ready to send request frames immediately after the preface. It may help to avoid unnecessary latency.

      Parameters:
      flushPreface - true to automatically flush, false otherwise.
      Returns:
      this.
      See Also:
    • flushPreface

      protected boolean flushPreface()
      Determine if the Preface should be automatically flushed when the Channel becomes active or not.

      Client may choose to opt-out from this automatic behavior and manage flush manually if it's ready to send request frames immediately after the preface. It may help to avoid unnecessary latency.

      Returns:
      true if automatically flushed.
      See Also:
    • build

      protected T build()
    • buildFromConnection

      private T buildFromConnection(Http2Connection connection)
    • buildFromCodec

      private T buildFromCodec(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder)
    • build

      protected abstract T build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) throws Exception
      Implement this method to create a new Http2ConnectionHandler or its subtype instance.

      The return of this method will be subject to the following:

      Throws:
      Exception
    • self

      protected final B self()
      Returns this.
    • enforceNonCodecConstraints

      private void enforceNonCodecConstraints(String rejected)
    • enforceConstraint

      private static void enforceConstraint(String methodName, String rejectorName, Object value)