|
Spring Integration | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.integration.file.FileReadingMessageSource
public class FileReadingMessageSource
MessageSource
that creates messages from a file system directory. To prevent messages for certain files, you
may supply a FileListFilter
. By default, an AcceptOnceFileListFilter
is used. It ensures files are
picked up only once from the directory.
AcceptOnceFileListFilter
does not prevent this. In most cases, this can be prevented if the file-writing process
renames each file as soon as it is ready for reading. A pattern-matching filter that accepts only files that are
ready (e.g. based on a known suffix), composed with the default AcceptOnceFileListFilter
would allow for
this. See CompositeFileListFilter
for a way to do this.
A Comparator
can be used to ensure internal ordering of the Files in a PriorityBlockingQueue
. This
does not provide the same guarantees as a ResequencingMessageGroupProcessor
, but in cases where writing files and failure
downstream are rare it might be sufficient.
FileReadingMessageSource is fully thread-safe under concurrent receive()
invocations and message
delivery callbacks.
Constructor Summary | |
---|---|
FileReadingMessageSource()
Creates a FileReadingMessageSource with a naturally ordered queue of unbounded capacity. |
|
FileReadingMessageSource(Comparator<File> receptionOrderComparator)
Creates a FileReadingMessageSource with a PriorityBlockingQueue ordered with the passed in Comparator
The size of the queue used should be large enough to hold all the files in the input directory in order to sort
all of them, so restricting the size of the queue is mutually exclusive with ordering. |
|
FileReadingMessageSource(int internalQueueCapacity)
Creates a FileReadingMessageSource with a bounded queue of the given capacity. |
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
void |
onFailure(Message<File> failedMessage,
Throwable t)
Adds the failed message back to the 'toBeReceived' queue if there is room. |
void |
onSend(Message<File> sentMessage)
The message is just logged. |
Message<File> |
receive()
Retrieve the next available message from this source. |
void |
setAutoCreateDirectory(boolean autoCreateDirectory)
Specify whether to create the source directory automatically if it does not yet exist upon initialization. |
void |
setDirectory(File directory)
Specify the input directory. |
void |
setFilter(FileListFilter filter)
Sets a FileListFilter . |
void |
setLocker(FileLocker locker)
Optional. |
void |
setScanEachPoll(boolean scanEachPoll)
Optional. |
void |
setScanner(DirectoryScanner scanner)
Optionally specify a custom scanner, for example the RecursiveLeafOnlyDirectoryScanner |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileReadingMessageSource()
public FileReadingMessageSource(int internalQueueCapacity)
internalQueueCapacity
- the size of the queue used to cache files to be received internally. This queue can
be made larger to optimize the directory scanning. With scanEachPoll set to false
and the queue to a large size, it will be filled once and then completely emptied
before a new directory listing is done. This is particularly useful to reduce scans
of large numbers of files in a directory.public FileReadingMessageSource(Comparator<File> receptionOrderComparator)
PriorityBlockingQueue
ordered with the passed in Comparator
The size of the queue used should be large enough to hold all the files in the input directory in order to sort
all of them, so restricting the size of the queue is mutually exclusive with ordering. No guarantees about file
delivery order can be made under concurrent access.
receptionOrderComparator
- the comparator to be used to order the files in the internal queueMethod Detail |
---|
public void setDirectory(File directory)
public void setScanner(DirectoryScanner scanner)
RecursiveLeafOnlyDirectoryScanner
public void setAutoCreateDirectory(boolean autoCreateDirectory)
public void setFilter(FileListFilter filter)
FileListFilter
. By default a AcceptOnceFileListFilter
with no bounds is used. In most
cases a customized FileListFilter
will be needed to deal with modification and duplication concerns. If
multiple filters are required a CompositeFileListFilter
can be used to group them together.
The supplied filter must be thread safe..
public void setLocker(FileLocker locker)
org.springframework.integration.file.locking.FileLocker
to be used to guard files
against duplicate processing.
The supplied FileLocker must be thread safe
public void setScanEachPoll(boolean scanEachPoll)
BlockingQueue
that this class is keeping will more likely be out of sync with the file
system if this flag is set to false
, but it will change more often (causing expensive reordering) if
it is set to true
.
public final void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
public Message<File> receive() throws MessagingException
MessageSource
null
if no message is available.
receive
in interface MessageSource<File>
MessagingException
public void onFailure(Message<File> failedMessage, Throwable t)
public void onSend(Message<File> sentMessage)
receive()
|
Spring Integration | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |