@Override
            protected void initChannel(Channel channel) {
                // Build the protocol stack for communicating with desired protocol.
                ChannelPipeline pipeline = channel.pipeline();
                pipeline.addLast(new ChannelInboundHandlerAdapter() {
                    @Override
                    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                        Stream<ConnectionStateListener> eventListeners = listeners.stream().filter(ConnectionStateListener.class::isInstance)
                            .map(ConnectionStateListener.class::cast);
                        if (evt instanceof ConnectedEvent) {
                            sessionSetupCompleteFuture.complete(null);
                            eventListeners.forEach(ConnectionStateListener::connected);
                        } else if (evt instanceof DisconnectedEvent) {
                            sessionDisconnectCompleteFuture.complete(null);
                            eventListeners.forEach(ConnectionStateListener::disconnected);
                            // Fix for https://github.com/apache/plc4x/issues/801
                            super.userEventTriggered(ctx, evt);
                        } else if (evt instanceof DiscoveredEvent) {
                            sessionDiscoverCompleteFuture.complete(((DiscoveredEvent) evt).getConfiguration());
                        } else if (evt instanceof ConnectEvent || evt instanceof DiscoverEvent) {
                            // Fix for https://github.com/apache/plc4x/issues/801
                            if (!sessionSetupCompleteFuture.isCompletedExceptionally()) {
                                if (awaitSessionSetupComplete) {
                                    setupProtocol(pipeline);
                                }
                                super.userEventTriggered(ctx, evt);
                            }
                        } else {
                            super.userEventTriggered(ctx, evt);
                        }
                    }
                });
                // If any exception goes through the pipeline unhandled, close the connection.
                pipeline.addLast(
                        new ChannelInboundHandlerAdapter() {
                            @Override
                            public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws PlcConnectionException {
                                logger.error("unknown error, close the connection", cause);
                                close();
                            }
                        }
                );
                // Initialize via Transport Layer
                channelFactory.initializePipeline(pipeline);
                // Initialize Protocol Layer
                // Fix for https://github.com/apache/plc4x/issues/801
                if (!awaitSessionSetupComplete) {
                    setupProtocol(pipeline);
                }
            }
Check if the communication channel is active (channel.isActive()) and the driver for a given protocol
has finished establishing the connection.
plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java