org.springframework.integration.adapter.file
Class AbstractDirectorySource<T>

java.lang.Object
  extended by org.springframework.integration.adapter.file.AbstractDirectorySource<T>
All Implemented Interfaces:
MessageDeliveryAware, MessageSource<T>, PollableSource<T>
Direct Known Subclasses:
FileSource, FtpSource

public abstract class AbstractDirectorySource<T>
extends java.lang.Object
implements PollableSource<T>, MessageDeliveryAware

Base class for implementing a PollableSource that creates messages from files in a directory, either local or remote.

Author:
Marius Bogoevici, Iwein Fuld

Field Summary
private  Backlog<FileInfo> directoryContentManager
           
static java.lang.String FILE_INFO_PROPERTY
           
private  org.apache.commons.logging.Log logger
           
private  MessageCreator<T,T> messageCreator
           
 
Constructor Summary
AbstractDirectorySource(MessageCreator<T,T> messageCreator)
           
 
Method Summary
protected  Message<T> buildNextMessage()
          Hook point for implementors to create the next message that should be received.
protected  void fileProcessed(java.lang.String... fileNames)
           
protected  Backlog<FileInfo> getDirectoryContentManager()
           
 MessageCreator<T,T> getMessageCreator()
           
 void onFailure(Message<?> failedMessage, java.lang.Throwable exception)
          Callback method invoked after a message delivery failure.
abstract  void onSend(Message<?> message)
          Callback method invoked after a message is sent successfully.
protected abstract  void populateSnapshot(java.util.Map<java.lang.String,FileInfo> snapshot)
          Constructs the snapshot by iterating files.
 Message<T> receive()
          Retrieve a message from this source or null if no message is available.
protected  void refreshSnapshotAndMarkProcessing(Backlog<FileInfo> directoryContentManager)
          Naive implementation that ignores thread safety.
protected abstract  T retrieveNextPayload()
          Returns the next file, based on the backlog data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_INFO_PROPERTY

public static final java.lang.String FILE_INFO_PROPERTY
See Also:
Constant Field Values

logger

private final org.apache.commons.logging.Log logger

directoryContentManager

private final Backlog<FileInfo> directoryContentManager

messageCreator

private final MessageCreator<T,T> messageCreator
Constructor Detail

AbstractDirectorySource

public AbstractDirectorySource(MessageCreator<T,T> messageCreator)
Method Detail

getDirectoryContentManager

protected Backlog<FileInfo> getDirectoryContentManager()

getMessageCreator

public MessageCreator<T,T> getMessageCreator()

receive

public final Message<T> receive()
Description copied from interface: PollableSource
Retrieve a message from this source or null if no message is available.

Specified by:
receive in interface PollableSource<T>

refreshSnapshotAndMarkProcessing

protected void refreshSnapshotAndMarkProcessing(Backlog<FileInfo> directoryContentManager)
                                         throws java.io.IOException
Naive implementation that ignores thread safety. Subclasses that want to be thread safe and use the reservation facilities of Backlog should override this method and call directoryContentManager.fileProcessing(...) with the appropriate arguments.

Parameters:
directoryContentManager -
Throws:
java.io.IOException

buildNextMessage

protected Message<T> buildNextMessage()
                               throws java.io.IOException
Hook point for implementors to create the next message that should be received. Implementations can use a File by File approach (like FileSource). In cases where retrieval could be expensive because of network latency, a batched approach could be implemented here. See FtpSource for an example.

Returns:
the next message containing (part of) the unprocessed content of the directory
Throws:
java.io.IOException

onSend

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

Specified by:
onSend in interface MessageDeliveryAware

onFailure

public void onFailure(Message<?> failedMessage,
                      java.lang.Throwable exception)
Description copied from interface: MessageDeliveryAware
Callback method invoked after a message delivery failure.

Specified by:
onFailure in interface MessageDeliveryAware

populateSnapshot

protected abstract void populateSnapshot(java.util.Map<java.lang.String,FileInfo> snapshot)
                                  throws java.io.IOException
Constructs the snapshot by iterating files.

Parameters:
snapshot -
Throws:
java.io.IOException

retrieveNextPayload

protected abstract T retrieveNextPayload()
                                  throws java.io.IOException
Returns the next file, based on the backlog data.

Returns:
Throws:
java.io.IOException

fileProcessed

protected final void fileProcessed(java.lang.String... fileNames)