@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); 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(); }