<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def close(self):
 """Close the client. This includes closing the Session and CBS authentication layer as well as the Connection. If the client was opened using an external Connection, this will be left intact. No further messages can be sent or received and the client cannot be re-opened. All pending, unsent messages will remain uncleared to allow them to be inspected and queued to a new client. """

        if self.message_handler:
            self.message_handler.destroy()
            self.message_handler = None
        self._shutdown = True
        if self._keep_alive_thread:
            self._keep_alive_thread.join()
            self._keep_alive_thread = None
        if not self._session:
            return  # already closed.
        if not self._connection.cbs:
            _logger.debug("Closing non-CBS session.")
            self._session.destroy()
        else:
            _logger.debug("CBS session pending.")
        self._session = None
        if not self._ext_connection:
            _logger.debug("Closing exclusive connection.")
            self._connection.destroy()
        else:
            _logger.debug("Shared connection remaining open.")
        self._connection = None