コード例 #1
0
  /**
   * Clear everything including cache, session, files.
   *
   * @throws TimeoutException
   * @throws ExecutionException
   * @throws InterruptedException
   */
  public void clear() {
    // clear stuff on the server
    staticStateManagerService.clearClient(staticStateIdentifierManager.getIdentifier());

    // remove cookie and session
    staticStateIdentifierManager.clearIdentifier();
  }
コード例 #2
0
  /**
   * Creates or restores a new file.
   *
   * @param uuid
   * @return
   * @throws IOException
   */
  private T createOrRestore(UUID uuid) throws IOException {

    // restore cache from file:
    File uuidFileParent = staticStateDirectoryManager.getUUIDFileParent();

    // if that file is scheduled for deletion, we do not restore it
    if (fileDeleter.deletionQueueContains(uuidFileParent)) {
      log.debug("trying to restore from state a file that is scheduled for deletion");
      // invalidate identifier
      staticStateIdentifierManager.clearIdentifier();
      // get a new one
      // and recreate file
      uuidFileParent = staticStateDirectoryManager.getUUIDFileParent();
    }

    File uuidFile = new File(uuidFileParent, FILENAME);
    T entity = null;

    if (uuidFile.exists()) {
      log.debug("No value in the cache for uuid " + uuid + ". Filling cache from file.");
      try {
        entity = read(uuidFile);
      } catch (Exception e) {
        log.error(
            "Cache cannot be restored from "
                + uuidFile.getAbsolutePath()
                + "."
                + "The file might be empty or the model has changed since last time: "
                + e.getMessage(),
            e);
      }
    } else {
      log.debug(
          "No value in the cache for uuid "
              + uuid
              + " and no value in the file. Creating a new one.");

      // create the file
      try {
        uuidFile.createNewFile();
      } catch (IOException e) {
        log.error("cannot create model file: " + e.getMessage(), e);
        throw e;
      }

      // and persist an entity
      try {
        entity = getEntityType().newInstance();
      } catch (InstantiationException e) {
        throw new RuntimeException(e);
      } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
      }
      staticStateManagerService.writeEntity(uuidFile, entity);
    }

    // then return entity
    return entity;
  }
コード例 #3
0
 public void clearFile(final UUID fileId) {
   staticStateManagerService.clearFile(staticStateIdentifierManager.getIdentifier(), fileId);
 }
コード例 #4
0
 /**
  * Persist modifications to file and cache.
  *
  * @param entity
  * @return
  * @throws ExecutionException
  */
 public void updateEntity(T entity) {
   UUID uuid = staticStateIdentifierManager.getIdentifier();
   staticStateManagerService.updateEntity(uuid, entity);
 }
コード例 #5
0
 /**
  * Retrieves the entity from cache or null if this entity is not present.
  *
  * @return
  */
 public StaticStatePersistedOnFileSystemEntity getEntityIfPresent() {
   return staticStateManagerService.getEntityIfPresent(
       staticStateIdentifierManager.getIdentifier());
 }