Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16127

Revisit PackageScanResourceResolver

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.8.0
    • Component/s: camel-core, camel-core-api
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      The PackageScanResourceResolver has two methods to resolve resources:

      Set<InputStream> findResources(String location) throws Exception;
      Set<String> findResourceNames(String location) throws Exception;
      

      The default implementation provided by DefaultPackageScanResourceResolver is:

      @Override
      public Set<String> findResourceNames(String location) throws Exception {
          Set<KeyValueHolder<String, InputStream>> answer = new LinkedHashSet<>();
          doFindResources(location, answer);
          return answer.stream().map(KeyValueHolder::getKey).collect(Collectors.toSet());
      }
      @Override
      public Set<InputStream> findResources(String location) throws Exception {
          Set<KeyValueHolder<String, InputStream>> answer = new LinkedHashSet<>();
          doFindResources(location, answer);
          return answer.stream().map(KeyValueHolder::getValue).collect(Collectors.toSet());
      }
      

      There are two issues here:
      1. findResourceNames leaks resources as the InpuStreams found by doFindResources are never closed.
      2. is is not possible to correlate an InputStream with the related resource name which would be useful for CAMEL-15560

      I'd propose to refactor this interface to something like:

      Map<String, ThrowingSupplier<InputStream>> findResources();
      
      default Collection<String> findResourceNames()  throws Exception {
          return findResources().keySet():
      }
      
      default Collection<InputStream> findResourceStreams() throws Exception {
          Collection<ThrowingSupplier<InputStream>> values = findResources().values();
          List<InputStream> answer = new ArrayList(values.size());
          for (ThrowingSupplier<InputStream> supplier : values) {
              streams.add(supplier.get());
          }
      
          return answer;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              lb Luca Burgazzoli
              Reporter:
              lb Luca Burgazzoli

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment