code: public static void waitForToken(String siteUri, String token, Long since, Long timeout) throws Exception {
  
      if(!siteUri.endsWith("/system/history")) {
        siteUri += "/system/history";
      }
      siteUri += "/" + token;
      if(since != null) {
        siteUri += "/" + since;
      }
      
      HttpClient httpClient = httpClient();
      HttpGet get = new HttpGet(siteUri);
      Long currentTime = System.currentTimeMillis();
      Long timeoutTime = currentTime + timeout;
      do {
        currentTime = System.currentTimeMillis();
        
        HttpResponse resp = httpClient.execute(get);
        if(resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
          String response = EntityUtils.toString(resp.getEntity());
          if(response != null && response.trim().equalsIgnoreCase("true")) {
            return;
          } else {
            Thread.sleep(1000l);
          }
        } else {
          String errorResponse = EntityUtils.toString(resp.getEntity());
          if(errorResponse != null) {
            throw new Exception(errorResponse.trim());
          } else {
            throw new Exception("Command failed!");
          }
        }
      } while(currentTime < timeoutTime);
      if(currentTime >= timeoutTime) {
        throw new Exception("Timed out waiting for command to complete!");
      }
    }
docs: Waits until a timeout is reached or a token shows up in the history of a site as finished or failed.
  
  @param siteUri The uri to a cadmium site.
  @param token The token that represents a history event to wait for.
  @param since A timestamp to pass on the the cadmium site to set a limit on how far back to check the history for a token.
  @param timeout The timeout in milliseconds to wait for if the token never shows up or fails in the sites log.
  @throws Exception