@Override
    public void close() throws PlcConnectionException {
        if(channel == null) {
            return;
        }

        logger.debug("Closing connection to PLC, await for disconnect = {}", awaitSessionDisconnectComplete);
        channel.pipeline().fireUserEventTriggered(new DisconnectEvent());
        try {
            if (awaitSessionDisconnectComplete) {
                sessionDisconnectCompleteFuture.get(DEFAULT_DISCONNECT_WAIT_TIME, TimeUnit.MILLISECONDS);
            }
        } catch (Exception e) {
            logger.error("Timeout while trying to close connection");
        }

        // The channel might have already been closed by the remote end.
        if (channel.isOpen()) {
            try {
                channel.pipeline().fireUserEventTriggered(new CloseConnectionEvent());
                channel.close().awaitUninterruptibly();
            } catch (RejectedExecutionException ex) {
                if (channel.isOpen()) {
                    throw ex;
                }
            }
        }

        if (!sessionDisconnectCompleteFuture.isDone()) {
            sessionDisconnectCompleteFuture.complete(null);
        }

        // Shutdown the Worker Group
        channelFactory.closeEventLoopForChannel(channel);

        channel = null;
        connected = false;
    }
Close the connection by firstly calling disconnect and waiting for a DisconnectedEvent occurs and then calling
Close() to finish up any other clean up.

@throws PlcConnectionException when a error occurs while closing
plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java