private void invalidateCustoms(String dateTime) {
    String invalidsNextToken = null;
    do {
      SelectRequest invalidsRequest =
          new SelectRequest(
              "select `itemName()` from `"
                  + AdWhirlUtil.DOMAIN_CUSTOMS_INVALID
                  + "` where dateTime < '"
                  + dateTime
                  + "'");
      invalidsRequest.setNextToken(invalidsNextToken);
      try {
        SelectResult invalidsResult = sdb.select(invalidsRequest);
        invalidsNextToken = invalidsResult.getNextToken();
        List<Item> invalidsList = invalidsResult.getItems();

        for (Item item : invalidsList) {
          String aid = item.getName();
          deleteInvalid(AdWhirlUtil.DOMAIN_CUSTOMS_INVALID, aid);
        }
      } catch (Exception e) {
        AdWhirlUtil.logException(e, log);

        // Eventually we'll get a 'stale request' error and need to start over.
        invalidsNextToken = null;
      }
    } while (invalidsNextToken != null);
  }
Exemplo n.º 2
0
  /**
   * Get a list of all nodes in the cluster
   *
   * @param app Cluster name
   * @return
   */
  public Set<PriamInstance> getAllIds(String app) {
    AmazonSimpleDBClient simpleDBClient = getSimpleDBClient();
    Set<PriamInstance> inslist = new HashSet<PriamInstance>();
    String nextToken = null;
    do {
      SelectRequest request = new SelectRequest(String.format(ALL_QUERY, app));
      request.setNextToken(nextToken);
      SelectResult result = simpleDBClient.select(request);
      nextToken = result.getNextToken();
      Iterator<Item> itemiter = result.getItems().iterator();
      while (itemiter.hasNext()) {
        inslist.add(transform(itemiter.next()));
      }

    } while (nextToken != null);
    return inslist;
  }
  /*
   * Using the pre-defined query, extracts items from the domain in a determined order using the 'select' operation.
   */
  public synchronized List<HighScore> getHighScores() {
    String query = null;
    switch (this.sortMethod) {
      case PLAYER_SORT:
        query = PLAYER_SORT_QUERY;
        break;
      case SCORE_SORT:
        query = SCORE_SORT_QUERY;
        break;
      default:
        query = NO_SORT_QUERY;
        break;
    }

    SelectRequest selectRequest = new SelectRequest(query).withConsistentRead(true);
    selectRequest.setNextToken(this.nextToken);

    SelectResult response = this.sdbClient.select(selectRequest);
    this.nextToken = response.getNextToken();

    return this.convertItemListToHighScoreList(response.getItems());
  }