org.geoserver.platform.resource.Resource.lastmodified()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.geoserver.platform.resource.Resource.lastmodified方法的一些代码示例,展示了Resource.lastmodified的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.lastmodified方法的具体详情如下:
包路径:org.geoserver.platform.resource.Resource
类名称:Resource
方法名:lastmodified

Resource.lastmodified介绍

[英]Time this resource was last modified.
[中]上次修改此资源的时间。

代码示例

代码示例来源:origin: geoserver/geoserver

@Override
public long lastmodified() {
  return delegate.lastmodified();
}

代码示例来源:origin: geoserver/geoserver

@Override
public long lastModified() throws IOException {
  return resource.lastmodified();
}

代码示例来源:origin: geoserver/geoserver

/** @return info about the watched file */
public String getFileInfo() {
  SimpleDateFormat sdf = new SimpleDateFormat();
  StringBuffer buff = new StringBuffer(path);
  buff.append(" last modified: ");
  buff.append(sdf.format(resource.lastmodified()));
  return buff.toString();
}

代码示例来源:origin: geoserver/geoserver

/**
   * Another method to avoid reloads if this object is registered
   *
   * @see GeoServerUserGroupService#registerUserGroupLoadedListener(UserGroupLoadedListener)
   */
  @Override
  public void usersAndGroupsChanged(UserGroupLoadedEvent event) {
    // avoid unnecessary reloads
    setLastModified(resource.lastmodified());
    LOGGER.info("Adjusted last modified for file: " + path);
  }
}

代码示例来源:origin: geoserver/geoserver

/** Determines if the underlying file has been modified since the last check. */
public boolean isModified() {
  long now = System.currentTimeMillis();
  if ((now - lastCheck) > 1000) {
    lastCheck = now;
    stale =
        (resource.getType() != Type.UNDEFINED)
            && (resource.lastmodified() != lastModified);
  }
  return stale;
}

代码示例来源:origin: geoserver/geoserver

/**
   * Another method to avoid reloads if this object is registered
   *
   * @see GeoServerRoleService#registerRoleLoadedListener(RoleLoadedListener)
   */
  @Override
  public void rolesChanged(RoleLoadedEvent event) {
    // avoid reloads
    setLastModified(resource.lastmodified());
    LOGGER.info("Adjusted last modified for file: " + path);
  }
}

代码示例来源:origin: geoserver/geoserver

/**
 * return true if a write lock is hold by this file watcher
 *
 * @throws IOException
 */
public boolean hasWriteLock() throws IOException {
  return Resources.exists(lockFile) && lockFile.lastmodified() == lockFileLastModified;
}

代码示例来源:origin: geoserver/geoserver

/**
 * return true if a write lock is hold by another file watcher
 *
 * @throws IOException
 */
public boolean hasForeignWriteLock() throws IOException {
  return Resources.exists(lockFile) && lockFile.lastmodified() != lockFileLastModified;
}

代码示例来源:origin: geoserver/geoserver

/** remove the lockfile */
public void writeUnLock() {
  if (Resources.exists(lockFile)) {
    if (lockFile.lastmodified() == lockFileLastModified) {
      lockFileLastModified = 0;
      lockFile.delete();
    } else {
      LOGGER.warning("Tried to unlock foreign lock: " + lockFile.path());
    }
  } else {
    LOGGER.warning("Tried to unlock not exisiting lock: " + lockFile.path());
  }
}

代码示例来源:origin: geoserver/geoserver

/**
 * Search for resources using pattern and last modified time.
 *
 * @param resource Resource indicated
 * @param lastModified time stamp to search from
 * @return list of modified resources
 */
public static List<Resource> search(Resource resource, long lastModified) {
  if (resource.getType() == Type.DIRECTORY) {
    ArrayList<Resource> results = new ArrayList<Resource>();
    for (Resource child : resource.list()) {
      switch (child.getType()) {
        case RESOURCE:
          if (child.lastmodified() > lastModified) {
            results.add(child);
          }
          break;
        default:
          break;
      }
    }
    return results;
  }
  return Collections.emptyList();
}

代码示例来源:origin: geoserver/geoserver

/**
 * Reads the file updating the last check timestamp.
 *
 * <p>Subclasses can override {@link #parseFileContents(InputStream)} to do something when the
 * file is read.
 *
 * @return parsed file contents
 */
public T read() throws IOException {
  T result = null;
  if (resource.getType() == Type.RESOURCE) {
    InputStream is = null;
    try {
      is = resource.in();
      result = parseFileContents(is);
      lastModified = resource.lastmodified();
      lastCheck = System.currentTimeMillis();
      stale = false;
    } finally {
      if (is != null) {
        is.close();
      }
    }
  }
  return result;
}

代码示例来源:origin: geoserver/geoserver

/** Test constellation and call {@link #doOnChange()} if necessary */
protected void checkAndConfigure() {
  boolean fileExists;
  try {
    fileExists = resource.getType() == Type.RESOURCE;
  } catch (SecurityException e) {
    LOGGER.warning("Was not allowed to read check file existance, file:[" + path + "].");
    setTerminate(true); // there is no point in continuing
    return;
  }
  if (fileExists) {
    long l = resource.lastmodified(); // this can also throw a SecurityException
    if (testAndSetLastModified(l)) { // however, if we reached this point this
      doOnChange(); // is very unlikely.
      warnedAlready = false;
    }
  } else {
    if (!warnedAlready) {
      LOGGER.warning("[" + path + "] does not exist.");
      warnedAlready = true;
    }
  }
}

代码示例来源:origin: geoserver/geoserver

/**
 * Try to get a lock
 *
 * @throws IOException
 */
public void writeLock() throws IOException {
  if (hasWriteLock()) return; // already locked
  if (Resources.exists(lockFile)) {
    LOGGER.warning("Cannot obtain  lock: " + lockFile.path());
    Properties props = new Properties();
    try (InputStream in = lockFile.in()) {
      props.load(in);
    }
    throw new IOException(Util.convertPropsToString(props, "Already locked"));
  } else { // success
    writeLockFileContent(lockFile);
    lockFileLastModified = lockFile.lastmodified();
    LOGGER.info("Successful lock: " + lockFile.path());
  }
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryExtantHaveDate(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, defined());
  long result = res.lastmodified();
  assertThat(result, notNullValue());
}

代码示例来源:origin: geoserver/geoserver

new RoleFileWatcher(resource, service, resource.lastmodified());
service.registerRoleLoadedListener(watcher);
watcher.start();

代码示例来源:origin: org.geoserver.extension/gs-wps-core

public void run() {
    long newLastModified = configFile.lastmodified();
    if (lastModified == null || newLastModified != lastModified) {
      lastModified = newLastModified;
      loadConfiguration();
    }
  }
}

代码示例来源:origin: org.geoserver/gs-gwc

@Override
  public int compare(Resource o1, Resource o2) {
    return (int) (o1.lastmodified() - o2.lastmodified());
  }
});

代码示例来源:origin: org.geoserver/gs-wms

/** Returns true if the backing file does not exist any more, or has been modified */
  public boolean isStale() {
    return !Resources.exists(file) || (file.lastmodified() != lastModified);
  }
}

代码示例来源:origin: org.geoserver.community/gs-jdbcstore

@Theory
  public void theoryModifiedUpdated(String path) throws Exception {
    Resource res = getResource(path);

    assumeThat(res, not(directory()));

    long lastmod = res.lastmodified();

    OutputStream out = res.out();
    out.write(1234);
    out.close();

    assertTrue(res.lastmodified() > lastmod);
  }
}

代码示例来源:origin: org.geoserver/gs-platform

@Theory
public void theoryExtantHaveDate(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, defined());
  long result = res.lastmodified();
  assertThat(result, notNullValue());
}

相关文章