/** {@inheritDoc} */
    @Override
    public void reconnectionSuccessful() {
      Log.d(TAG, "reconnectionSuccessful");
      mApplication.setConnected(true);
      PacketFilter filter =
          new PacketFilter() {

            @Override
            public boolean accept(Packet packet) {
              if (packet instanceof Presence) {
                Presence pres = (Presence) packet;
                if (pres.getType() == Presence.Type.subscribe) return true;
              }
              return false;
            }
          };

      mAdaptee.addPacketListener(
          new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
              String from = packet.getFrom();
              Notification notif =
                  new Notification(
                      android.R.drawable.stat_notify_more,
                      mService.getString(R.string.AcceptContactRequest, from),
                      System.currentTimeMillis());
              notif.flags = Notification.FLAG_AUTO_CANCEL;
              Intent intent = new Intent(mService, Subscription.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("from", from);
              notif.setLatestEventInfo(
                  mService,
                  from,
                  mService.getString(R.string.AcceptContactRequestFrom, from),
                  PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
              int id = packet.hashCode();
              mService.sendNotification(id, notif);
            }
          },
          filter);

      final int n = mRemoteConnListeners.beginBroadcast();

      for (int i = 0; i < n; i++) {
        IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
        try {
          if (listener != null) listener.reconnectionSuccessful();
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
          Log.w(TAG, "Error while triggering remote connection listeners", e);
        }
      }
      mRemoteConnListeners.finishBroadcast();
    }
    /** {@inheritDoc} */
    @Override
    public void reconnectionFailed(Exception arg0) {
      Log.d(TAG, "reconnectionFailed");
      final int r = mRemoteConnListeners.beginBroadcast();

      for (int i = 0; i < r; i++) {
        IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
        try {
          if (listener != null) listener.reconnectionFailed();
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
          Log.w(TAG, "Error while triggering remote connection listeners", e);
        }
      }
      mRemoteConnListeners.finishBroadcast();
    }
    /**
     * Connection failed callback.
     *
     * @param errorMsg smack failure message
     */
    public void connectionFailed(String errorMsg) {
      Log.d(TAG, "Connection Failed");
      final int n = mRemoteConnListeners.beginBroadcast();

      for (int i = 0; i < n; i++) {
        IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
        try {
          if (listener != null) listener.connectionFailed(errorMsg);
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
          Log.w(TAG, "Error while triggering remote connection listeners", e);
        }
      }
      mRemoteConnListeners.finishBroadcast();
      mService.stopSelf();
      resetApplication();
    }