private int processedFailedNotifications() throws CommunicationException, KeystoreException {
    if (useEnhancedNotificationFormat) {
      logger.debug("Reading responses");
      int responsesReceived = ResponsePacketReader.processResponses(this);
      while (responsesReceived > 0) {
        final PushedNotification skippedNotification = null;
        final List<PushedNotification> notificationsToResend = new ArrayList<>();
        boolean foundFirstFail = false;
        for (final PushedNotification notification : pushedNotifications.values()) {
          if (foundFirstFail || !notification.isSuccessful()) {
            if (foundFirstFail) {
              notificationsToResend.add(notification);
            } else {
              foundFirstFail = true;
            }
          }
        }
        pushedNotifications.clear();
        final int toResend = notificationsToResend.size();
        logger.debug("Found " + toResend + " notifications that must be re-sent");
        if (toResend > 0) {
          logger.debug("Restarting connection to resend notifications");
          restartPreviousConnection();
          for (final PushedNotification pushedNotification : notificationsToResend) {
            sendNotification(pushedNotification, false);
          }
        }
        final int remaining = responsesReceived = ResponsePacketReader.processResponses(this);
        if (remaining == 0) {
          logger.debug("No notifications remaining to be resent");
          return 0;
        }
      }
      return responsesReceived;
    } else {
      logger.debug("Not reading responses because using simple notification format");
      return 0;
    }
  }