示例#1
0
  public boolean containsWord(final String word) {
    if (status != STATUS.OPEN) {
      return false;
    }

    final String testWord = normalizeWord(word);

    if (testWord == null) {
      return false;
    }

    // final long startTime = System.currentTimeMillis();
    boolean result = false;

    try {
      final String hashedWord = hashWord(testWord);
      final boolean inDB = localDB.contains(WORDS_DB, hashedWord);
      if (inDB) {
        final long timeStamp = Long.parseLong(localDB.get(WORDS_DB, hashedWord));
        final long entryAge = System.currentTimeMillis() - timeStamp;
        if (entryAge < settings.maxAgeMs) {
          result = true;
        }
      }

    } catch (Exception e) {
      LOGGER.warn("error checking global history list: " + e.getMessage());
    }

    // LOGGER.trace(pwmSession, "successfully checked word, result=" + result + ", duration=" + new
    // TimeDuration(System.currentTimeMillis(), startTime).asCompactString());
    return result;
  }
示例#2
0
  public synchronized void addWord(final PwmSession pwmSession, final String word) {
    if (status != STATUS.OPEN) {
      return;
    }

    final String addWord = normalizeWord(word);

    if (addWord == null) {
      return;
    }

    final long startTime = System.currentTimeMillis();

    try {
      final String hashedWord = hashWord(addWord);

      final boolean preExisting = localDB.contains(WORDS_DB, hashedWord);
      localDB.put(WORDS_DB, hashedWord, Long.toString(System.currentTimeMillis()));

      {
        final StringBuilder logOutput = new StringBuilder();
        logOutput.append(preExisting ? "updated" : "added").append(" word");
        logOutput
            .append(" (")
            .append(new TimeDuration(System.currentTimeMillis(), startTime).asCompactString())
            .append(")");
        logOutput.append(" (").append(this.size()).append(" total words)");
        LOGGER.trace(logOutput.toString());
      }
    } catch (Exception e) {
      LOGGER.warn(pwmSession, "error adding word to global history list: " + e.getMessage());
    }
  }