简体   繁体   English

用于 Sftp 入站适配器的 LastModifiedFileListFilter

[英]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.

相关问题 Spring SFTP入站适配器出现问题 - Problems with spring sftp inbound adapter 为什么SFTP入站/出站通道适配器有单独的通道声明,为什么没有简单文件入站/出站通道适配器的通道声明? - Why there is separate channel declaration for SFTP inbound/outbound channel adapter and why not for simple file inbound/outbound channel adapter? Spring SFTP入站chanel适配器删除本地文件 - Spring SFTP inbound chanel adapter delete local file SFTP入站通道适配器挂在PollableChannel接收方法上 - SFTP inbound channel adapter hangs at PollableChannel receive method 同步工厂删除sftp:inbound-channel-adapter的文件夹 - Synchronization-factory deletes folder for sftp:inbound-channel-adapter 如何在使用入站流通道适配器时从 SFTP 中删除文件 - How to delete File from SFTP while using inbound-streaming-channel-adapter Spring 使用入站适配器消息处理程序中的出站网关的 Sftp 获取文件 - Spring Sftp fetch file using outbound gateway within inbound adapter message handler 如何为 Spring Integration SFTP 入站适配器动态定义文件过滤器模式? - How to dynamically define file filter pattern for Spring Integration SFTP Inbound Adapter? 使用Spring Integration for Inbound Adapter时如何检查SFTP连接是否成功 - How to check whether the SFTP connection is successful or not when using Spring Integration for Inbound Adapter 使用int-sftp:inbound-channel-adapter时重新读取文件 - Re Read file when using int-sftp:inbound-channel-adapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM