2

With Spring Integration 4.2.0, it mentioned that 'filter' and 'locker' must be present if custom Scanner is being used (https://jira.spring.io/browse/INT-3619).

I don't know how to set this with XML config if I simply override the listEligibleFiles() method and use the default filters provided by DefaultDirectoryScanner.

e.g.

// using the default filters
public class MyDirectoryScanner extends DefaultDirectoryScanner {
    @Override
    protected File[] listEligibleFiles(File directory) throws IllegalArgumentException {
        return super.listEligibleFiles(directory);
    }
}

<bean id="myCustomScanner"
      class="com.company.MyDirectoryScanner" />

<int-file:inbound-channel-adapter directory="my_directory"
                                  prevent-duplicates="true"
                                  scanner="myCustomScanner"
                                  channel="myChannel">
    <int:poller fixed-rate="10"
                time-unit="SECONDS" max-messages-per-poll="5" />
</int-file:inbound-channel-adapter>
user3544765
  • 456
  • 5
  • 13

2 Answers2

0

It's not clear what you mean; that JIRA was to fix a bug where those properties were incorrectly overridden.

When injecting a custom scanner, you need to set those properties on your scanner rather than via the namespace.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • If I simply extends the class DefaultDirectoryScanner and only override listEligibleFiles() for my own purpose. It should use the default IgnoreHiddenFileListFilter and AcceptOnceFileListFilter through DefaultDirectoryScanner() default constuctor. i.e I don't need to explicitly set the filter properties. However, I still get exception java.lang.IllegalStateException: The 'filter' and 'locker' options must be present on the provided external 'scanner'. That's why I am asking whether I need to do sthg else via namespace – user3544765 Sep 16 '15 at 02:07
  • With 4.2, if you inject a custom scanner, you must set the filter and locker on that object yourself; you are no longer allowed to use the namespace attributes. Previously, the namespace incorrectly overwrote any such properties. The framework doesn't know whether or not it's 'ok' to overwrite, so we err on the side of caution. – Gary Russell Sep 16 '15 at 13:35
  • This is not a bug, it's a planned behavior change, to fix a problem where user settings were incorrectly overwritten. See [the migration guide](https://github.com/spring-projects/spring-integration/wiki/Spring-Integration-4.1-to-4.2-Migration-Guide). – Gary Russell Sep 25 '15 at 12:03
  • Sorry that I still have question for migration to SI 4.2.0. Now, I have removed the prevent-duplicate attribute in file-inbound-adapter and the filters are controlled by the scanner itself. However, AcceptOnceFileListFilter is still created implicitly by the file-inbound-adapter internally. That means even the scanner doesn't have the AcceptOnceFileListFilter but file-inbound-adapter still filter out duplicated message. How could I disable the AcceptOnceFileListFilter in file-inbound-adapter if "prevent-duplicate" attribute could not be used? – user3544765 Oct 19 '15 at 07:16
  • Now THAT __is__ a bug. I have opened a [JIRA issue](https://jira.spring.io/browse/INT-3858). – Gary Russell Oct 19 '15 at 13:44
  • Thanks Gary for this. – user3544765 Oct 19 '15 at 13:58
  • See my answer for more info: http://stackoverflow.com/questions/32583113/how-to-skip-the-setting-of-filter-and-locker-attribute-if-custom-directorysc/33224194#33224194 – Artem Bilan Oct 19 '15 at 21:26
0

use the default filters provided by DefaultDirectoryScanner.

The DefaultDirectoryScanner has the code:

public DefaultDirectoryScanner() {
    final List<FileListFilter<File>> defaultFilters = new ArrayList<FileListFilter<File>>(2);
    defaultFilters.add(new IgnoreHiddenFileListFilter());
    defaultFilters.add(new AcceptOnceFileListFilter<File>());
    this.filter = new CompositeFileListFilter<File>(defaultFilters);
}

So, if you would like do not use AcceptOnceFileListFilter (or any other default) you should follow with the recommendation from the Docs and use setFilter() of the DirectoryScanner contract. For this purpose there is FileListFilterFactoryBean with the setPreventDuplicates() to be set to false.

And yes, remove, please, prevent-duplicates="true" from your configuration, because it is prohibited, when scanner is in use:

Assert.state(!(this.scannerExplicitlySet && (this.filter != null || this.locker != null)),
            "The 'filter' and 'locker' options must be present on the provided external 'scanner': "
                    + this.scanner);

The filter can be set to null on the DefaultDirectoryScanner by the way...

I'm converting the JIRA to Documentation just to be more clear on the matter.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118