Happen when device closes connection or stop() has been called.
357396
def connection_lost(self, exc):
        """"""
        if self.state == STATE_RUNNING:
            _LOGGER.warning('Lost connection to deCONZ')
            self.retry()
967879
def close(self):
        
        if not self.is_closed():
            self._closing = True
            # Let the ConnectionActor do the actual close operations.
            # It will do the work on CloseOK
            self.sender.send_Close(
                0, 'Connection closed by application', 0, 0)
            try:
                yield from self.synchroniser.wait(spec.ConnectionCloseOK)
            except AMQPConnectionError:
                # For example if both sides want to close or the connection
                # is closed.
                pass
        else:
            if self._closing:
                log.warn("Called `close` on already closing connection...")
        # finish all pending tasks
        yield from self.protocol.heartbeat_monitor.wait_closed()
676451
public synchronized void stop() {
        if (isRunning()) {
            running.set(false);
            DeviceFinder.getInstance().removeDeviceAnnouncementListener(announcementListener);
            dbServerPorts.clear();
            for (Client client : openClients.values()) {
                try {
                    client.close();
                } catch (Exception e) {
                    logger.warn("Problem closing " + client + " when stopping", e);
                }
            }
            openClients.clear();
            useCounts.clear();
            deliverLifecycleAnnouncement(logger, false);
        }
    }
307160
public void connectionClosed(javax.sql.ConnectionEvent event) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
            Tr.event(this, tc, "connectionClosed", "Notification of connection closed received from the JDBC driver", AdapterUtil.toString(event.getSource()));

        // We have intentionally removed our connection event listener prior to closing the
        // underlying connection. Therefore, if this event ever occurs, it indicates a
        // scenario where the connection has been closed unexpectedly by the JDBC driver
        // or database. We will treat this as a connection error.
        if(isAborted()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(this, tc, "The connection was aborted, so this event will not be processed");
        } else {
            processConnectionErrorOccurredEvent(null, event.getSQLException());
        }
    }
275157
def connectionLost(self, reason):
        
        AMP.connectionLost(self, reason)
        if self.logout is not None:
            self.logout()
            self.boxReceiver = self.logout = None
760402
def close_connection(self):
        ""
        if self._is_connected:
            self._is_connected = False
            self._command_parser.close_when_done()
122751
def on_close(self) -> None:
        """"""
        logger.info('WebSocket CLOSED')
        if self in connections:
            # Remove this connection from connection-list
            connections.remove(self)
        # close if auto_shutdown is enabled and there is no more connection
        if config.auto_shutdown and not is_connected():
            asyncio.ensure_future(self.terminate())
1012444
public void stopConnection() throws CommunicationException, KeystoreException {
		processedFailedNotifications();
		try {
			logger.debug("Closing connection");
			this.socket.close();
		} catch (Exception e) {
			/* Do not complain if connection is already closed... */
		}
	}
506013
public void close() {
        if (connected) {
            try {
                terminal.deactivate();
            }
            catch (Exception ex) {
                logger.debug("Exception occurred while closing UDPMasterConnection", ex);
            }
            connected = false;
        }
    }
1126501
def _close_connection(self):
        """"""
        if (self._mode == PROP_MODE_SERIAL):
            self._serial.close()
        elif (self._mode == PROP_MODE_TCP):
            self._socket.close()
        elif (self._mode == PROP_MODE_FILE):
            self._file.close()
679624
def close(self):
        
        self.stopped.set()
        for event in self.to_be_stopped:
            event.set()
        if self._receiver_thread is not None:
            self._receiver_thread.join()
        self._socket.close()
770559
def stop(self):
        """"""
        self._stop_thread.set()
        # f you want to close the connection in a timely fashion,
        # call shutdown() before close().
        with self._lock:  # Receive thread might use the socket
            self.receive_socket.shutdown(socket.SHUT_RDWR)
            self.receive_socket.close()

        self.send_socket.shutdown(socket.SHUT_RDWR)
        self.send_socket.close()
9121
def closed(self, reason):
        """"""
        self.client.remove_connection(self)
        self.protocol.connection_lost(reason)
        if not isinstance(reason, ConnectionClosed):
            logger.warn("connection closed, reason {}".format(reason))
        else:
            logger.info("connection closed")
180256
def stop(self):
        """"""
        self.reconnect = False
        self.logger.debug("Shutting down.")
        if self.transport:
            self.transport.close()
1303509
def shutdown(opts):
    '''
    
    '''
    try:
        if not NETWORK_DEVICE.get('UP', False):
            raise Exception('not connected!')
        NETWORK_DEVICE.get('DRIVER').close()
    except Exception as error:
        port = NETWORK_DEVICE.get('OPTIONAL_ARGS', {}).get('port')
        log.error(
            'Cannot close connection with %s%s! Please check error: %s',
            NETWORK_DEVICE.get('HOSTNAME', '[unknown hostname]'),
            ':{0}'.format(port) if port else '',
            error
        )

    return True
45293
public void stop() {
        try {
            safeClose(myServerSocket);
            closeAllConnections();
            myThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
1278901
def close(self):
        """"""
        if not self.is_running:
            return

        self._state = CLOSED
        self.logger.debug('closing connection(s)')

        while True:
            try:
                conn = self._connections.get(block=False)
            except Empty:
                break

            conn.close_stream()

        self.on_close.send(self)