protected String getNextAccountToRetrieve() {
    try {
      if (accountsToRetrieve == null) {
        logInfo("Getting list of accounts");
        NetworkResponse response = gateway.listAccountsForMirroring(getSecurity());
        String resultCode = response.getResultCode();
        if (resultCode.equals(NetworkInterfaceConstants.OK)) {
          accountsToRetrieve = new Vector(response.getResultVector());
          logNotice("Account count:" + accountsToRetrieve.size());
        } else {
          logError("error returned by " + ip + ": " + resultCode);
        }
      }

      if (accountsToRetrieve == null || accountsToRetrieve.size() == 0) {
        accountsToRetrieve = null;
        return null;
      }

      return (String) accountsToRetrieve.remove(0);
    } catch (Exception e) {
      logError("getNextAccountToRetrieve: ", e);
      return null;
    }
  }
 private void scheduleSleep() {
   logNotice(
       "Scheduling mirror sleep for "
           + ip
           + " of "
           + inactiveSleepMillis / 1000 / 60
           + " minutes");
   sleepUntil = System.currentTimeMillis() + inactiveSleepMillis;
 }
  public void processNextBulletin() {
    if (isSleeping()) return;

    BulletinMirroringInformation item = getNextItemToRetrieve();
    if (item == null) {
      scheduleSleep();
      return;
    }

    // TODO handle delete requests when we are propagating deletes.

    try {
      UniversalId uid = item.getUid();
      String publicCode = MartusCrypto.getFormattedPublicCode(uid.getAccountId());
      logNotice("Getting bulletin: " + publicCode + "->" + uid.getLocalId());
      String bur = retrieveBurFromMirror(uid);
      File zip = File.createTempFile("$$$MirroringRetriever", null);
      try {
        zip.deleteOnExit();
        retrieveOneBulletin(zip, uid);
        long zipSize = zip.length();
        long mTime = item.getmTime();
        BulletinHeaderPacket bhp = store.saveZipFileToDatabase(zip, uid.getAccountId(), mTime);
        store.writeBur(bhp, bur);
        store.deleteDel(bhp.getUniversalId());
        logNotice(
            "Stored bulletin:  " + publicCode + "->" + uid.getLocalId() + " Size: " + zipSize);
      } finally {
        zip.delete();
      }
    } catch (ServerErrorException e) {
      logError("Supplier server:", e);
    } catch (ServerNotAvailableException e) {
      // TODO: Notify once per hour that something is wrong
    } catch (Exception e) {
      logError(e);
    }
  }