Esempio n. 1
0
 @Override
 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
   // Initialize the encoder, decoder, flow controllers, and internal state.
   encoder.lifecycleManager(this);
   decoder.lifecycleManager(this);
   encoder.flowController().channelHandlerContext(ctx);
   decoder.flowController().channelHandlerContext(ctx);
   byteDecoder = new PrefaceDecoder(ctx);
 }
 @Override
 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
   // Initialize the encoder and decoder.
   encoder.lifecycleManager(this);
   decoder.lifecycleManager(this);
   byteDecoder = new PrefaceDecoder(ctx);
 }
 /**
  * Constructor for pre-configured encoder and decoder. Just sets the {@code this} as the {@link
  * Http2LifecycleManager} and builds them.
  */
 public Http2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder) {
   this.initialSettings = null;
   this.decoder = checkNotNull(decoder, "decoder");
   this.encoder = checkNotNull(encoder, "encoder");
   if (encoder.connection() != decoder.connection()) {
     throw new IllegalArgumentException(
         "Encoder and Decoder do not share the same connection object");
   }
 }
Esempio n. 4
0
 @Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   if (byteDecoder != null) {
     encoder.flowController().channelHandlerContext(null);
     decoder.flowController().channelHandlerContext(null);
     byteDecoder.channelInactive(ctx);
     super.channelInactive(ctx);
     byteDecoder = null;
   }
 }
Esempio n. 5
0
 @Override
 public void flush(ChannelHandlerContext ctx) throws Http2Exception {
   // Trigger pending writes in the remote flow controller.
   encoder.flowController().writePendingBytes();
   try {
     super.flush(ctx);
   } catch (Throwable t) {
     throw new Http2Exception(INTERNAL_ERROR, "Error flushing", t);
   }
 }
  /**
   * Handles the server-side (cleartext) upgrade from HTTP to HTTP/2.
   *
   * @param settings the settings for the remote endpoint.
   */
  public void onHttpServerUpgrade(Http2Settings settings) throws Http2Exception {
    if (!connection().isServer()) {
      throw connectionError(PROTOCOL_ERROR, "Server-side HTTP upgrade requested for a client");
    }
    if (prefaceSent() || decoder.prefaceReceived()) {
      throw connectionError(
          PROTOCOL_ERROR, "HTTP upgrade must occur before HTTP/2 preface is sent or received");
    }

    // Apply the settings but no ACK is necessary.
    encoder.remoteSettings(settings);

    // Create a stream in the half-closed state.
    connection().remote().createStream(HTTP_UPGRADE_STREAM_ID, true);
  }
 public Http2Connection connection() {
   return encoder.connection();
 }