Exemplo n.º 1
0
  /** if some pages are too old, remove them */
  public void removeOldPages() {
    // the oldest page is in the front of the list, and the most recent page is in the tail of the
    // list
    int duration = curTime - pageStartTimes.get(0).start_time;
    int count = 0;

    // pay special attention to >=, if ==, still need to go ahead.
    while (duration >= Configuration.T_period) {
      count++;
      if (count >= pageStartTimes.size()) break;
      duration = curTime - pageStartTimes.get(count).start_time + 1;
    }

    // all previous data need to be erased.
    for (int i = 0; i < count - 1; i++) {
      m_pStorageManager.deleteByteArray(pageStartTimes.get(i).pageId);
    }

    // shifting, move all the data Item to the front of the list
    for (int j = count - 1; j >= 0 && j < pageStartTimes.size(); j++) {
      pageStartTimes.set(j - count + 1, pageStartTimes.get(j));
    }

    // erase the data at the tail after shifting
    for (int i = 0; i < count - 1; i++) {
      pageStartTimes.remove(pageStartTimes.size() - 1);
    }
  }