Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-4351

FileInboundChannelAdapter with watch service incompatible with LastModifiedFileListFilter?

    XMLWordPrintable

Details

    Description

      The watch service is incompatible with the LastModifiedFileListFilter. For e.g.

      • If the LastModifiedFileListfilter is set to look for files at least 5 seconds old, and the poller is set to poll every 10 seconds.
      • At the 9th second, a file could be created in the watched folder.
      • At 10 seconds the poller queries the watch service to find out what changed in the past 10 seconds.
      • It finds the newly created file.
      • The newly created has a last modified time of -1 second, so it does not process it.
      • At 20 seconds, the poller queries the watch service a second time, this time it does not see the unprocessed file as it was created more than 10 seconds ago.

      Sample code below:

      @Bean
      public IntegrationFlow ftpInputFileWatcher()
      {
          return IntegrationFlows.from(ftpInboundFolder(), filePoller())
                  .handle()
                  /*abbreviated*/
                  .get();
      }
      
      private FileInboundChannelAdapterSpec ftpInboundFolder() {
           LastModifiedFileListFilter lastModifiedFileListFilter = new LastModifiedFileListFilter();
          lastModifiedFileListFilter.setAge(5);
      
          return Files.inboundAdapter(inboundFolder)
                  .preventDuplicates(false)
                  .useWatchService(true)
                  .filter(fileAgeFilterToPreventPrematurePickup());
      }
      
      protected Consumer<SourcePollingChannelAdapterSpec> filePoller(){
          return poller -> poller.poller((Function<PollerFactory, PollerSpec>) p -> p.fixedRate(2000));
      }
      

      Attachments

        Activity

          People

            abilan Artem Bilan
            yihfeng Yih Feng Low
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: