[英]LastModifiedFileListFilter for Sftp inbound adapter
I am trying to implement LastModifiedFileListFilter
as it looks like there is no similar filter for spring-integration-sftp yet for 5.3.2 release, I tried to copy the LastModifiedFileListFilter
from spring-integration-file but the discard callback isn't working.我正在尝试实现
LastModifiedFileListFilter
,因为 5.3.2 版本似乎还没有类似的 spring-integration-sftp 过滤器,我尝试从 spring-integration-file 复制LastModifiedFileListFilter
但丢弃回调不起作用。 Here is my implementation:这是我的实现:
@Slf4j
@Data
public class LastModifiedLsEntryFileListFilter implements DiscardAwareFileListFilter<ChannelSftp.LsEntry> {
private static final long ONE_SECOND = 1000;
private static final long DEFAULT_AGE = 30;
private volatile long age = DEFAULT_AGE;
@Nullable
private Consumer<ChannelSftp.LsEntry> discardCallback;
public LastModifiedLsEntryFileListFilter(final long age) {
this.age = age;
}
@Override
public List<ChannelSftp.LsEntry> filterFiles(final ChannelSftp.LsEntry[] files) {
final List<ChannelSftp.LsEntry> list = new ArrayList<>();
final long now = System.currentTimeMillis() / ONE_SECOND;
for (final ChannelSftp.LsEntry file : files) {
if (this.fileIsAged(file, now)) {
log.info("File [{}] is aged...", file.getFilename());
list.add(file);
} else if (this.discardCallback != null) {
log.info("File [{}] is still being uploaded...", file.getFilename());
this.discardCallback.accept(file);
}
}
return list;
}
@Override
public boolean accept(final ChannelSftp.LsEntry file) {
if (this.fileIsAged(file, System.currentTimeMillis() / ONE_SECOND)) {
return true;
}
else if (this.discardCallback != null) {
this.discardCallback.accept(file);
}
return false;
}
private boolean fileIsAged(final ChannelSftp.LsEntry file, final long now) {
return file.getAttrs().getMTime() + this.age <= now;
}
@Override
public void addDiscardCallback(@Nullable final Consumer<ChannelSftp.LsEntry> discardCallbackToSet) {
this.discardCallback = discardCallbackToSet;
}
}
The filter is able to correctly identify the age of file and discards it but that file is not retried which I believe is part of discard callback.过滤器能够正确识别文件的年龄并丢弃它,但不会重试该文件,我认为这是丢弃回调的一部分。 I guess my question is how to set discard callback to keep retrying the discarded file until files
ages
.我想我的问题是如何设置丢弃回调以继续重试丢弃的文件,直到文件
ages
。 Thanks谢谢
not retried which I believe is part of discard callback.
未重试,我认为这是丢弃回调的一部分。
I wonder what makes you think that way...我想知道是什么让你有这样的想法......
The fact that FileReadingMessageSource
with its WatchService
option has the logic like this: FileReadingMessageSource
及其WatchService
选项具有如下逻辑:
if (filter instanceof DiscardAwareFileListFilter) {
((DiscardAwareFileListFilter<File>) filter).addDiscardCallback(this.filesToPoll::add);
}
doesn't mean that SFTP implementation is similar.并不意味着 SFTP 实现是相似的。
The retry is there anyway: on the next poll not accepted file will be checked again.无论如何都要重试:在下一次轮询中,未接受的文件将再次检查。
You probably don't show other filters you use, and your file is filtered out before this LastModifiedLsEntryFileListFilter
, eg with the SftpPersistentAcceptOnceFileListFilter
.您可能没有显示您使用的其他过滤器,并且您的文件在此
LastModifiedLsEntryFileListFilter
之前被过滤掉,例如使用SftpPersistentAcceptOnceFileListFilter
。 You need to consider to have your "last-modified" as a first one in the chain.您需要考虑将“最后修改”作为链中的第一个。
If you are not going to support discard callback from the outside, you probably don't need to implement that DiscardAwareFileListFilter
at all.如果您不打算支持来自外部的丢弃回调,您可能根本不需要实现
DiscardAwareFileListFilter
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.