public void disconnect(Connection connection){ try { connection.getClient().disconnect(); } catch( MqttException ex){ Log.e(TAG, "Exception occurred during disconnect: " + ex.getMessage()); } }
connection.getClient().disconnect();
/** * 断开连接 */ public void disconnect(){ try { client.disconnect(); } catch (Exception e) { Log.e(TAG,e.toString()); } }
connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime);
connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); disconnectToken.waitForCompletion(waitForCompletionTime); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); disconnectToken.waitForCompletion(waitForCompletionTime);
@Override protected void onDestroy() { super.onDestroy(); if(client!=null) try { client.disconnect(); } catch (MqttException e) { e.printStackTrace(); } } }
public void disconnect(@NonNull MqttAndroidClient client) throws MqttException { IMqttToken mqttToken = client.disconnect(); mqttToken.setActionCallback(new IMqttActionListener() { @Override public void onSuccess(IMqttToken iMqttToken) { Log.d(TAG, "Successfully disconnected"); } @Override public void onFailure(IMqttToken iMqttToken, Throwable throwable) { Log.d(TAG, "Failed to disconnected " + throwable.toString()); } }); }
public void disconnect() { if (mMqttClient != null && mMqqtClientStatus == MqqtConnectionStatus.CONNECTED) { try { Log.d(TAG, "Mqtt: disconnect"); // mMqqtClientStatus = MqqtConnectionStatus.DISCONNECTING; mMqqtClientStatus = MqqtConnectionStatus.DISCONNECTED; // Note: it seems that the disconnected callback is never invoked. So we fake here that the final state is disconnected mMqttClient.disconnect(null, this); mMqttClient.unregisterResources(); mMqttClient = null; } catch (MqttException e) { Log.e(TAG, "Mqtt:x disconnection error: ", e); } } }
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); disconnectToken.waitForCompletion(waitForCompletionTime);
disconnectToken = mqttClient.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime);
@Override public void close() { Log.v(TAG, "Closing MQTT client [" + mMqttAndroidClient.getClientId() + ""); try { //Disconnect the connection with quiese timeout set to 0, which means disconnect immediately. //Issue the close connection on the callback - this ensures that the connection is properly closed out before resources are freed/reclaimed by the close method. mMqttAndroidClient.disconnect(0,null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { try { mMqttAndroidClient.close(); Log.d(TAG, "Subscription Infrastructure: Successfully closed the connection. Client ID [" + mMqttAndroidClient.getClientId() + "]"); } catch (Exception e) { Log.w(TAG, "Subscription Infrastructure: Error closing connection [" + e + "]"); } } @Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) { Log.w(TAG, "Subscription Infrastructure: Got exception [" + exception +"] when attempting to disconnect clientID " + mMqttAndroidClient.getClientId() + "]" ); } }); } catch (Exception e) { Log.w(TAG, "Got exception when closing MQTT client [" + mMqttAndroidClient.getClientId() + "]", e); } }
/** * Disconnect the client */ private void disconnect() { Connection c = Connections.getInstance(context).getConnection(clientHandle); //if the client is not connected, process the disconnect if (!c.isConnected()) { return; } try { c.getClient().disconnect(null, new ActionListener(context, Action.DISCONNECT, clientHandle, null)); c.changeConnectionStatus(ConnectionStatus.DISCONNECTING); } catch (MqttException e) { Log.e(this.getClass().getCanonicalName(), "Failed to disconnect the client with the handle " + clientHandle, e); c.addAction("Client failed to disconnect"); } }
client.disconnect(); Log.i(LOGTAG, "client disconnected"); } catch (MqttPersistenceException e) {
client.disconnect(); Log.i(LOGTAG, "client disconnected"); } catch (MqttPersistenceException e) {
@Override public void onClick(DialogInterface dialog, int which) { //user pressed continue disconnect client and delete try { connection.getClient().disconnect(); } catch (MqttException e) { e.printStackTrace(); } arrayAdapter.remove(connection); Connections.getInstance(clientConnections).removeConnection(connection); } }
IMqttToken mqttToken = mqttAndroidClient.disconnect();
LogUtil.d(TAG, "disconnect"); try { IMqttToken disconToken = mqttAndroidClient.disconnect(); disconToken.setActionCallback(new IMqttActionListener() { @Override
mClient.disconnect(mContext, mConnectionCb);