// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.handler.codec.http3;

import io.netty.util.internal.logging.InternalLoggerFactory;
import org.jetbrains.annotations.Nullable;
import io.netty.handler.codec.quic.QuicStreamChannel;
import io.netty.handler.codec.quic.QuicException;
import io.netty.channel.socket.ChannelInputShutdownEvent;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.channel.ChannelInboundHandlerAdapter;

public abstract class Http3RequestStreamInboundHandler extends ChannelInboundHandlerAdapter
{
    private static final InternalLogger logger;
    
    @Override
    public final void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
        if (msg instanceof Http3UnknownFrame) {
            this.channelRead(ctx, (Http3UnknownFrame)msg);
        }
        else if (msg instanceof Http3HeadersFrame) {
            this.channelRead(ctx, (Http3HeadersFrame)msg);
        }
        else if (msg instanceof Http3DataFrame) {
            this.channelRead(ctx, (Http3DataFrame)msg);
        }
        else {
            super.channelRead(ctx, msg);
        }
    }
    
    @Override
    public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception {
        if (evt == ChannelInputShutdownEvent.INSTANCE) {
            this.channelInputClosed(ctx);
        }
        ctx.fireUserEventTriggered(evt);
    }
    
    @Override
    public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
        if (cause instanceof QuicException) {
            this.handleQuicException(ctx, (QuicException)cause);
        }
        else if (cause instanceof Http3Exception) {
            this.handleHttp3Exception(ctx, (Http3Exception)cause);
        }
        else {
            ctx.fireExceptionCaught(cause);
        }
    }
    
    protected abstract void channelRead(final ChannelHandlerContext p0, final Http3HeadersFrame p1) throws Exception;
    
    protected abstract void channelRead(final ChannelHandlerContext p0, final Http3DataFrame p1) throws Exception;
    
    protected abstract void channelInputClosed(final ChannelHandlerContext p0) throws Exception;
    
    protected void channelRead(final ChannelHandlerContext ctx, final Http3UnknownFrame frame) {
        frame.release();
    }
    
    protected void handleQuicException(final ChannelHandlerContext ctx, final QuicException exception) {
        Http3RequestStreamInboundHandler.logger.debug("Caught QuicException on channel {}", ctx.channel(), exception);
    }
    
    protected void handleHttp3Exception(final ChannelHandlerContext ctx, final Http3Exception exception) {
        Http3RequestStreamInboundHandler.logger.error("Caught Http3Exception on channel {}", ctx.channel(), exception);
    }
    
    @Nullable
    protected final QuicStreamChannel controlStream(final ChannelHandlerContext ctx) {
        return Http3.getLocalControlStream(ctx.channel().parent());
    }
    
    static {
        logger = InternalLoggerFactory.getInstance(Http3RequestStreamInboundHandler.class);
    }
}
