我正在尝试使用spring集成来轮询我的一些目录。由于Spring集成在KeyValue表中写入并且它接受了这一点。以及.. unix inode并尝试重复写入我的db表,它会在尝试几秒后抛出异常。我想学习一种忽略弹簧拾取的方法。我已经在使用AcceptOnceFileListFilter了。此外,我尝试使用自定义过滤器过滤掉文件名长度小于3的任何文件,但它们不起作用。
更新
我正在使用IgnoreHiddenFileListFilter
但它无效。我已经缩小了问题,因为我的自定义过滤器实现FileListFilter < File >
所有进入此过滤器的文件都是java.io.File对象,并且它不能将.
和..
识别为文件。我确认了这一点,因为我的sftp远程过滤器实现了FileListFilter< LsEntry >
,它正确地过滤掉了我在日志中可以看到的.
和..
。但是我不能在本地使用LsEntry
,因为它会抛出一个类型转换异常。
以下是我对过滤器的配置:
<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="^.*(?<!.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="^.*(?<!.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>
这是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
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;
}
}
这是我的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
但这是我的KeyValue表 View of my table