Java Code Examples for io.netty.channel.ChannelHandlerContext.fireExceptionCaught()

The following are Jave code examples for showing how to use fireExceptionCaught() of the io.netty.channel.ChannelHandlerContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: drift   File: ThriftUnframedDecoder.java   View Source Code Vote up 6 votes
private Object decode(ChannelHandlerContext ctx, ByteBuf buffer)
{
    int frameOffset = buffer.readerIndex();
    try {
        TTransport transport = new TChannelBufferInputTransport(buffer);
        TProtocolReader protocol = protocolFactory.getProtocol(transport);

        protocol.readMessageBegin();
        TProtocolUtil.skip(protocol, TType.STRUCT);
        protocol.readMessageEnd();

        int frameLength = buffer.readerIndex() - frameOffset;
        if (frameLength > maxFrameSize) {
            ctx.fireExceptionCaught(new TooLongFrameException("Response message exceeds max size " + maxFrameSize + ": " + frameLength + " - discarded"));
        }

        return buffer.slice(frameOffset, frameLength).retain();
    }
    catch (Throwable th) {
        buffer.readerIndex(frameOffset);
        return null;
    }
}
 
Example 2
Project: hekate   File: NettyClient.java   View Source Code Vote up 6 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable error) throws Exception {
    if (firstError != null) {
        // Handle only the very first error.
        return;
    }

    // Propagate exception through the pipeline if there are some other handlers.
    if (ctx.pipeline().last() != this) {
        ctx.fireExceptionCaught(error);
    }

    if (error instanceof CodecException) {
        // Ignore since this is an application-level error.
        return;
    }

    if (trace) {
        log.trace("Exception caught in state handler [to={}]", id, error);
    }

    firstError = NettyErrorUtils.unwrap(error);

    ctx.close();
}
 
Example 3
Project: hekate   File: NettyClientHandler.java   View Source Code Vote up 6 votes
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    if (metrics != null) {
        metrics.onDisconnect();
    }

    if (state == CONNECTING) {
        state = DISCONNECTED;

        ctx.fireExceptionCaught(new ConnectException("Got disconnected on handshake [channel=" + id + ']'));
    } else {
        state = DISCONNECTED;

        super.channelInactive(ctx);
    }
}
 
Example 4
Project: util4j   File: LoggerHandler.java   View Source Code Vote up 6 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
	if(cause instanceof IOException)
	{
		if (logger.isEnabled(internalLevel)) 
		{
			logger.log(internalLevel,cause.getClass().getName()+":"+cause.getLocalizedMessage());
	    }
		return;
	}
	if (logger.isEnabled(internalLevel)) 
	{
		logger.log(internalLevel, format(ctx, "EXCEPTION", cause),cause);
    }
	ctx.fireExceptionCaught(cause);
}
 
Example 5
Project: reactive-pg-client   File: InitiateSslHandler.java   View Source Code Vote up 6 votes
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  // This must be a single byte buffer - after that follow the SSL handshake
  ByteBuf byteBuf = (ByteBuf) msg;
  byte b = byteBuf.getByte(0);
  byteBuf.release();
  switch (b) {
    case SSL_YES: {
      conn.upgradeToSSL(v -> {
        ctx.pipeline().remove(this);
        upgradeFuture.complete();
      });
      break;
    }
    case SSL_NO: {
      // This case is not tested as our test db is configured for SSL
      ctx.fireExceptionCaught(new Exception("Postgres does not handle SSL"));
      break;
    }
    default:
      ctx.fireExceptionCaught(new Exception("Invalid connection data"));
      break;
  }
}
 
Example 6
Project: fresco_floodlight   File: AbstractRPCChannelHandler.java   View Source Code Vote up 6 votes
@Override
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
    if (message instanceof SyncMessage) {
        handleSyncMessage((SyncMessage)message, ctx.channel());
    } else if (message instanceof List) {
        for (Object i : (List<?>)message) {
            if (i instanceof SyncMessage) {
                try {
                    handleSyncMessage((SyncMessage)i,
                                         ctx.channel());
                } catch (Exception ex) {
                    ctx.fireExceptionCaught(ex);
                }
            }
        }
    } else {
        handleUnknownMessage(ctx, message);
    }
}
 
Example 7
Project: TakinRPC   File: ReadTimeoutHandler.java   View Source Code Vote up 5 votes
/**
 * Is called when a read timeout was detected.
 */
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception {
    if (!closed) {
        ctx.fireExceptionCaught(ReadTimeoutException.INSTANCE);
        ctx.close();
        closed = true;
    }
}
 
Example 8
Project: util4j   File: AbstractListenerHandler.java   View Source Code Vote up 5 votes
@Override
public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
		throws Exception {
	if(cause instanceof IOException)
	{
		return;
	}
	log.error(ctx.channel() + ":"+cause.toString());
	ctx.fireExceptionCaught(cause);
}
 
Example 9
Project: fresco_floodlight   File: OFChannelHandler.java   View Source Code Vote up 5 votes
@Override
public void channelRead0(ChannelHandlerContext ctx, Iterable<OFMessage> msgList) throws Exception {
	for (OFMessage ofm : msgList) {
		try {
			// Do the actual packet processing
			state.processOFMessage(ofm);
		}
		catch (Exception ex) {
			// We are the last handler in the stream, so run the
			// exception through the channel again by passing in
			// ctx.getChannel().
			ctx.fireExceptionCaught(ex);
		}
	}
}
 
Example 10
Project: upgradeToy   File: SimpleServerHandler.java   View Source Code Vote up 4 votes
@Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("inactive");
        ctx.fireExceptionCaught(new Throwable());
//        ctx.fireChannelRead(new Object());
    }
 
Example 11
Project: nettyRpc   File: BusinessServerHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
        throws Exception {
    System.out.println(cause);
    ctx.fireExceptionCaught(cause);
}
 
Example 12
Project: hekate   File: NettyClientHandler.java   View Source Code Vote up 4 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        if (((SslHandshakeCompletionEvent)evt).isSuccess()) {
            if (debug) {
                log.debug("SSL connection established [to={}]", id);
            }

            handshake(ctx);
        }

        super.userEventTriggered(ctx, evt);
    } else if (evt instanceof AutoReadChangeEvent) {
        if (evt == AutoReadChangeEvent.PAUSE) {
            // Completely ignore read timeouts.
            ignoreTimeouts = -1;
        } else {
            // Ignore next timeout.
            ignoreTimeouts = 1;
        }
    } else if (evt instanceof IdleStateEvent) {
        if (state == CONNECTING || state == CONNECTED) {
            IdleStateEvent idle = (IdleStateEvent)evt;

            if (idle.state() == IdleState.WRITER_IDLE) {
                if (hbFlushed) {
                    // Make sure that we don't push multiple heartbeats to the network buffer simultaneously.
                    // Need to perform this check since remote peer can hang and stop reading
                    // while this channel will still be trying to put more and more heartbeats on its send buffer.
                    hbFlushed = false;

                    ctx.writeAndFlush(Heartbeat.INSTANCE).addListener(hbOnFlush);
                }
            } else {
                // Reader idle.
                // Ignore if auto-reading was disabled since in such case we will not read any heartbeats.
                if (ignoreTimeouts != -1 && ctx.channel().config().isAutoRead()) {
                    // Check if timeout should be ignored.
                    if (ignoreTimeouts > 0) {
                        // Decrement the counter of ignored timeouts.
                        ignoreTimeouts--;
                    } else {
                        if (state == CONNECTING) {
                            ctx.fireExceptionCaught(new ConnectTimeoutException("Timeout while connecting to " + id));
                        } else if (state == CONNECTED) {
                            ctx.fireExceptionCaught(new SocketTimeoutException("Timeout while reading data from " + id));
                        }
                    }
                }
            }
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
 
Example 13
Project: aws-sdk-java-v2   File: LoggingHandler.java   View Source Code Vote up 4 votes
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    log(() -> format(ctx, "EXCEPTION", cause));
    ctx.fireExceptionCaught(cause);
}