本文整理汇总了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();
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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);
}
}
}
示例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());
}
示例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);
}
示例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);
}
}
示例13: exceptionCaught
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
log(() -> format(ctx, "EXCEPTION", cause));
ctx.fireExceptionCaught(cause);
}