Пример #1
0
  private synchronized void keepAlive() {
    try {
      // Send a keep alive, if there is a connection.
      if (mStarted == true && mConnection != null) {
        mConnection.sendKeepAlive();
      }
    } catch (MqttException e) {
      log("MqttException: " + (e.getMessage() != null ? e.getMessage() : "NULL"), e);

      mConnection.disconnect();
      mConnection = null;
      cancelReconnect();
    }
  }
Пример #2
0
        @Override
        public void onReceive(Context context, Intent intent) {
          // Get network info
          NetworkInfo info =
              (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

          // Is there connectivity?
          boolean hasConnectivity = (info != null && info.isConnected()) ? true : false;

          log("Connectivity changed: connected=" + hasConnectivity);

          if (hasConnectivity) {
            reconnectIfNecessary();
          } else if (mConnection != null) {
            // if there no connectivity, make sure MQTT connection is
            // destroyed
            mConnection.disconnect();
            cancelReconnect();
            mConnection = null;
          }
        }
Пример #3
0
  private synchronized void stop() {
    // Do nothing, if the service is not running.
    if (mStarted == false) {
      Log.w(TAG, "Attempt to stop connection not active.");
      return;
    }

    // Save stopped state in the preferences
    setStarted(false);

    // Remove the connectivity receiver
    unregisterReceiver(mConnectivityChanged);
    // Any existing reconnect timers should be removed, since we explicitly
    // stopping the service.
    cancelReconnect();

    // Destroy the MQTT connection if there is one
    if (mConnection != null) {
      mConnection.disconnect();
      mConnection = null;
    }
  }
Пример #4
0
 @Override
 public boolean subscribe(String rx, int grp, IMessage msg) {
   return connection.subscribe(addDispatcher(rx, grp, msg));
 }
Пример #5
0
 @Override
 public boolean subscribe(IMessage msg) {
   return connection.subscribe(addDispatcher(msg));
 }