org.springframework.integration.file
Class FileReadingMessageSource

java.lang.Object
  extended by org.springframework.integration.file.FileReadingMessageSource
All Implemented Interfaces:
MessageDeliveryAware<java.io.File>, MessageSource<java.io.File>

public class FileReadingMessageSource
extends java.lang.Object
implements MessageSource<java.io.File>, MessageDeliveryAware<java.io.File>

PollableSource 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.

A common problem with reading files is that a file may be detected before it is ready. The default 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 for a way to do this.

Author:
Iwein Fuld

Constructor Summary
FileReadingMessageSource()
           
 
Method Summary
 void onFailure(Message<java.io.File> failedMessage, java.lang.Throwable t)
          In concurrent scenarios onFailure() might cause failing files to be ignored.
 void onSend(Message<java.io.File> sentMessage)
          Callback method invoked after a message is sent successfully.
 Message<java.io.File> receive()
          Retrieve the next available message from this source.
 void setFilter(FileListFilter filter)
          Sets a FileFilter on the PollableSource.
 void setInputDirectory(org.springframework.core.io.Resource inputDirectory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileReadingMessageSource

public FileReadingMessageSource()
Method Detail

setInputDirectory

public void setInputDirectory(org.springframework.core.io.Resource inputDirectory)

setFilter

public void setFilter(FileListFilter filter)
Sets a FileFilter on the PollableSource. By default a AcceptOnceFileListFilter with no bounds is used. In most cases a customized FileFilter will be needed to deal with modification and duplication concerns. If multiple filters are required a CompositeFileListFilter can be used to group them together

Note that the supplied filter must be thread safe.


receive

public Message<java.io.File> receive()
                              throws MessagingException
Description copied from interface: MessageSource
Retrieve the next available message from this source. Returns null if no message is available.

Specified by:
receive in interface MessageSource<java.io.File>
Throws:
MessagingException

onFailure

public void onFailure(Message<java.io.File> failedMessage,
                      java.lang.Throwable t)
In concurrent scenarios onFailure() might cause failing files to be ignored. If this is not acceptable access to this method should be synchronized on this instance externally.

Specified by:
onFailure in interface MessageDeliveryAware<java.io.File>

onSend

public void onSend(Message<java.io.File> sentMessage)
Description copied from interface: MessageDeliveryAware
Callback method invoked after a message is sent successfully.

Specified by:
onSend in interface MessageDeliveryAware<java.io.File>