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:
java.io.Closeable, java.lang.AutoCloseable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, InboundFileSynchronizer

public abstract class AbstractInboundFileSynchronizer<F>
extends java.lang.Object
implements InboundFileSynchronizer, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, java.io.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
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static org.springframework.expression.ExpressionParser EXPRESSION_PARSER  
    protected org.apache.commons.logging.Log logger  
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractInboundFileSynchronizer​(SessionFactory<F> sessionFactory)
    Create a synchronizer with the SessionFactory used to acquire Session instances.
  • Method Summary

    Modifier and Type Method Description
    void afterPropertiesSet()  
    void close()  
    protected boolean copyFileToLocalDirectory​(java.lang.String remoteDirectoryPath, org.springframework.expression.EvaluationContext localFileEvaluationContext, F remoteFile, java.io.File localDirectory, Session<F> session)  
    protected void doInit()
    Subclasses can override to perform initialization - called from InitializingBean.afterPropertiesSet().
    protected void doSetFilter​(FileListFilter<F> filterToSet)  
    protected void doSetRemoteDirectoryExpression​(org.springframework.expression.Expression expression)  
    protected java.util.List<F> filterFiles​(F[] files)  
    protected java.util.Comparator<F> getComparator()  
    protected abstract java.lang.String getFilename​(F file)  
    protected abstract long getModified​(F file)  
    java.lang.String getRemoteFileMetadata​(java.io.File localFile)
    Obtain a metadata for remote file associated with the provided local file.
    protected java.lang.String getTemporaryFileSuffix()  
    protected abstract boolean isFile​(F file)  
    protected abstract java.lang.String protocol()
    Return the protocol this synchronizer works with.
    void removeRemoteFileMetadata​(java.io.File localFile)
    Remove a metadata for remote file associated with the provided local file.
    protected void rollbackFromFileToListEnd​(java.util.List<F> filteredFiles, F file)  
    void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)  
    void setBeanName​(java.lang.String name)  
    void setComparator​(java.util.Comparator<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.
    void setDeleteRemoteFiles​(boolean deleteRemoteFiles)
    Set to true to enable deletion of remote files after successful transfer.
    void setFilter​(FileListFilter<F> filter)
    Set the filter to be applied to the remote files before transferring.
    void setLocalFilenameGeneratorExpression​(org.springframework.expression.Expression localFilenameGeneratorExpression)
    Set an expression used to determine the local file name.
    void setLocalFilenameGeneratorExpressionString​(java.lang.String localFilenameGeneratorExpression)
    Set an expression used to determine the local file name.
    void setMetadataStorePrefix​(java.lang.String metadataStorePrefix)
    Specify a prefix for keys in metadata store do not clash with other keys in the shared store.
    void setPreserveTimestamp​(boolean preserveTimestamp)
    Set to true to enable the preservation of the remote file timestamp when transferring.
    void setRemoteDirectory​(java.lang.String remoteDirectory)
    Specify the full path to the remote directory.
    void setRemoteDirectoryExpression​(org.springframework.expression.Expression remoteDirectoryExpression)
    Specify an expression that evaluates to the full path to the remote directory.
    void setRemoteDirectoryExpressionString​(java.lang.String remoteDirectoryExpression)
    Specify an expression that evaluates to the full path to the remote directory.
    void setRemoteFileMetadataStore​(org.springframework.integration.metadata.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.
    void setRemoteFileSeparator​(java.lang.String remoteFileSeparator)  
    void setTemporaryFileSuffix​(java.lang.String temporaryFileSuffix)
    Set a temporary file suffix to be used while transferring files.
    void synchronizeToLocalDirectory​(java.io.File localDirectory)
    Synchronize all available files to the local directory.
    void synchronizeToLocalDirectory​(java.io.File localDirectory, int maxFetchSize)
    Synchronize up to maxFetchSize files to the local directory.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EXPRESSION_PARSER

      protected static final org.springframework.expression.ExpressionParser EXPRESSION_PARSER
    • logger

      protected final org.apache.commons.logging.Log logger
  • Constructor Details

  • Method Details

    • getComparator

      @Nullable protected java.util.Comparator<F> getComparator()
    • setComparator

      public void setComparator​(@Nullable java.util.Comparator<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​(java.lang.String remoteFileSeparator)
      Parameters:
      remoteFileSeparator - the remote file separator.
      See Also:
      RemoteFileTemplate.setRemoteFileSeparator(String)
    • setLocalFilenameGeneratorExpression

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

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

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

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

      public void setRemoteDirectoryExpression​(org.springframework.expression.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​(java.lang.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:
      setRemoteDirectoryExpression(Expression)
    • doSetRemoteDirectoryExpression

      protected final void doSetRemoteDirectoryExpression​(org.springframework.expression.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​(org.springframework.integration.metadata.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​(java.lang.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:
      setRemoteFileMetadataStore(MetadataStore)
    • setBeanFactory

      public void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException
    • setBeanName

      public void setBeanName​(java.lang.String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • afterPropertiesSet

      public final void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • doInit

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

      protected final java.util.List<F> filterFiles​(F[] files)
    • getTemporaryFileSuffix

      protected java.lang.String getTemporaryFileSuffix()
    • close

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

      public void synchronizeToLocalDirectory​(java.io.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​(java.io.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​(java.util.List<F> filteredFiles, F file)
    • copyFileToLocalDirectory

      protected boolean copyFileToLocalDirectory​(java.lang.String remoteDirectoryPath, @Nullable org.springframework.expression.EvaluationContext localFileEvaluationContext, F remoteFile, java.io.File localDirectory, Session<F> session) throws java.io.IOException
      Throws:
      java.io.IOException
    • getRemoteFileMetadata

      @Nullable public java.lang.String getRemoteFileMetadata​(java.io.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​(java.io.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 java.lang.String getFilename​(F file)
    • getModified

      protected abstract long getModified​(F file)
    • protocol

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