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
FileListFilter
s to
ensure the file entry is acceptable.
- Since:
- 2.0
- Author:
- Josh Long, Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractInboundFileSynchronizer
(SessionFactory<F> sessionFactory) Create a synchronizer with theSessionFactory
used to acquireSession
instances. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
void
close()
protected boolean
copyFileToLocalDirectory
(String remoteDirectoryPath, EvaluationContext localFileEvaluationContext, F remoteFile, File localDirectory, Session<F> session) protected void
doInit()
Subclasses can override to perform initialization - called fromInitializingBean.afterPropertiesSet()
.protected final void
doSetFilter
(FileListFilter<F> filterToSet) protected final void
doSetRemoteDirectoryExpression
(Expression expression) filterFiles
(F[] files) protected Comparator<? extends F>
protected abstract String
getFilename
(F file) protected abstract long
getModified
(F file) getRemoteFileMetadata
(File localFile) Obtain a metadata for remote file associated with the provided local file.protected String
protected abstract boolean
protected abstract String
protocol()
Return the protocol this synchronizer works with.void
removeRemoteFileMetadata
(File localFile) Remove a metadata for remote file associated with the provided local file.protected void
rollbackFromFileToListEnd
(List<F> filteredFiles, F file) void
setBeanFactory
(BeanFactory beanFactory) void
setBeanName
(String name) void
setComparator
(Comparator<? extends F> comparator) Set a comparator to sort the retrieved list ofF
(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
(Expression localFilenameGeneratorExpression) Set an expression used to determine the local file name.void
setLocalFilenameGeneratorExpressionString
(String localFilenameGeneratorExpression) Set an expression used to determine the local file name.void
setMetadataStorePrefix
(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
(String remoteDirectory) Specify the full path to the remote directory.void
setRemoteDirectoryExpression
(Expression remoteDirectoryExpression) Specify an expression that evaluates to the full path to the remote directory.void
setRemoteDirectoryExpressionString
(String remoteDirectoryExpression) Specify an expression that evaluates to the full path to the remote directory.void
setRemoteFileMetadataStore
(MetadataStore remoteFileMetadataStore) Configure aMetadataStore
to hold a remote file info (host, port, remote directory) to transfer downstream in message headers when local file is pulled.void
setRemoteFileSeparator
(String remoteFileSeparator) void
setTemporaryFileSuffix
(String temporaryFileSuffix) Set a temporary file suffix to be used while transferring files.void
synchronizeToLocalDirectory
(File localDirectory) Synchronize all available files to the local directory.void
synchronizeToLocalDirectory
(File localDirectory, int maxFetchSize) Synchronize up to maxFetchSize files to the local directory.
-
Field Details
-
EXPRESSION_PARSER
-
logger
-
-
Constructor Details
-
AbstractInboundFileSynchronizer
Create a synchronizer with theSessionFactory
used to acquireSession
instances.- Parameters:
sessionFactory
- The session factory.
-
-
Method Details
-
getComparator
-
setComparator
Set a comparator to sort the retrieved list ofF
(the Type that represents the remote file) prior to applying filters and max fetch size.- Parameters:
comparator
- the comparator.- Since:
- 5.1
-
setRemoteFileSeparator
- Parameters:
remoteFileSeparator
- the remote file separator.- See Also:
-
setLocalFilenameGeneratorExpression
Set an expression used to determine the local file name.- Parameters:
localFilenameGeneratorExpression
- the expression.
-
setLocalFilenameGeneratorExpressionString
Set an expression used to determine the local file name.- Parameters:
localFilenameGeneratorExpression
- the expression.- Since:
- 4.3.13
- See Also:
-
setTemporaryFileSuffix
Set a temporary file suffix to be used while transferring files. Default ".writing".- Parameters:
temporaryFileSuffix
- the file suffix.
-
setRemoteDirectory
Specify the full path to the remote directory.- Parameters:
remoteDirectory
- The remote directory.
-
setRemoteDirectoryExpression
Specify an expression that evaluates to the full path to the remote directory.- Parameters:
remoteDirectoryExpression
- The remote directory expression.- Since:
- 4.2
-
setRemoteDirectoryExpressionString
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
-
setFilter
Set the filter to be applied to the remote files before transferring.- Parameters:
filter
- the file list filter.
-
doSetFilter
-
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
Configure aMetadataStore
to hold a remote file info (host, port, remote directory) to transfer downstream in message headers when local file is pulled.- Parameters:
remoteFileMetadataStore
- theMetadataStore
to use.- Since:
- 5.2
-
setMetadataStorePrefix
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
- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Throws:
BeansException
-
setBeanName
- Specified by:
setBeanName
in interfaceBeanNameAware
-
afterPropertiesSet
public final void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
doInit
protected void doInit()Subclasses can override to perform initialization - called fromInitializingBean.afterPropertiesSet()
. -
filterFiles
-
getTemporaryFileSuffix
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
synchronizeToLocalDirectory
Description copied from interface:InboundFileSynchronizer
Synchronize all available files to the local directory.- Specified by:
synchronizeToLocalDirectory
in interfaceInboundFileSynchronizer
- Parameters:
localDirectory
- the directory.
-
synchronizeToLocalDirectory
Description copied from interface:InboundFileSynchronizer
Synchronize up to maxFetchSize files to the local directory.- Specified by:
synchronizeToLocalDirectory
in interfaceInboundFileSynchronizer
- Parameters:
localDirectory
- the directory.maxFetchSize
- the maximum files to fetch.
-
rollbackFromFileToListEnd
-
copyFileToLocalDirectory
protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, @Nullable EvaluationContext localFileEvaluationContext, F remoteFile, File localDirectory, Session<F> session) throws IOException - Throws:
IOException
-
getRemoteFileMetadata
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
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
-
getFilename
-
getModified
-
protocol
Return the protocol this synchronizer works with.- Returns:
- the protocol this synchronizer works with.
- Since:
- 5.2
-