简体   繁体   English

使用Spring Integration轮询目录时如何过滤出点和点点(默认的unix索引节点)

[英]How to filter out dot and dot dot(default unix inodes) while polling a directory using spring integration

I am trying to use spring integration to poll some of my directories. 我正在尝试使用spring集成来轮询一些目录。 Since spring integration writes in KeyValue table and it picks up this . 由于spring集成会在KeyValue表中写入数据,因此它将对此进行处理。 as well as .. unix inode and tries to write repeatedly to my db table it throws exception after a few seconds of trying. 以及.. unix inode并尝试重复写入我的db表,尝试几秒钟后抛出异常。 I would like to learn a way to ignore them for spring to pickup. 我想学习一种忽略它们的方法。 I am already using AcceptOnceFileListFilter. 我已经在使用AcceptOnceFileListFilter。 Also I have tried with a custom filter that filters out any file with filename length less than 3 but they are not working. 我也尝试过使用自定义过滤器,该过滤器可以过滤出文件名长度小于3的任何文件,但它们无法正常工作。

Update: 更新:

I am using IgnoreHi‌​ddenFileListFilter yet its not working. 我正在使用IgnoreHi‌​ddenFileListFilter但无法正常工作。 I have narrowed the issue that Since my custom filter implements FileListFilter < File > all the files coming to this filter are java.io.File objects and it does not recognize . 由于我的自定义过滤器实现了FileListFilter < File > ,因此解决了该过滤器的所有文件都是java.io.File对象,并且无法识别的问题. and .. as Files. ..作为文件。 I confirmed this since my sftp remote filter implements FileListFilter< LsEntry > and it is correctly filtering out . 我确认了这一点,因为我的sftp远程过滤器实现了FileListFilter< LsEntry > ,并且可以正确过滤掉. and .. which i can see in logs. ..我可以在日志中看到。 However i cannot use LsEntry in local as it throws a type cast exception. 但是我不能在本地使用LsEntry ,因为它会引发类型转换异常。

Here is my configuration for filters: 这是我的过滤器配置:

<bean id="remoteCompositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
  <list>
    <bean class="com.file.RemoteCustomFilter"/>
  <bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />
    <!-- download files whose extension is not .writing -->
    <bean class="org.springframework.integration.sftp.filters.SftpRegexPatternFileListFilter" >
      <constructor-arg value="^.*(?&lt;!.writing)$" /> 
    </bean>
    <!-- List of qualifying files to be retrieved from remote server are stored in KEY_VALUE_STORE table.
         jdbcMetadataStore is defined in test-sftp-common.xml -->
    <bean id="remotePersistentFilter" 
        class="org.springframework.integration.sftp.filters.SftpPersistentAcceptOnceFileListFilter">
        <constructor-arg name="store" ref="jdbcMetadataStore"/>
        <constructor-arg name="prefix" value="" />
        <property name="flushOnUpdate" value="true" />
    </bean>
  </list>
</constructor-arg>

<bean id="localCompositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
  <list>
    <bean class="com.file.CustomFilter"/>
    <bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />
    <bean class="org.springframework.integration.file.filters.IgnoreHiddenFileListFilter" />

    <!-- download files whose extension is not .writing -->
    <bean class="org.springframework.integration.file.filters.RegexPatternFileListFilter" >
        <constructor-arg value="^.*(?&lt;!.writing)$" /> 
    </bean>
    <bean id="localIncomingPersistentFilter"
        class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
        <constructor-arg name="store" ref="propertiesMetadataStore"/>
        <constructor-arg name="prefix" value="" />
        <property name="flushOnUpdate" value="true" />
    </bean>
  </list>
</constructor-arg>

And here is the CustomFilter 这是CustomFilter

public class CustomFilter implements FileListFilter<File> {
private static Logger log = Logger.getLogger(CustomFilter.class); 
@Override
public List<File> filterFiles(File[] files) {
    List<File> filteredFileList = new LinkedList<File>();
    for (File this_file : files){
        log.info("Checking file : " + this_file.getAbsolutePath());
        if(!this_file.getName().startsWith(".")){
            filteredFileList.add(this_file);
            log.info("Adding local file to filtered list : " + this_file.getAbsolutePath());
        }
        else{
            log.info("Rejecting local file from filtered list : " + this_file.getAbsolutePath());
        }
    }
    return filteredFileList;
}

} }

RemoteCustomFilter RemoteCustomFilter

public class RemoteCustomFilter implements FileListFilter<LsEntry> {
private static Logger log = Logger.getLogger(CustomFilter.class); 
@Override
public List<LsEntry> filterFiles(LsEntry[] files) {
    List<LsEntry> filteredFileList = new LinkedList<LsEntry>();
    for (LsEntry this_file : files){
        log.info("Checking file : " + this_file.getFilename());
        if(!this_file.getFilename().startsWith(".")){
            filteredFileList.add(this_file);
            log.info("Adding remote file to filtered list : " + this_file.getFilename());
        }
        else{
            log.info("Rejecting remote file from filtered list : " + this_file.getFilename());
        }
    }
    return filteredFileList;
}

} }

This is what my DEBUG log looks like: 这是我的DEBUG日志的样子:

2017-02-02|13:26:17.878 DEBUG [task-scheduler-3] org.springframework.integration.util.SimplePool [doGetItem:190] - Obtained new org.springframework.integration.sftp.session.SftpSession@3221346d.
2017-02-02|13:26:18.423 INFO  [task-scheduler-1] com.file.CustomFilter [filterFiles:16] - Checking file : /outgoing/.DS_Store
2017-02-02|13:26:18.423 INFO  [task-scheduler-1] com.file.CustomFilter [filterFiles:22] - Rejecting local file from filtered list : /outgoing/.DS_Store
2017-02-02|13:26:18.424 DEBUG [task-scheduler-1] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:261] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.021 DEBUG [task-scheduler-4] org.springframework.integration.util.SimplePool [doGetItem:190] - Obtained new org.springframework.integration.sftp.session.SftpSession@3b560425.
2017-02-02|13:26:19.095 DEBUG [task-scheduler-3] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-2] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-1] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-7] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-9] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-10] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-6] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-2] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-7] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-3] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-9] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.095 DEBUG [task-scheduler-10] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:208] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:19.372 INFO  [task-scheduler-3] com.file.CustomFilter [filterFiles:17] - Checking file : .
2017-02-02|13:26:19.372 INFO  [task-scheduler-3] com.file.CustomFilter [filterFiles:23] - Rejecting remote file from filtered list : .
2017-02-02|13:26:19.372 INFO  [task-scheduler-3] com.file.CustomFilter [filterFiles:17] - Checking file : ..
2017-02-02|13:26:19.372 INFO  [task-scheduler-3] com.file.CustomFilter [filterFiles:23] - Rejecting remote file from filtered list : ..
2017-02-02|13:26:19.854 DEBUG [task-scheduler-3] org.springframework.integration.file.remote.session.CachingSessionFactory [close:187] - Releasing Session org.springframework.integration.sftp.session.SftpSession@3221346d back to the pool.
2017-02-02|13:26:19.854 DEBUG [task-scheduler-3] org.springframework.integration.util.SimplePool [releaseItem:221] - Releasing org.springframework.integration.sftp.session.SftpSession@3221346d back to the pool
2017-02-02|13:26:19.854 DEBUG [task-scheduler-3] org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer [synchronizeToLocalDirectory:270] - 0 files transferred
2017-02-02|13:26:19.854 INFO  [task-scheduler-3] com.file.CustomFilter [filterFiles:16] - Checking file : incoming/.DS_Store
2017-02-02|13:26:19.855 INFO  [task-scheduler-3] com.file.CustomFilter [filterFiles:22] - Rejecting local file from filtered list : incoming/.DS_Store
2017-02-02|13:26:19.855 DEBUG [task-scheduler-3] org.springframework.integration.endpoint.SourcePollingChannelAdapter [doPoll:261] - Received no Message during the poll, returning 'false'
2017-02-02|13:26:21.080 INFO  [task-scheduler-1] com.file.CustomFilter [filterFiles:16] - Checking file : incoming/.DS_Store
2017-02-02|13:26:21.080 INFO  [task-scheduler-1] com.file.CustomFilter [filterFiles:22] - Rejecting local file from filtered list : incoming/.DS_Store
2017-02-02|13:26:21.081 DEBUG [task-scheduler-1] org.springframework.integration.util.SimplePool [doGetItem:185] - Obtained org.springframework.integration.sftp.session.SftpSession@3221346d from pool.
2017-02-02|13:26:21.101 INFO  [task-scheduler-4] com.file.CustomFilter [filterFiles:17] - Checking file : .
2017-02-02|13:26:21.102 INFO  [task-scheduler-4] com.file.CustomFilter [filterFiles:23] - Rejecting remote file from filtered list : .
2017-02-02|13:26:21.102 INFO  [task-scheduler-4] com.file.CustomFilter [filterFiles:17] - Checking file : ..
2017-02-02|13:26:21.102 INFO  [task-scheduler-4] com.file.CustomFilter [filterFiles:23] - Rejecting remote file from filtered list : ..
2017-02-02|13:26:21.707 DEBUG [task-scheduler-4] org.springframework.integration.file.remote.session.CachingSessionFactory [close:187] - Releasing Session org.springframework.integration.sftp.session.SftpSession@3b560425 back to the pool.
2017-02-02|13:26:21.707 DEBUG [task-scheduler-4] org.springframework.integration.util.SimplePool [releaseItem:221] - Releasing org.springframework.integration.sftp.session.SftpSession@3b560425 back to the pool
2017-02-02|13:26:21.707 DEBUG [task-scheduler-4] org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer [synchronizeToLocalDirectory:270] - 0 files transferred

But here is my KeyValue Table View of my table 但是这是我的表的KeyValue表视图

Use the IgnoreHiddenFileListFilter 使用IgnoreHiddenFileListFilter

or a regex filter with [^.].* . 或带有[^.].*的正则表达式过滤器。

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

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