@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); log.info("{} Disconnected", ctx.channel()); if (!connectionFuture.isDone()) { connectionFuture.completeExceptionally(new PulsarClientException("Connection already closed")); } PulsarClientException e = new PulsarClientException( "Disconnected from server at " + ctx.channel().remoteAddress()); // Fail out all the pending ops pendingRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingLookupRequests.forEach((key, future) -> future.completeExceptionally(e)); waitingLookupRequests.forEach(pair -> pair.getRight().getRight().completeExceptionally(e)); pendingGetLastMessageIdRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingGetTopicsRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingGetSchemaRequests.forEach((key, future) -> future.completeExceptionally(e)); // Notify all attached producers/consumers so they have a chance to reconnect producers.forEach((id, producer) -> producer.connectionClosed(this)); consumers.forEach((id, consumer) -> consumer.connectionClosed(this)); pendingRequests.clear(); pendingLookupRequests.clear(); waitingLookupRequests.clear(); pendingGetLastMessageIdRequests.clear(); pendingGetTopicsRequests.clear(); producers.clear(); consumers.clear(); timeoutTask.cancel(true); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); if (directProxyHandler != null && directProxyHandler.outboundChannel != null) { directProxyHandler.outboundChannel.close(); } if (client != null) { client.close(); } LOG.info("[{}] Connection closed", remoteAddress); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); isActive = false; log.info("Closed connection from {}", remoteAddress); // Connection is gone, close the producers immediately producers.values().forEach((producerFuture) -> { if (producerFuture.isDone() && !producerFuture.isCompletedExceptionally()) { Producer producer = producerFuture.getNow(null); producer.closeNow(); } }); consumers.values().forEach((consumerFuture) -> { Consumer consumer; if (consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) { consumer = consumerFuture.getNow(null); } else { return; } try { consumer.close(); } catch (BrokerServiceException e) { log.warn("Consumer {} was already closed: {}", consumer, e.getMessage(), e); } }); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); log.info("{} Disconnected", ctx.channel()); if (!connectionFuture.isDone()) { connectionFuture.completeExceptionally(new PulsarClientException("Connection already closed")); } PulsarClientException e = new PulsarClientException( "Disconnected from server at " + ctx.channel().remoteAddress()); // Fail out all the pending ops pendingRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingLookupRequests.forEach((key, future) -> future.completeExceptionally(e)); waitingLookupRequests.forEach(pair -> pair.getRight().getRight().completeExceptionally(e)); pendingGetLastMessageIdRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingGetTopicsRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingGetSchemaRequests.forEach((key, future) -> future.completeExceptionally(e)); // Notify all attached producers/consumers so they have a chance to reconnect producers.forEach((id, producer) -> producer.connectionClosed(this)); consumers.forEach((id, consumer) -> consumer.connectionClosed(this)); pendingRequests.clear(); pendingLookupRequests.clear(); waitingLookupRequests.clear(); pendingGetLastMessageIdRequests.clear(); pendingGetTopicsRequests.clear(); producers.clear(); consumers.clear(); }