/** * See {@link ThreadPoolExecutor#shutdownNow()} for how it handles the shutdown. If <code>true * </code> is given to this method it also notifies all {@link ChannelFuture}'s of the not * executed {@link ChannelEventRunnable}'s. * * <p>Be aware that if you call this with <code>false</code> you will need to handle the * notification of the {@link ChannelFuture}'s by your self. So only use this if you really have a * use-case for it. */ public List<Runnable> shutdownNow(boolean notify) { if (!notify) { return super.shutdownNow(); } Throwable cause = null; Set<Channel> channels = null; List<Runnable> tasks = super.shutdownNow(); // loop over all tasks and cancel the ChannelFuture of the ChannelEventRunable's for (Runnable task : tasks) { if (task instanceof ChannelEventRunnable) { if (cause == null) { cause = new IOException("Unable to process queued event"); } ChannelEvent event = ((ChannelEventRunnable) task).getEvent(); event.getFuture().setFailure(cause); if (channels == null) { channels = new HashSet<Channel>(); } // store the Channel of the event for later notification of the exceptionCaught event channels.add(event.getChannel()); } } // loop over all channels and fire an exceptionCaught event if (channels != null) { for (Channel channel : channels) { Channels.fireExceptionCaughtLater(channel, cause); } } return tasks; }
@Override public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception { Channel channel = e.getChannel(); if (channel instanceof SctpServerChannelImpl) { handleServerSocket(e); } else if (channel instanceof SctpChannelImpl) { handleAcceptedSocket(e); } }
/** Handle suspended reads */ protected boolean handleReadSuspend(ChannelHandlerContext ctx, ChannelEvent e) { if (e instanceof ChannelStateEvent) { ChannelStateEvent cse = (ChannelStateEvent) e; if (cse.getState() == ChannelState.INTEREST_OPS && (((Integer) cse.getValue()).intValue() & Channel.OP_READ) != 0) { // setReadable(true) requested boolean readSuspended = ctx.getAttachment() != null; if (readSuspended) { // Drop the request silently if MemoryAwareThreadPool has // set the flag. e.getFuture().setSuccess(); return true; } } } return false; }