Example usage for org.springframework.core.io Resource hashCode

List of usage examples for org.springframework.core.io Resource hashCode

Introduction

In this page you can find the example usage for org.springframework.core.io Resource hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:org.jahia.services.seo.urlrewrite.UrlRewriteService.java

/**
 * @return <code>null</code> if resources were unchanged, the list of updated resources otherwise
 * @throws IOException//w w w. ja  va 2s.  c  om
 */
private List<Resource> getMergedResourcesIfReloadNeeded() throws IOException {
    if (confReloadCheckIntervalSeconds > -1 && hasConfigurationResources()) {

        boolean doReload = false;
        List<Resource> result = null;
        if (modified || confReloadCheckIntervalSeconds == 0 || lastChecked == 0
                || lastChecked + confReloadCheckIntervalSeconds * 1000L < System.currentTimeMillis()) {
            logger.debug("Checking for modifications in URL rewriter configuration resources.");
            List<Resource> mergedConfigurationResources = getMergedConfigurationResources();

            // look at last modified time for resources
            for (Resource resource : mergedConfigurationResources) {
                long resourceLastModified = FileUtils.getLastModified(resource);
                int hash = resource.hashCode();
                Long previous = lastModified.get(hash);

                // if we detected that a resource was modified since last time we checked, we don't need to look further
                doReload = previous == null || resourceLastModified > previous;
                if (doReload) {
                    lastModified.put(hash, resourceLastModified);
                    result = mergedConfigurationResources;
                    break;
                }
            }
            logger.debug(doReload ? "Changes detected" : "No changes detected");
        }

        lastChecked = System.currentTimeMillis();
        modified = false; // we've checked if there were changes, so reset modified flag

        return result;
    }
    return null;
}