示例#1
0
 private synchronized Collection<ResourceModelSource> getResourceModelSources() {
   // determine if sources need to be reloaded
   final long lastMod =
       projectConfig.getConfigLastModifiedTime() != null
           ? projectConfig.getConfigLastModifiedTime().getTime()
           : 0;
   if (lastMod > nodesSourcesLastReload) {
     nodesSourceList = new ArrayList<>();
     loadResourceModelSources();
   }
   return nodesSourceList;
 }
示例#2
0
  private void loadResourceModelSources() {
    Map<String, Exception> exceptions =
        Collections.synchronizedMap(new HashMap<String, Exception>());
    Set<String> validSources = new HashSet<>();
    // generate Configuration for file source
    if (projectConfig.hasProperty(PROJECT_RESOURCES_FILE_PROPERTY)) {
      try {
        final Properties config = createFileSourceConfiguration();
        logger.info("Source (project.resources.file): loading with properties: " + config);
        nodesSourceList.add(
            loadResourceModelSource("file", config, shouldCacheForType("file"), "file.file"));
        validSources.add("project.file");
      } catch (ExecutionServiceException e) {
        logger.error("Failed to load file resource model source: " + e.getMessage(), e);
        exceptions.put("project.file", e);
      }
    }
    if (projectConfig.hasProperty(PROJECT_RESOURCES_URL_PROPERTY)) {
      try {
        final Properties config = createURLSourceConfiguration();
        logger.info("Source (project.resources.url): loading with properties: " + config);
        nodesSourceList.add(
            loadResourceModelSource("url", config, shouldCacheForType("url"), "file.url"));
        validSources.add("project.url");
      } catch (ExecutionServiceException e) {
        logger.error("Failed to load file resource model source: " + e.getMessage(), e);
        exceptions.put("project.url", e);
      }
    }

    final List<Map<String, Object>> list = listResourceModelConfigurations();
    int i = 1;
    for (final Map<String, Object> map : list) {
      final String providerType = (String) map.get("type");
      final Properties props = (Properties) map.get("props");

      logger.info("Source #" + i + " (" + providerType + "): loading with properties: " + props);
      try {
        nodesSourceList.add(
            loadResourceModelSource(
                providerType, props, shouldCacheForType(providerType), i + ".source"));
        validSources.add(i + ".source");
      } catch (ExecutionServiceException e) {
        logger.error(
            "Failed loading resource model source #" + i + ", skipping: " + e.getMessage(), e);
        exceptions.put(i + ".source", e);
      }
      i++;
    }
    synchronized (nodesSourceExceptions) {
      nodesSourceExceptions.putAll(exceptions);
      for (String validSource : validSources) {
        nodesSourceExceptions.remove(validSource);
      }
    }

    Date configLastModifiedTime = projectConfig.getConfigLastModifiedTime();
    nodesSourcesLastReload = configLastModifiedTime != null ? configLastModifiedTime.getTime() : -1;
  }