Example usage for io.netty.channel ChannelHandlerContext fireExceptionCaught

List of usage examples for io.netty.channel ChannelHandlerContext fireExceptionCaught

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext fireExceptionCaught.

Prototype

@Override
    ChannelHandlerContext fireExceptionCaught(Throwable cause);

Source Link

Usage

From source file:com.github.nettybook.ch0.LoggingHandler.java

License:Apache License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "EXCEPTION", cause), cause);
    }//w ww . j a v  a2s . c om
    ctx.fireExceptionCaught(cause);
}

From source file:com.github.pgasync.impl.netty.ByteBufMessageDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (in.readableBytes() == 0) {
        return;/*from  w  ww.  ja  v  a2  s .c o  m*/
    }

    byte id = in.readByte();
    int length = in.readInt();

    Decoder<?> decoder = DECODERS.get(id);
    try {
        if (decoder != null) {
            ByteBuffer buffer = in.nioBuffer();
            out.add(decoder.read(buffer));
            in.skipBytes(buffer.position());
        } else {
            in.skipBytes(length - 4);
        }
    } catch (Throwable t) {
        // broad catch as otherwise the exception is silently dropped
        ctx.fireExceptionCaught(t);
    }
}

From source file:com.github.pgasync.impl.netty.ByteBufMessageEncoder.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception {
    Encoder<Message> encoder = (Encoder<Message>) ENCODERS.get(msg.getClass());

    buffer.clear();/*from ww w  .ja va2 s. co  m*/
    ByteBuffer msgbuf = buffer;
    try {
        while (true) {
            try {
                encoder.write(msg, msgbuf);
                break;
            } catch (BufferOverflowException overflow) {
                // large clob/blob, resize buffer aggressively
                msgbuf = ByteBuffer.allocate(msgbuf.capacity() * 4);
            }
        }

        msgbuf.flip();
        out.writeBytes(msgbuf);
    } catch (Throwable t) {
        // broad catch as otherwise the exception is silently dropped
        ctx.fireExceptionCaught(t);
    }
}

From source file:com.github.pgasync.impl.netty.NettyPgProtocolStream.java

License:Apache License

ChannelHandler newSslInitiator() {
    return new ByteToMessageDecoder() {
        @Override//from   w  ww. j av  a2 s  .c o  m
        protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
            if (in.readableBytes() < 1) {
                return;
            }
            if ('S' != in.readByte()) {
                ctx.fireExceptionCaught(
                        new IllegalStateException("SSL required but not supported by backend server"));
                return;
            }
            ctx.pipeline().remove(this);
            ctx.pipeline().addFirst(SslContextBuilder.forClient()
                    .trustManager(InsecureTrustManagerFactory.INSTANCE).build().newHandler(ctx.alloc()));
        }
    };
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.AbstractHttpHandler.java

License:Open Source License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable t) {
    failAndResetUserPromise(t);
    ctx.fireExceptionCaught(t);
}

From source file:com.heelenyc.im.client.handler.ClientLoginAuthReqHandler.java

License:Apache License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    ctx.fireExceptionCaught(cause);
}

From source file:com.heren.turtle.entry.channel.handler.LoginAuthRespHandler.java

License:Open Source License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    ctx.close();//w ww  .  j a va 2  s . c o  m
    ctx.fireExceptionCaught(cause);
}

From source file:com.jjzhk.Chapter14.netty.LoginAuthRespHandler.java

License:Apache License

public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    cause.printStackTrace();//from  ww w .  j  a v a2s .c  o m
    nodeCheck.remove(ctx.channel().remoteAddress().toString());
    ctx.close();
    ctx.fireExceptionCaught(cause);
}

From source file:com.linecorp.armeria.internal.FlushConsolidationHandler.java

License:Apache License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    // To ensure we not miss to flush anything, do it now.
    flushIfNeeded(ctx, true);//from  w  w  w. j a  v  a2  s  . c  o m
    ctx.fireExceptionCaught(cause);
}

From source file:com.linkedin.r2.transport.http.client.Http2AlpnHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
        if (handshakeEvent.isSuccess()) {
            LOG.debug("SSL handshake succeeded");
            SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
            if (sslHandler == null) {
                ctx.fireExceptionCaught(
                        new IllegalStateException("cannot find a SslHandler in the pipeline (required for "
                                + "application-level protocol negotiation)"));
                return;
            }/* w  w  w .ja  v a2 s  .  co m*/
            String protocol = sslHandler.applicationProtocol();
            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                LOG.debug("HTTP/2 is negotiated");

                // Add HTTP/2 handler
                ctx.pipeline().addAfter("sslHandler", "http2Handler", _http2Handler);

                // Remove handler from pipeline after negotiation is complete
                ctx.pipeline().remove(this);
                _alpnPromise.setSuccess();
            } else {
                LOG.error("Protocol {}, instead of HTTP/2, is negotiated through ALPN", protocol);
                _alpnPromise.setFailure(new IllegalStateException("HTTP/2 ALPN negotiation failed"));
            }
        } else {
            LOG.error("SSL handshake failed", handshakeEvent.cause());
            _alpnPromise.setFailure(handshakeEvent.cause());
        }
    }

    ctx.fireUserEventTriggered(evt);
}