當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelHandlerContext.fireExceptionCaught方法代碼示例

本文整理匯總了Java中io.netty.channel.ChannelHandlerContext.fireExceptionCaught方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelHandlerContext.fireExceptionCaught方法的具體用法?Java ChannelHandlerContext.fireExceptionCaught怎麽用?Java ChannelHandlerContext.fireExceptionCaught使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.channel.ChannelHandlerContext的用法示例。


在下文中一共展示了ChannelHandlerContext.fireExceptionCaught方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exceptionCaught

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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();
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:26,代碼來源:NettyClient.java

示例2: decode

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:24,代碼來源:ThriftUnframedDecoder.java

示例3: channelInactive

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:17,代碼來源:NettyClientHandler.java

示例4: exceptionCaught

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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);
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:17,代碼來源:LoggerHandler.java

示例5: channelRead

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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;
  }
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:25,代碼來源:InitiateSslHandler.java

示例6: channelRead

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:20,代碼來源:AbstractRPCChannelHandler.java

示例7: readTimedOut

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
/**
 * 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;
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:11,代碼來源:ReadTimeoutHandler.java

示例8: exceptionCaught

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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);
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:11,代碼來源:AbstractListenerHandler.java

示例9: channelRead0

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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);
		}
	}
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:16,代碼來源:OFChannelHandler.java

示例10: channelInactive

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("inactive");
        ctx.fireExceptionCaught(new Throwable());
//        ctx.fireChannelRead(new Object());
    }
 
開發者ID:alamby,項目名稱:upgradeToy,代碼行數:7,代碼來源:SimpleServerHandler.java

示例11: exceptionCaught

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
        throws Exception {
    System.out.println(cause);
    ctx.fireExceptionCaught(cause);
}
 
開發者ID:recklessMo,項目名稱:nettyRpc,代碼行數:7,代碼來源:BusinessServerHandler.java

示例12: userEventTriggered

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:56,代碼來源:NettyClientHandler.java

示例13: exceptionCaught

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    log(() -> format(ctx, "EXCEPTION", cause));
    ctx.fireExceptionCaught(cause);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:6,代碼來源:LoggingHandler.java


注:本文中的io.netty.channel.ChannelHandlerContext.fireExceptionCaught方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。