/** * Check if resources from a group were changed. If a change is detected, the changeListener will * be invoked. * * @param cacheEntry the cache key which was requested. The key contains the groupName which has * to be checked for changes. */ public void check(final CacheKey cacheEntry) { Validate.notNull(cacheEntry); LOG.debug("ResourceWatcher started..."); final StopWatch watch = new StopWatch(); watch.start("detect changes"); try { final Group group = new WroModelInspector(modelFactory.create()).getGroupByName(cacheEntry.getGroupName()); if (isGroupChanged(group.collectResourcesOfType(cacheEntry.getType()))) { onGroupChanged(cacheEntry); } changeDetector.reset(); } catch (final Exception e) { onException(e); } finally { watch.stop(); LOG.debug("resource watcher info: {}", watch.prettyPrint()); } }
/** * Check if resources from a group were changed. If a change is detected, the changeListener will * be invoked. * * @param cacheKey the cache key which was requested. The key contains the groupName which has to * be checked for changes. */ public void check(final CacheKey cacheKey, final Callback callback) { notNull(cacheKey); LOG.debug("started"); final StopWatch watch = new StopWatch(); watch.start("detect changes"); try { final Group group = new WroModelInspector(modelFactory.create()).getGroupByName(cacheKey.getGroupName()); if (isGroupChanged(group.collectResourcesOfType(cacheKey.getType()), callback)) { callback.onGroupChanged(cacheKey); cacheStrategy.put(cacheKey, null); } resourceChangeDetector.reset(); } catch (final Exception e) { onException(e); } finally { watch.stop(); LOG.debug("resource watcher info: {}", watch.prettyPrint()); } }
/** * Check if the resource was changed from previous run. The implementation uses resource content * digest (hash) to check for change. * * @param resource the {@link Resource} to check. * @return true if the resource was changed. */ private boolean isChanged(final Resource resource, final String groupName) { boolean changed = false; try { final String uri = resource.getUri(); // using AtomicBoolean because we need to mutate this variable inside an anonymous class. final AtomicBoolean changeDetected = new AtomicBoolean(resourceChangeDetector.checkChangeForGroup(uri, groupName)); if (!changeDetected.get() && resource.getType() == ResourceType.CSS) { final Reader reader = new InputStreamReader(locatorFactory.locate(uri)); LOG.debug("\tCheck @import directive from {}", resource); createCssImportProcessor(changeDetected, groupName) .process(resource, reader, new StringWriter()); } changed = changeDetected.get(); } catch (final IOException e) { LOG.debug( "[FAIL] Cannot check {} resource (Exception message: {}). Assuming it is unchanged...", resource, e.getMessage()); } LOG.debug("resource={}, changed={}", resource.getUri(), changed); return changed; }