Exemplo n.º 1
0
  /**
   * @return calculates a random delay after the timestamp, unless the timestamp is more than 3 days
   *     in the future.
   */
  private static long delay(long now, long timestamp) {
    if (timestamp - now > THREE_DAYS) return 0;

    long delay = UpdateSettings.UPDATE_DELAY.getValue();
    long random = Math.abs(new Random().nextLong() % delay);
    long then = timestamp + random;

    if (LOG.isInfoEnabled()) {
      LOG.info(
          "Delaying Update."
              + "\nNow    : "
              + now
              + " ("
              + new Date(now)
              + ")"
              + "\nStamp  : "
              + timestamp
              + " ("
              + new Date(timestamp)
              + ")"
              + "\nDelay  : "
              + delay
              + " ("
              + CommonUtils.seconds2time(delay / 1000)
              + ")"
              + "\nRandom : "
              + random
              + " ("
              + CommonUtils.seconds2time(random / 1000)
              + ")"
              + "\nThen   : "
              + then
              + " ("
              + new Date(then)
              + ")"
              + "\nDiff   : "
              + (then - now)
              + " ("
              + CommonUtils.seconds2time((then - now) / 1000)
              + ")");
    }

    return Math.max(0, then - now);
  }
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

    if (value != null && value instanceof Long) {
      setText(CommonUtils.seconds2time((Long) value));
    } else {
      setText("");
    }
    return this;
  }