code: public void close(ScopeWrapper<S> scope)
        throws IOException {
      List<Throwable> exceptionsList = Lists.newArrayList();
      List<Service> awaitShutdown = Lists.newArrayList();
  
      for (Map.Entry<RawJobBrokerKey, Object> entry : Maps.filterKeys(this.sharedResourceCache.asMap(),
          new ScopeIsAncestorFilter(scope)).entrySet()) {
  
        this.sharedResourceCache.invalidate(entry.getKey());
  
        if (entry.getValue() instanceof ResourceInstance) {
          Object obj = ((ResourceInstance) entry.getValue()).getResource();
          // Catch unchecked exception while closing resources, make sure all resources managed by cache are closed.
          try {
            SharedResourcesBrokerUtils.shutdownObject(obj, log);
          } catch (Throwable t) {
            exceptionsList.add(t);
          }
          if (obj instanceof Service) {
            awaitShutdown.add((Service) obj);
          }
        }
      }
  
      for (Service service : awaitShutdown) {
        try {
          service.awaitTerminated(10, TimeUnit.SECONDS);
        } catch (TimeoutException te) {
          log.error("Failed to shutdown {}.", service);
        }
      }
  
      // log exceptions while closing resources up.
      if (exceptionsList.size() > 0) {
        log.error(exceptionsList.stream()
            .map(Throwables::getStackTraceAsString).collect(Collectors.joining("\n")));
      }
    }
docs: Invalidate all objects at scopes which are descendant of the input scope. Any such invalidated object that is a
  {@link Closeable} will be closed, and any such object which is a {@link Service} will be shutdown.
  @throws IOException