简体   繁体   English

为什么在将 ftp java dsl 配置引入 spring 集成核心时过滤器行为发生了变化

[英]Why was the filter behaviour changed when the ftp java dsl config was brought into spring integration core

At Spring Integration 4 I had code like this using the spring integration java dsl project:在 Spring Integration 4 中,我使用 spring 集成 java dsl 项目编写了这样的代码:

      FtpInboundChannelAdapterSpec ftpAdapterSpec = Ftp.inboundAdapter(ftpSessionFactory)
                .preserveTimestamp(true)
                .remoteDirectory(remoteFolder)
                .filter(new FtpPersistentAcceptOnceFileListFilter(metaDataStore, "ftp-inbound-" + id + ":"))
                .regexFilter(".*")                
                .localDirectory(Paths.get(System.getProperty("java.io.tmpdir"), "ftp-inbound", localPath).toFile()).autoCreateLocalDirectory(true)
                .deleteRemoteFiles(false);

Notice how it includes a regex filter and a FtpPersistentAcceptOnceFilterListFilter.请注意它如何包含一个正则表达式过滤器和一个 FtpPersistentAcceptOnceFilterListFilter。 This worked great.这很好用。

The code for filter (the original java dsl project) which regexFilter wraps is: regexFilter 包装的过滤器(原始 java dsl 项目)的代码是:

public S filter(FileListFilter<F> filter) {
    if (this.filter == null) {
        if (filter instanceof CompositeFileListFilter) {
            this.filter = (CompositeFileListFilter<F>) filter;
        }
        else {
            this.filter = new CompositeFileListFilter<F>();
            this.filter.addFilter(filter);
        }
        this.synchronizer.setFilter(this.filter);
    }
    else {
        this.filter.addFilter(filter);
    }
    return _this();
}

So as you can see it builds up a composite filter from the passed in filter (and stacks as you pass in more).因此,如您所见,它从传入的过滤器中构建了一个复合过滤器(并且随着您传入的更多而堆叠)。

But then when java dsl was brought in to core integration the filter method changed to :但是当 java dsl 被引入核心集成时,过滤器方法更改为

public S filter(FileListFilter<F> filter) {
    this.synchronizer.setFilter(filter);
    return _this();
}

That's fine by itself but then methods like regexFilter became :这本身很好,但是像 regexFilter 这样的方法变成了

    @Override
    public FtpInboundChannelAdapterSpec regexFilter(String regex) {
        return filter(composeFilters(new FtpRegexPatternFileListFilter(regex)));
    }

    @SuppressWarnings("unchecked")
    private CompositeFileListFilter<FTPFile> composeFilters(FileListFilter<FTPFile> fileListFilter) {
        CompositeFileListFilter<FTPFile> compositeFileListFilter = new CompositeFileListFilter<>();
        compositeFileListFilter.addFilters(fileListFilter,
                new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpMessageSource"));
        return compositeFileListFilter;
    }

So now the code that I had no does do what I desired as the FtpPersistentAcceptOnceFileListFilter which takes my persistent metadatastore is now replaced by a FtpPersistentAcceptOnceFileListFilter which takes a SimpleMetaDataStore.所以现在我没有的代码可以做我想要的,因为采用我的持久元数据存储的 FtpPersistentAcceptOnceFileListFilter 现在被采用 SimpleMetaDataStore 的 FtpPersistentAcceptOnceFileListFilter 取代。

So now although the code compiles fine when it runs it receives duplicates.所以现在虽然代码在运行时编译得很好,但它会收到重复项。

So the question is why was it changed and is there a good reason why it was changed?所以问题是为什么要改变它,是否有充分的理由改变它? Because as it stands because of the non obvious side effect of the regexFilter method it becomes fairly unusable.因为 regexFilter 方法的副作用并不明显,所以它变得相当不可用。

It has been changed the way that filter(FileListFilter<F> filter) has a precedence over all other filtering options the way like it is with the XML configuration for consistency.已更改filter(FileListFilter<F> filter)优先于所有其他过滤选项的方式,就像使用 XML 配置以保持一致性一样。 The reason of such a behavior just because we don't know the order you would like to compose those filters.这种行为的原因只是因为我们不知道您要组合这些过滤器的顺序。 So, to ensure the proper order you need to build a CompositeFileListFilter , including a required FtpRegexPatternFileListFilter , by yourself and and inject it into this fitler() option.因此,为了确保正确的顺序,您需要自己构建CompositeFileListFilter ,包括所需的FtpRegexPatternFileListFilter并将其注入到此fitler()选项中。

The regexFilter() and patternFilter() are still here for convenience to configure simple common use-cases, when you have only this filter and nothing more.regexFilter()patternFilter()还在这里为了方便配置简单常见的用的情况下,当你只有这个过滤器,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM