/** * Fail all buffered writes that are left. * See <a href="https://github.com/netty/netty/issues/308>#308</a> for more details. */ public void afterRemove(ChannelHandlerContext ctx) throws Exception { Throwable cause = null; for (;;) { MessageEvent ev = queue.poll(); if (ev == null) { break; } if (cause == null) { cause = new IOException("Unable to flush message"); } ev.getFuture().setFailure(cause); } if (cause != null) { Channels.fireExceptionCaughtLater(ctx.getChannel(), cause); } } }
Channels.fireExceptionCaughtLater(channel, cause);
fireExceptionCaughtLater(ctx, cause);
fireExceptionCaughtLater(ctx.getChannel(), cause);
private void discard(ChannelHandlerContext ctx, boolean fireNow) { ClosedChannelException cause = null; for (;;) { MessageEvent currentEvent = this.currentEvent; if (this.currentEvent == null) { currentEvent = queue.poll(); } else { this.currentEvent = null; } if (currentEvent == null) { break; } Object m = currentEvent.getMessage(); if (m instanceof ChunkedInput) { closeInput((ChunkedInput) m); } // Trigger a ClosedChannelException if (cause == null) { cause = new ClosedChannelException(); } currentEvent.getFuture().setFailure(cause); } if (cause != null) { if (fireNow) { fireExceptionCaught(ctx.getChannel(), cause); } else { fireExceptionCaughtLater(ctx.getChannel(), cause); } } }
/** * Sends an {@link ExceptionEvent} upstream with the specified * {@code cause}. * * @param event the {@link ChannelEvent} which caused a * {@link ChannelHandler} to raise an exception * @param cause the exception raised by a {@link ChannelHandler} */ public void exceptionCaught(ChannelPipeline pipeline, ChannelEvent event, ChannelPipelineException cause) throws Exception { Throwable actualCause = cause.getCause(); if (actualCause == null) { actualCause = cause; } if (isFireExceptionCaughtLater(event, actualCause)) { fireExceptionCaughtLater(event.getChannel(), actualCause); } else { fireExceptionCaught(event.getChannel(), actualCause); } }
fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t);
fireExceptionCaught(channel, e); } else { fireExceptionCaughtLater(channel, e); fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t);
fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t);
static void disconnect(OioDatagramChannel channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean iothread = isIoThread(channel); try { channel.socket.disconnect(); future.setSuccess(); if (connected) { // Notify. if (iothread) { fireChannelDisconnected(channel); } else { fireChannelDisconnectedLater(channel); } } } catch (Throwable t) { future.setFailure(t); if (iothread) { fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t); } } } }
fireExceptionCaught(channel, cause); } else { fireExceptionCaughtLater(channel, cause);
static void disconnect(NioDatagramChannel channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean iothread = isIoThread(channel); try { channel.getDatagramChannel().disconnect(); future.setSuccess(); if (connected) { if (iothread) { fireChannelDisconnected(channel); } else { fireChannelDisconnectedLater(channel); } } } catch (Throwable t) { future.setFailure(t); if (iothread) { fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t); } } }
fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t);
fireExceptionCaught(ctx, t); } else { fireExceptionCaughtLater(ctx, t);
fireExceptionCaughtLater(channel, t);
fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t);
private void failConnect(Throwable cause) { LOGGER.warn("fail connect to unresolved address:{}", originalAddress, cause); Channels.fireExceptionCaughtLater(ctx, cause); } });
static void disconnect(NioDatagramChannel channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean iothread = isIoThread(channel); try { channel.getDatagramChannel().disconnect(); future.setSuccess(); if (connected) { if (iothread) { fireChannelDisconnected(channel); } else { fireChannelDisconnectedLater(channel); } } } catch (Throwable t) { future.setFailure(t); if (iothread) { fireExceptionCaught(channel, t); } else { fireExceptionCaughtLater(channel, t); } } }