Пример #1
0
  public CacheFileNames getCacheFileNames(final UserAccount user) {

    SecureHashKeyResult toRet =
        executeWithConnection(
            new ConnectionExecuteFunction<SecureHashKeyResult>() {
              public SecureHashKeyResult execute(Connection c) throws SQLException {
                return getSecureHashKey(user, c);
              }
            });

    if (toRet == null) {
      // A DB error should have been logged.
      return null;
    }

    // EMSDEV-7854.  Signal file manipulation is done outside of a DB transaction.
    String stateFile = null;
    String newmailFile = null;
    ClientHashSupport hash = null;
    byte[] key = toRet.getKey();
    if (key != null) {
      hash = new ClientHashSupport();
      hash.setCustomerId(user.getCustomerID());
      hash.setHashKey(key);
      hash.setUserId(user.getUserID());
      hash.getStateCachePath();
      hash.setLastActivationId(user.getLastActivationId());

      // Lines below don't hit the spindle.
      File stateFileF = new File(getCacheBase(), hash.getStateCachePath());
      stateFile = stateFileF.getAbsolutePath();

      File newmailFileF = new File(getCacheBase(), hash.getNewMailCachePath());
      newmailFile = newmailFileF.getAbsolutePath();

      if (toRet.isJustCreated()) {
        // If Webmail doesn't find the signal file, it polls the database,
        // so ensure the files are there.
        updateSignalFiles(hash, user.getUserState(), user.isDeleted());
      }
    }
    return new CacheFileNames(stateFile, newmailFile);
  }
Пример #2
0
  /**
   * Writes cache files, first new mail, than state to avoid client prematurely looking for
   * activation info. Hits nfs.
   */
  private void updateSignalFiles(ClientHashSupport hash, CustomerState state, boolean isDeleted) {

    File base = getCacheBase();
    int userId = hash.getUserId();
    File stateFile = new File(base, hash.getStateCachePath());
    if (isDeleted || state == CustomerState.READY) {
      deleteFileIfNeeded(stateFile, userId);
    } // ready state.
    else {
      byte[] stateData = STATE_DATA_CACHE.get(state);
      touchFile(stateFile, stateData, userId, true);
    }
    File newMailFile = new File(base, hash.getNewMailCachePath());
    if (!isDeleted && state.type() == CustomerState.Type.Active) {
      touchFile(newMailFile, ZERO, userId, true);
    } else {
      deleteFileIfNeeded(newMailFile, userId);
    }
    if (isDeleted || state.type() != CustomerState.Type.Active) {
      File f = getSessionFile(hash.getLastActivationToken());
      deleteFileIfNeeded(f, userId);
    }
  }