@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { decoder.channelInactive(ctx); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { try { decoder.handlerAdded(ctx); } finally { encoder.handlerAdded(ctx); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { decoder.channelRead(ctx, msg); }
/** * Called when the input of the channel was closed which may be because it changed to inactive or because of * {@link ChannelInputShutdownEvent}. */ void channelInputClosed(ChannelHandlerContext ctx, List<Object> out) throws Exception { if (cumulation != null) { callDecode(ctx, cumulation, out); decodeLast(ctx, cumulation, out); } else { decodeLast(ctx, Unpooled.EMPTY_BUFFER, out); } }
/** * Decode the from one {@link ByteBuf} to an other. This method will be called till either the input * {@link ByteBuf} has nothing to read when return from this method or till nothing was read from the input * {@link ByteBuf}. * * @param ctx the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to * @param in the {@link ByteBuf} from which to read data * @param out the {@link List} to which decoded messages should be added * @throws Exception is thrown if an error occurs */ final void decodeRemovalReentryProtection(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { decodeState = STATE_CALLING_CHILD_DECODE; try { decode(ctx, in, out); } finally { boolean removePending = decodeState == STATE_HANDLER_REMOVED_PENDING; decodeState = STATE_INIT; if (removePending) { handlerRemoved(ctx); } } }
cumulation = cumulator.cumulate(ctx.alloc(), cumulation, data); callDecode(ctx, cumulation, out); } catch (DecoderException e) { throw e; discardSomeReadBytes(); fireChannelRead(ctx, out, size); out.recycle();
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { decoder.channelReadComplete(ctx); }
/** * Handles {@link Http2Exception} objects that were thrown from other handlers. Ignores all other exceptions. */ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (getEmbeddedHttp2Exception(cause) != null) { // Some exception in the causality chain is an Http2Exception - handle it. onError(ctx, false, cause); } else { super.exceptionCaught(ctx, cause); } }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { try { decoder.handlerRemoved(ctx); } finally { encoder.handlerRemoved(ctx); } }
@Override public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception { if (decodeState == STATE_CALLING_CHILD_DECODE) { decodeState = STATE_HANDLER_REMOVED_PENDING; return; } ByteBuf buf = cumulation; if (buf != null) { // Directly set this to null so we are sure we not access it in any other method here anymore. cumulation = null; int readable = buf.readableBytes(); if (readable > 0) { ByteBuf bytes = buf.readBytes(readable); buf.release(); ctx.fireChannelRead(bytes); } else { buf.release(); } numReads = 0; ctx.fireChannelReadComplete(); } handlerRemoved0(ctx); }
@Override protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { super.decodeLast(ctx, in, out); if (!handledResponse) { // If the connection has been closed even without receiving anything useful, // it is likely that the server failed to decode the preface string. if (httpPreference == HttpPreference.HTTP2_REQUIRED) { finishWithNegotiationFailure(ctx, H2C, H1C, "too little data to determine the HTTP version"); } else { // We can silently retry with H1C. retryWithH1C(ctx); } } } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { if (byteDecoder == null) { byteDecoder = new PrefaceDecoder(ctx); } byteDecoder.channelActive(ctx); super.channelActive(ctx); }
cumulation = cumulator.cumulate(ctx.alloc(), cumulation, data); callDecode(ctx, cumulation, out); } catch (DecoderException e) { throw e; discardSomeReadBytes(); fireChannelRead(ctx, out, size); out.recycle();
/** * Called when the input of the channel was closed which may be because it changed to inactive or because of * {@link ChannelInputShutdownEvent}. */ void channelInputClosed(ChannelHandlerContext ctx, List<Object> out) throws Exception { if (cumulation != null) { callDecode(ctx, cumulation, out); decodeLast(ctx, cumulation, out); } else { decodeLast(ctx, Unpooled.EMPTY_BUFFER, out); } }
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { decoder.channelReadComplete(ctx); }
/** * Decode the from one {@link ByteBuf} to an other. This method will be called till either the input * {@link ByteBuf} has nothing to read when return from this method or till nothing was read from the input * {@link ByteBuf}. * * @param ctx the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to * @param in the {@link ByteBuf} from which to read data * @param out the {@link List} to which decoded messages should be added * @throws Exception is thrown if an error occurs */ final void decodeRemovalReentryProtection(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { decodeState = STATE_CALLING_CHILD_DECODE; try { decode(ctx, in, out); } finally { boolean removePending = decodeState == STATE_HANDLER_REMOVED_PENDING; decodeState = STATE_INIT; if (removePending) { handlerRemoved(ctx); } } }
@Override public final void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { if (onFailure != null) { onFailure.accept(cause); } else { super.exceptionCaught(ctx, cause); } }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { try { decoder.handlerRemoved(ctx); } finally { encoder.handlerRemoved(ctx); } }
@Override public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception { if (decodeState == STATE_CALLING_CHILD_DECODE) { decodeState = STATE_HANDLER_REMOVED_PENDING; return; } ByteBuf buf = cumulation; if (buf != null) { // Directly set this to null so we are sure we not access it in any other method here anymore. cumulation = null; int readable = buf.readableBytes(); if (readable > 0) { ByteBuf bytes = buf.readBytes(readable); buf.release(); ctx.fireChannelRead(bytes); } else { buf.release(); } numReads = 0; ctx.fireChannelReadComplete(); } handlerRemoved0(ctx); }
@Override protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { super.decodeLast(ctx, in, out);