Beispiel #1
0
 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();
 }
Beispiel #2
0
 /**
  * @VisibleForTesting
  *
  * @param callable {@link Callable} to submit for asynchronous execution.
  */
 void submit(final Callable<Void> callable) {
   executorServiceRef.get().submit(callable);
 }