Java Sftp入站适配器的LastModifiedFileListFilter
我正在尝试实现Java Sftp入站适配器的LastModifiedFileListFilter,java,spring,spring-integration,spring-integration-sftp,Java,Spring,Spring Integration,Spring Integration Sftp,我正在尝试实现LastModifiedFileListFilter,因为5.3.2版本的spring integration sftp似乎还没有类似的过滤器,我尝试从spring integration文件复制LastModifiedFileListFilter,但放弃回调不起作用。以下是我的实现: @Slf4j @Data public class LastModifiedLsEntryFileListFilter implements DiscardAwareFileListFilter&l
LastModifiedFileListFilter
,因为5.3.2版本的spring integration sftp似乎还没有类似的过滤器,我尝试从spring integration文件复制LastModifiedFileListFilter
,但放弃回调不起作用。以下是我的实现:
@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;
}
}
@Slf4j
@资料
公共类LastModifiedSentryFileListFilter实现DiscardAwareFileListFilter{
专用静态最终长1秒=1000;
私人静态最终长期默认年龄=30岁;
私人易变长年龄=默认年龄;
@可空
私人消费者;
公共LastModifiedSentryFileListFilter(最终长期){
这个。年龄=年龄;
}
@凌驾
公共列表筛选器文件(最终通道sftp.LsEntry[]文件){
最终列表=新的ArrayList();
final long now=System.currentTimeMillis()/一秒;
用于(最终ChannelSftp.LsEntry文件:文件){
if(this.fileIsAged(file,now)){
log.info(“文件[{}]已过期…”,File.getFilename());
列表。添加(文件);
}else if(this.discardCallback!=null){
log.info(“文件[{}]仍在上载…”,File.getFilename());
this.discardCallback.accept(文件);
}
}
退货清单;
}
@凌驾
公共布尔接受(最终ChannelSftp.LsEntry文件){
if(this.fileIsAged(file,System.currentTimeMillis()/1秒)){
返回true;
}
else if(this.discardCallback!=null){
this.discardCallback.accept(文件);
}
返回false;
}
私有布尔文件已标记(最终ChannelSftp.LsEntry文件,最终long now){
返回文件.getAttrs().getMTime()+this.age
不重试,我相信这是放弃回调的一部分
我想知道是什么让你这么想
FileReadingMessageSource
及其WatchService
选项的逻辑如下:
if (filter instanceof DiscardAwareFileListFilter) {
((DiscardAwareFileListFilter<File>) filter).addDiscardCallback(this.filesToPoll::add);
}
if(DiscardAwareFileListFilter的筛选器实例){
((DiscardAwareFileListFilter)filter).addDiscardCallback(this.filesToPoll::add);
}
这并不意味着SFTP实现是类似的
重试仍然存在:下次轮询时,将再次检查未接受的文件
您可能不显示您使用的其他过滤器,并且您的文件在这个代码之前被过滤掉。LASTMODIFIEDLCSNEYFILististFux,例如用<代码> SFFTPrimeEntEntCyFielistFaster 。您需要考虑将“最后修改”作为链中的第一个修改。
如果您不打算从外部支持discard callback,您可能根本不需要实现该DiscardAwareFileListFilter
。感谢您为我指明了正确的方向。是的,确实是其他筛选器导致了问题。我洗牌了筛选器序列,它按预期工作。正如您所建议的那样ested我没有使用任何外部丢弃回调,因此实现了FileListFilter
。再次感谢!!很酷!所以,听起来是时候这样做了:!