/** * Will try an asynchronous check if the async configuration is enabled. If async check is not * configured, a synchronous check will be performed. The async check assumes that the {@link * ResourceWatcherRequestHandler} is enabled. * * <p>If the async check is not allowed (the request was not passed through {@link WroFilter}) - * no check will be performed. This is important for use-cases when wro resource is included using * a taglib which performs a wro api call directly, without being invoked through {@link * WroFilter}. * * @return true if the actual check invocation was performed. This is important to decide if the * resource change should be skipped or not. */ public boolean tryAsyncCheck(final CacheKey cacheKey) { boolean checkInvoked = false; if (context.getConfig().isResourceWatcherAsync()) { if (isAsyncCheckAllowed()) { LOG.debug("Checking resourceWatcher asynchronously..."); final Callable<Void> callable = createAsyncCheckCallable(cacheKey); submit(callable); checkInvoked = true; } } else { LOG.debug("Async check not allowed. Falling back to sync check."); check(cacheKey); checkInvoked = true; } return checkInvoked; }
private boolean isGroupChanged(final Group group, final Callback callback) { final List<Resource> resources = group.getResources(); final AtomicBoolean isChanged = new AtomicBoolean(false); final List<Future<?>> futures = new ArrayList<Future<?>>(); final boolean isAsync = context.getConfig().isResourceWatcherAsync(); try { for (final Resource resource : resources) { if (isAsync) { futures.add( executorServiceRef .get() .submit( ContextPropagatingCallable.decorate( new Callable<Void>() { public Void call() throws Exception { checkResourceChange(resource, group, callback, isChanged); return null; } }))); } else { checkResourceChange(resource, group, callback, isChanged); } } if (isAsync) { LOG.debug("await async execution"); // await for all futures to complete before returning the result for (final Future<?> future : futures) { future.get(); } } } catch (final Exception e) { LOG.debug("Exception while onResourceChange is invoked", e); } LOG.debug("group={}, changed={}", group.getName(), isChanged); return isChanged.get(); }