public void closeChannel(Channel channel) { // The channel may have already been removed from the future if a timeout occurred, and this method may be called just after. LOGGER.debug("Closing Channel {} ", channel); try { removeAll(channel); Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } catch (Throwable t) { LOGGER.debug("Error closing a connection", t); } openChannels.remove(channel); }
@Override public boolean cancel(boolean force) { cancelTimeouts(); if (isCancelled.getAndSet(true)) return false; // cancel could happen before channel was attached if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (!onThrowableCalled.getAndSet(true)) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } latch.countDown(); runListeners(); return true; }
private void close(Channel channel) { // FIXME pity to have to do this here Channels.setDiscard(channel); channelId2Creation.remove(channel.getId()); Channels.silentlyCloseChannel(channel); }
@Override public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception { // call super to reset the read timeout super.messageReceived(ctx, e); Channel channel = ctx.getChannel(); Object attribute = Channels.getAttribute(channel); if (attribute instanceof Callback) { Object message = e.getMessage(); Callback ac = (Callback) attribute; if (message instanceof HttpChunk) { // the AsyncCallable is to be processed on the last chunk if (HttpChunk.class.cast(message).isLast()) // process the AsyncCallable before passing the message to the protocol ac.call(); // FIXME remove attribute? } else { LOGGER.info("Received unexpected message while expecting a chunk: " + message); ac.call(); Channels.setDiscard(channel); } } else if (attribute instanceof NettyResponseFuture<?>) { NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute; protocol.handle(channel, future, e.getMessage()); } else if (attribute != DiscardEvent.INSTANCE) { // unhandled message LOGGER.debug("Orphan channel {} with attribute {} received message {}, closing", channel, attribute, e.getMessage()); Channels.silentlyCloseChannel(channel); } }
public final void tryToOfferChannelToPool(Channel channel, boolean keepAlive, Object partitionKey) { if (channel.isConnected() && keepAlive && channel.isReadable()) { LOGGER.debug("Adding key: {} for channel {}", partitionKey, channel); Channels.setDiscard(channel); if (channelPool.offer(channel, partitionKey)) { if (maxConnectionsPerHostEnabled) channelId2PartitionKey.putIfAbsent(channel.getId(), partitionKey); } else { // rejected by pool closeChannel(channel); } } else { // not offered closeChannel(channel); } }
Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); webSocket.onClose(closeFrame.getStatusCode(), closeFrame.getReasonText());
private void close(Channel channel) { try { // FIXME pity to have to do this here Channels.setDiscard(channel); channelId2Creation.remove(channel.getId()); channel.close(); } catch (Throwable t) { // noop } } }
public void closeChannel(Channel channel) { removeAll(channel); Channels.setDiscard(channel); // The channel may have already been removed if a timeout occurred, and this method may be called just after. if (channel != null) { LOGGER.debug("Closing Channel {} ", channel); try { channel.close(); } catch (Throwable t) { LOGGER.debug("Error closing a connection", t); } openChannels.remove(channel); } }
public final void tryToOfferChannelToPool(Channel channel, boolean keepAlive, String poolKey) { if (keepAlive && channel.isReadable()) { LOGGER.debug("Adding key: {} for channel {}", poolKey, channel); channelPool.offer(channel, poolKey); if (maxConnectionsPerHostEnabled) channelId2KeyPool.putIfAbsent(channel.getId(), poolKey); Channels.setDiscard(channel); } else { // not offered closeChannel(channel); } }
@Override public boolean cancel(boolean force) { cancelTimeouts(); if (isCancelled.getAndSet(true)) return false; try { Channels.setDiscard(channel); channel.close(); } catch (Throwable t) { // Ignore } if (!onThrowableCalled.getAndSet(true)) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } latch.countDown(); runListeners(); return true; }
LOGGER.info("Received unexpected message while expecting a chunk: " + message); ac.call(); Channels.setDiscard(channel);
Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); webSocket.onClose(closeFrame.getStatusCode(), closeFrame.getReasonText());