Class AbstractInboundFileSynchronizer<F>

java.lang.Object
org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer<F>
Type Parameters:
F - the Type that represents a remote file.
All Implemented Interfaces:
Closeable, AutoCloseable, Aware, BeanFactoryAware, BeanNameAware, InitializingBean, InboundFileSynchronizer
Direct Known Subclasses:
FtpInboundFileSynchronizer, SftpInboundFileSynchronizer, SmbInboundFileSynchronizer

public abstract class AbstractInboundFileSynchronizer<F> extends Object implements InboundFileSynchronizer, BeanFactoryAware, BeanNameAware, InitializingBean, Closeable
Base class charged with knowing how to connect to a remote file system, scan it for new files and then download the files.

The implementation should run through any configured FileListFilters to ensure the file entry is acceptable.

Since:
2.0
Author:
Josh Long, Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
  • Field Details

    • EXPRESSION_PARSER

      protected static final ExpressionParser EXPRESSION_PARSER
    • logger

      protected final Log logger
  • Constructor Details

    • AbstractInboundFileSynchronizer

      public AbstractInboundFileSynchronizer(SessionFactory<F> sessionFactory)
      Create a synchronizer with the SessionFactory used to acquire Session instances.
      Parameters:
      sessionFactory - The session factory.
  • Method Details

    • getComparator

      @Nullable protected Comparator<? extends F> getComparator()
    • setComparator

      public void setComparator(@Nullable Comparator<? extends F> comparator)
      Set a comparator to sort the retrieved list of F (the Type that represents the remote file) prior to applying filters and max fetch size.
      Parameters:
      comparator - the comparator.
      Since:
      5.1
    • setRemoteFileSeparator

      public void setRemoteFileSeparator(String remoteFileSeparator)
      Parameters:
      remoteFileSeparator - the remote file separator.
      See Also:
    • setLocalFilenameGeneratorExpression

      public void setLocalFilenameGeneratorExpression(Expression localFilenameGeneratorExpression)
      Set an expression used to determine the local file name.
      Parameters:
      localFilenameGeneratorExpression - the expression.
    • setLocalFilenameGeneratorExpressionString

      public void setLocalFilenameGeneratorExpressionString(String localFilenameGeneratorExpression)
      Set an expression used to determine the local file name.
      Parameters:
      localFilenameGeneratorExpression - the expression.
      Since:
      4.3.13
      See Also:
    • setTemporaryFileSuffix

      public void setTemporaryFileSuffix(String temporaryFileSuffix)
      Set a temporary file suffix to be used while transferring files. Default ".writing".
      Parameters:
      temporaryFileSuffix - the file suffix.
    • setRemoteDirectory

      public void setRemoteDirectory(String remoteDirectory)
      Specify the full path to the remote directory.
      Parameters:
      remoteDirectory - The remote directory.
    • setRemoteDirectoryExpression

      public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression)
      Specify an expression that evaluates to the full path to the remote directory.
      Parameters:
      remoteDirectoryExpression - The remote directory expression.
      Since:
      4.2
    • setRemoteDirectoryExpressionString

      public void setRemoteDirectoryExpressionString(String remoteDirectoryExpression)
      Specify an expression that evaluates to the full path to the remote directory.
      Parameters:
      remoteDirectoryExpression - The remote directory expression.
      Since:
      4.3.13
      See Also:
    • doSetRemoteDirectoryExpression

      protected final void doSetRemoteDirectoryExpression(Expression expression)
    • setFilter

      public void setFilter(@Nullable FileListFilter<F> filter)
      Set the filter to be applied to the remote files before transferring.
      Parameters:
      filter - the file list filter.
    • doSetFilter

      protected final void doSetFilter(@Nullable FileListFilter<F> filterToSet)
    • setDeleteRemoteFiles

      public void setDeleteRemoteFiles(boolean deleteRemoteFiles)
      Set to true to enable deletion of remote files after successful transfer.
      Parameters:
      deleteRemoteFiles - true to delete.
    • setPreserveTimestamp

      public void setPreserveTimestamp(boolean preserveTimestamp)
      Set to true to enable the preservation of the remote file timestamp when transferring.
      Parameters:
      preserveTimestamp - true to preserve.
    • setRemoteFileMetadataStore

      public void setRemoteFileMetadataStore(MetadataStore remoteFileMetadataStore)
      Configure a MetadataStore to hold a remote file info (host, port, remote directory) to transfer downstream in message headers when local file is pulled.
      Parameters:
      remoteFileMetadataStore - the MetadataStore to use.
      Since:
      5.2
    • setMetadataStorePrefix

      public void setMetadataStorePrefix(String metadataStorePrefix)
      Specify a prefix for keys in metadata store do not clash with other keys in the shared store.
      Parameters:
      metadataStorePrefix - the prefix to use.
      Since:
      5.2
      See Also:
    • setBeanFactory

      public void setBeanFactory(BeanFactory beanFactory) throws BeansException
      Specified by:
      setBeanFactory in interface BeanFactoryAware
      Throws:
      BeansException
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface BeanNameAware
    • afterPropertiesSet

      public final void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • doInit

      protected void doInit()
      Subclasses can override to perform initialization - called from InitializingBean.afterPropertiesSet().
    • filterFiles

      protected final List<F> filterFiles(F[] files)
    • getTemporaryFileSuffix

      protected String getTemporaryFileSuffix()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • synchronizeToLocalDirectory

      public void synchronizeToLocalDirectory(File localDirectory)
      Description copied from interface: InboundFileSynchronizer
      Synchronize all available files to the local directory.
      Specified by:
      synchronizeToLocalDirectory in interface InboundFileSynchronizer
      Parameters:
      localDirectory - the directory.
    • synchronizeToLocalDirectory

      public void synchronizeToLocalDirectory(File localDirectory, int maxFetchSize)
      Description copied from interface: InboundFileSynchronizer
      Synchronize up to maxFetchSize files to the local directory.
      Specified by:
      synchronizeToLocalDirectory in interface InboundFileSynchronizer
      Parameters:
      localDirectory - the directory.
      maxFetchSize - the maximum files to fetch.
    • rollbackFromFileToListEnd

      protected void rollbackFromFileToListEnd(List<F> filteredFiles, F file)
    • copyFileToLocalDirectory

      protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, @Nullable EvaluationContext localFileEvaluationContext, F remoteFile, File localDirectory, Session<F> session) throws IOException
      Throws:
      IOException
    • getRemoteFileMetadata

      @Nullable public String getRemoteFileMetadata(File localFile)
      Obtain a metadata for remote file associated with the provided local file.
      Parameters:
      localFile - the local file to retrieve metadata for.
      Returns:
      the metadata for remove file in the URI style: protocol://host:port/remoteDirectory#remoteFileName
      Since:
      5.2
    • removeRemoteFileMetadata

      public void removeRemoteFileMetadata(File localFile)
      Remove a metadata for remote file associated with the provided local file.
      Parameters:
      localFile - the local file to remove metadata for.
      Since:
      5.2
    • isFile

      protected abstract boolean isFile(F file)
    • getFilename

      protected abstract String getFilename(F file)
    • getModified

      protected abstract long getModified(F file)
    • protocol

      protected abstract String protocol()
      Return the protocol this synchronizer works with.
      Returns:
      the protocol this synchronizer works with.
      Since:
      5.2