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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractInboundFileSynchronizer(SessionFactory<F> sessionFactory) Create a synchronizer with theSessionFactoryused to acquireSessioninstances. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidvoidclose()protected booleancopyFileToLocalDirectory(String remoteDirectoryPath, EvaluationContext localFileEvaluationContext, F remoteFile, File localDirectory, Session<F> session) protected voiddoInit()Subclasses can override to perform initialization - called fromInitializingBean.afterPropertiesSet().protected final voiddoSetFilter(FileListFilter<F> filterToSet) protected final voiddoSetRemoteDirectoryExpression(Expression expression) filterFiles(F[] files) protected Comparator<? extends F> protected abstract StringgetFilename(F file) protected abstract longgetModified(F file) getRemoteFileMetadata(File localFile) Obtain a metadata for remote file associated with the provided local file.protected Stringprotected abstract booleanprotected abstract Stringprotocol()Return the protocol this synchronizer works with.voidremoveRemoteFileMetadata(File localFile) Remove a metadata for remote file associated with the provided local file.protected voidrollbackFromFileToListEnd(List<F> filteredFiles, F file) voidsetBeanFactory(BeanFactory beanFactory) voidsetBeanName(String name) voidsetComparator(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.voidsetDeleteRemoteFiles(boolean deleteRemoteFiles) Set to true to enable deletion of remote files after successful transfer.voidsetFilter(FileListFilter<F> filter) Set the filter to be applied to the remote files before transferring.voidsetLocalFilenameGeneratorExpression(Expression localFilenameGeneratorExpression) Set an expression used to determine the local file name.voidsetLocalFilenameGeneratorExpressionString(String localFilenameGeneratorExpression) Set an expression used to determine the local file name.voidsetMetadataStorePrefix(String metadataStorePrefix) Specify a prefix for keys in metadata store do not clash with other keys in the shared store.voidsetPreserveTimestamp(boolean preserveTimestamp) Set to true to enable the preservation of the remote file timestamp when transferring.voidsetRemoteDirectory(String remoteDirectory) Specify the full path to the remote directory.voidsetRemoteDirectoryExpression(Expression remoteDirectoryExpression) Specify an expression that evaluates to the full path to the remote directory.voidsetRemoteDirectoryExpressionString(String remoteDirectoryExpression) Specify an expression that evaluates to the full path to the remote directory.voidsetRemoteFileMetadataStore(MetadataStore remoteFileMetadataStore) Configure aMetadataStoreto hold a remote file info (host, port, remote directory) to transfer downstream in message headers when local file is pulled.voidsetRemoteFileSeparator(String remoteFileSeparator) voidsetTemporaryFileSuffix(String temporaryFileSuffix) Set a temporary file suffix to be used while transferring files.voidsynchronizeToLocalDirectory(File localDirectory) Synchronize all available files to the local directory.voidsynchronizeToLocalDirectory(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 theSessionFactoryused to acquireSessioninstances.- 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 aMetadataStoreto hold a remote file info (host, port, remote directory) to transfer downstream in message headers when local file is pulled.- Parameters:
remoteFileMetadataStore- theMetadataStoreto 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:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-
setBeanName
- Specified by:
setBeanNamein interfaceBeanNameAware
-
afterPropertiesSet
public final void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
doInit
protected void doInit()Subclasses can override to perform initialization - called fromInitializingBean.afterPropertiesSet(). -
filterFiles
-
getTemporaryFileSuffix
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
synchronizeToLocalDirectory
Description copied from interface:InboundFileSynchronizerSynchronize all available files to the local directory.- Specified by:
synchronizeToLocalDirectoryin interfaceInboundFileSynchronizer- Parameters:
localDirectory- the directory.
-
synchronizeToLocalDirectory
Description copied from interface:InboundFileSynchronizerSynchronize up to maxFetchSize files to the local directory.- Specified by:
synchronizeToLocalDirectoryin interfaceInboundFileSynchronizer- Parameters:
localDirectory- the directory.maxFetchSize- the maximum files to fetch.
-
rollbackFromFileToListEnd
-
copyFileToLocalDirectory
protected boolean copyFileToLocalDirectory(@Nullable 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
-