Spring Integration

org.springframework.integration.file
Class DefaultDirectoryScanner

java.lang.Object
  extended by org.springframework.integration.file.DefaultDirectoryScanner
All Implemented Interfaces:
DirectoryScanner
Direct Known Subclasses:
HeadDirectoryScanner, RecursiveLeafOnlyDirectoryScanner

public class DefaultDirectoryScanner
extends Object
implements DirectoryScanner

Default directory scanner and base class for other directory scanners. It takes care of the default interrelations between filtering, scanning and locking.

Since:
2.0
Author:
Iwein Fuld

Constructor Summary
DefaultDirectoryScanner()
           
 
Method Summary
protected  File[] listEligibleFiles(File directory)
          Subclasses may refine the listing strategy by overriding this method.
 List<File> listFiles(File directory)
          Scans the directory according to the strategy particular to this implementation and returns the selected files as a File array.
 void setFilter(EntryListFilter<File> filter)
          Sets a custom filter to be used by this scanner.
 void setLocker(FileLocker locker)
          Sets a custom locker to be used by this scanner.
 boolean tryClaim(File file)
          Claim the file to process.

This class takes the minimal implementation and merely delegates to the locker if set.

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDirectoryScanner

public DefaultDirectoryScanner()
Method Detail

listFiles

public final List<File> listFiles(File directory)
                           throws IllegalArgumentException
Description copied from interface: DirectoryScanner
Scans the directory according to the strategy particular to this implementation and returns the selected files as a File array. This method may never return files that are rejected by the filter.

Specified by:
listFiles in interface DirectoryScanner
Parameters:
directory - the directory to scan for files
Returns:
a list of files representing the content of the directory
Throws:
IllegalArgumentException - thrown if the input is incorrect

listEligibleFiles

protected File[] listEligibleFiles(File directory)
Subclasses may refine the listing strategy by overriding this method. The files returned here are passed onto the filter.

Parameters:
directory - root directory to use for listing
Returns:
the files this scanner should consider

setFilter

public void setFilter(EntryListFilter<File> filter)
Description copied from interface: DirectoryScanner
Sets a custom filter to be used by this scanner. The filter will get a chance to reject files before the scanner presents them through its listFiles method. A scanner may use additional filtering that is out of the control of the provided filter.

Specified by:
setFilter in interface DirectoryScanner
Parameters:
filter - the custom filter to be used

tryClaim

public final boolean tryClaim(File file)
Claim the file to process. It is up to the implementation to decide what additional safe guards are required to attain a claim to the file. But if a locker is set implementations MUST invoke its lock method and MUST return false if the locker did not grant the lock.

This class takes the minimal implementation and merely delegates to the locker if set.

Specified by:
tryClaim in interface DirectoryScanner
Parameters:
file - file to be claimed
Returns:
true if the claim was granted false otherwise

setLocker

public final void setLocker(FileLocker locker)
Sets a custom locker to be used by this scanner. The locker will get a chance to lock files and reject claims on files that are already locked.

Specified by:
setLocker in interface DirectoryScanner
Parameters:
locker - the custom locker to be used

Spring Integration

Copyright © 2010. All Rights Reserved.