io.netty.channel.ChannelHandlerContext#fireExceptionCaught ( )源码实例Demo

下面列出了io.netty.channel.ChannelHandlerContext#fireExceptionCaught ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xio   文件: Decoder.java
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
  // uuid
  byte[] uuidBytes = new byte[36];
  in.readBytes(uuidBytes);
  UUID id = UUID.fromString(new String(uuidBytes));

  // op
  byte[] opBytes = new byte[4];
  in.readBytes(opBytes);
  Message.Op op = Message.Op.fromBytes(opBytes);

  // payloadSize
  byte[] payloadSizeBytes = new byte[4];
  in.readBytes(payloadSizeBytes);
  int payloadSize = Ints.fromByteArray(payloadSizeBytes);

  if (in.readableBytes() < payloadSize) {
    ctx.fireExceptionCaught(new DecoderException("Not enough bytes available to decode payload"));
  }

  out.add(in.readRetainedSlice(payloadSize));
  out.add(new Message(id, op));
}
 
源代码2 项目: netty-4.1.22   文件: Http2MultiplexCodec.java
private void onHttp2GoAwayFrame(ChannelHandlerContext ctx, final Http2GoAwayFrame goAwayFrame) {
    try {
        forEachActiveStream(new Http2FrameStreamVisitor() {
            @Override
            public boolean visit(Http2FrameStream stream) {
                final int streamId = stream.id();
                final DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel;
                if (streamId > goAwayFrame.lastStreamId() && connection().local().isValidStreamId(streamId)) {
                    childChannel.pipeline().fireUserEventTriggered(goAwayFrame.retainedDuplicate());
                }
                return true;
            }
        });
    } catch (Http2Exception e) {
        ctx.fireExceptionCaught(e);
        ctx.close();
    } finally {
        // We need to ensure we release the goAwayFrame.
        goAwayFrame.release();
    }
}
 
@Override
@SuppressWarnings("unchecked")
protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) {
    Encoder<Message> encoder = (Encoder<Message>) ENCODERS.get(msg.getClass());

    buffer.clear();
    ByteBuffer msgbuf = buffer;
    try {
        while (true) {
            try {
                encoder.write(msg, msgbuf, encoding);
                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);
    }
}
 
源代码4 项目: reactor-netty   文件: HttpClientMetricsHandler.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
	recorder.incrementErrorsCount(ctx.channel().remoteAddress(),
			path != null ? path : resolveUri(ctx));

	ctx.fireExceptionCaught(cause);
}
 
源代码5 项目: netty.book.kor   文件: LoggingHandler.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "EXCEPTION", cause), cause);
    }
    ctx.fireExceptionCaught(cause);
}
 
源代码6 项目: ari4java   文件: NettyHttpClientHandler.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    this.exception = cause;
    if (!(cause instanceof ReadTimeoutException)) {
        logger.error("Not a read timeout", cause);
    }
    ctx.fireExceptionCaught(cause);
    ctx.close();
}
 
源代码7 项目: tftp4j   文件: TftpExceptionHandler.java
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    try {
        ctx.fireChannelActive();
    } catch (Throwable t) {
        ctx.fireExceptionCaught(t);
    }
}
 
源代码8 项目: netty-4.1.22   文件: SpdySessionHandler.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause instanceof SpdyProtocolException) {
        issueSessionError(ctx, SpdySessionStatus.PROTOCOL_ERROR);
    }

    ctx.fireExceptionCaught(cause);
}
 
源代码9 项目: netty-4.1.22   文件: ProxyHandler.java
@Override
public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (finished) {
        ctx.fireExceptionCaught(cause);
    } else {
        // Exception was raised before the connection attempt is finished.
        setConnectFailure(cause);
    }
}
 
源代码10 项目: r2dbc-mysql   文件: SslBridgeHandler.java
private void handleSslState(ChannelHandlerContext ctx, SslState state) {
    switch (state) {
        case BRIDGING:
            logger.debug("SSL event triggered, enable SSL handler to pipeline");

            MySqlSslConfiguration ssl = this.ssl;
            this.ssl = null;

            if (ssl == null) {
                ctx.fireExceptionCaught(new IllegalStateException("The SSL bridge has used, cannot build SSL handler twice"));
                return;
            }

            SslProvider sslProvider = buildProvider(ssl, context.getServerVersion());
            SslHandler sslHandler = sslProvider.getSslContext().newHandler(ctx.alloc());

            this.sslEngine = sslHandler.engine();

            ctx.pipeline().addBefore(NAME, SSL_NAME, sslHandler);

            break;
        case UNSUPPORTED:
            // Remove self because it is useless. (kick down the ladder!)
            logger.debug("Server unsupported SSL, remove SSL bridge in pipeline");
            ctx.pipeline().remove(NAME);
            break;
    }
    // Ignore another custom SSL states because they are useless.
}
 
源代码11 项目: netty-4.1.22   文件: ServerBootstrap.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final ChannelConfig config = ctx.channel().config();
    if (config.isAutoRead()) {
        // stop accept new connections for 1 second to allow the channel to recover
        // See https://github.com/netty/netty/issues/1328
        config.setAutoRead(false);
        ctx.channel().eventLoop().schedule(enableAutoReadTask, 1, TimeUnit.SECONDS);
    }
    // still let the exceptionCaught event flow through the pipeline to give the user
    // a chance to do something with it
    ctx.fireExceptionCaught(cause);
}
 
源代码12 项目: xio   文件: ClientCodec.java
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof Message) {
    Message message = (Message) msg;
    if (currentPayload == null) {
      log.error("No response payload received for request id '{}': {}", message.getId(), message);
      ctx.fireExceptionCaught(
          new RuntimeException(
              "No response payload received for request id '" + message.getId() + "'"));
      reset();
      return;
    }
    if (error) {
      log.error(
          "Multiple response payloads received for request id '{}': {}",
          message.getId(),
          message);
      ctx.fireExceptionCaught(
          new RuntimeException(
              "Multiple response payloads received for request id '" + message.getId() + "'"));
      reset();
      return;
    }
    Request request = getRequest(getMapping(ctx.channel()), message);
    if (request == null) {
      log.error("Unexpected response received for request id '{}': {}", message.getId(), message);
      ctx.fireExceptionCaught(
          new RuntimeException(
              "Unexpected response received for request id '" + message.getId() + "'"));
      reset();
      return;
    }
    Response response = new Response(message.getId(), currentPayload);
    request.getResponsePromise().set(response);
    reset();
  } else {
    if (currentPayload != null) {
      error = true;
      return;
    }
    currentPayload = msg;
  }
}
 
源代码13 项目: netty-reactive-streams   文件: HandlerSubscriber.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    cancel();
    ctx.fireExceptionCaught(cause);
}
 
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
	ctx.fireExceptionCaught(cause);
}
 
源代码15 项目: iot-dc   文件: ExceptionHandler.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOGGER.error("Error: ", cause);
    ctx.channel().close();
    ctx.fireExceptionCaught(cause);
}
 
源代码16 项目: dubbo-remoting-netty4   文件: NettyCodecAdapter.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    ctx.fireExceptionCaught(cause);
}
 
源代码17 项目: iot-dc   文件: ExceptionHandler.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOGGER.error("Error: ", cause);
    ctx.channel().close();
    ctx.fireExceptionCaught(cause);
}
 
源代码18 项目: dubbo3   文件: NettyCodecAdapter.java
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    ctx.fireExceptionCaught(cause);
}
 
private void onRstStreamRead(Http2ResetFrame resetFrame, ChannelHandlerContext ctx) throws Http2Exception {
    ctx.fireExceptionCaught(new Http2ResetException(resetFrame.errorCode()));
}
 
源代码20 项目: netty-4.1.22   文件: MessageAggregator.java
/**
 * Invoked when an incoming request exceeds the maximum content length.  The default behvaior is to trigger an
 * {@code exceptionCaught()} event with a {@link TooLongFrameException}.当传入请求超过最大内容长度时调用。默认的behvaior用一个TooLongFrameException触发一个exceptionCaught()事件。
 *
 * @param ctx the {@link ChannelHandlerContext}
 * @param oversized the accumulated message up to this point, whose type is {@code S} or {@code O}
 */
protected void handleOversizedMessage(ChannelHandlerContext ctx, S oversized) throws Exception {
    ctx.fireExceptionCaught(
            new TooLongFrameException("content length exceeded " + maxContentLength() + " bytes."));
}