Top Description Inners Fields Constructors Methods
org.mortbay.util

public Class Scanner

extends Object
Class Inheritance
Imports
java.io.File, .FilenameFilter, .IOException, java.util.ArrayList, .Collections, .HashMap, .HashSet, .Iterator, .List, .Map, .Set, .Timer, .TimerTask, org.mortbay.log.Log

Scanner Utility for scanning a directory for added, removed and changed files and reporting these events via registered Listeners. TODO AbstractLifeCycle

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
public static interface
public static interface
Scanner.Listener

Listener Marker for notifications re file changes.

Field Summary

Modifier and TypeField and Description
private static int
private Map<K, V>
private FilenameFilter
private List<E>
private Map<K, V>
private boolean
private boolean
private volatile boolean
private List<E>
private int
private TimerTask
private Timer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addListener(Scanner.Listener listener)

Add an added/removed/changed listener

public FilenameFilter
getFilenameFilter()

Get any filter applied to files in the scan dir.

public boolean
public File
getScanDir()

Deprecated use getScanDirs() instead
Get the location of the directory to scan
public List<E>
public int

Returns:

interval between scans in seconds
getScanInterval
()

Get the scan interval

public Timer
public TimerTask
public synchronized void
removeListener(Scanner.Listener
the Listener to be removed
listener
)

Remove a registered listener

private void
reportAddition(String filename)

Report a file addition to the registered FileAddedListeners

private void
reportBulkChanges(List<E> filenames)

private void
reportChange(String filename)

Report a file change to the FileChangedListeners

public void
reportDifferences(Map<K, V>
the info from the most recent pass
currentScan
,
Map<K, V>
info from the previous pass
oldScan
)

Report the adds/changes/removes to the registered listeners

private void
reportRemoval(String filename)

Report a file removal to the FileRemovedListeners

public void
scan()

Perform a pass of the scanner and report changes

private void
scanFile(File
file or directory
f
,
Map<K, V>
map of filenames to last modified times
scanInfoMap
)

Get last modified time on a single file or recurse if the file is a directory.

public void

Returns:

Map of name of file to last modified time
scanFiles
()

Recursively scan all files in the designated directories.

public void
public void
setFilenameFilter(FilenameFilter filter)

Apply a filter to files found in the scan directory.

public void
setRecursive(boolean recursive)

public void
setReportExistingFilesOnStartup(boolean
if true, all files found on initial scan will be reported as being added, otherwise not
reportExisting
)

Whether or not an initial scan will report all files as being added.

public void
setScanDir(File dir)

Deprecated use setScanDirs(List dirs) instead
Set the location of the directory to scan.
public void
setScanDirs(List<E> dirs)

public synchronized void
setScanInterval(int
pause between scans in seconds
scanInterval
)

Set the scan interval

public synchronized void
start()

Start the scanning action.

public synchronized void
stop()

Stop the scanning.

private void
warn(Object listener, String filename, Throwable th)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__scannerIdback to summary
private static int __scannerId
_currentScanback to summary
private Map<K, V> _currentScan
_filterback to summary
private FilenameFilter _filter
_listenersback to summary
private List<E> _listeners
_prevScanback to summary
private Map<K, V> _prevScan
_recursiveback to summary
private boolean _recursive
_reportExistingback to summary
private boolean _reportExisting
_runningback to summary
private volatile boolean _running
_scanDirsback to summary
private List<E> _scanDirs
_scanIntervalback to summary
private int _scanInterval
_taskback to summary
private TimerTask _task
_timerback to summary
private Timer _timer

Constructor Detail

Scannerback to summary
public Scanner()

Method Detail

addListenerback to summary
public synchronized void addListener(Scanner.Listener listener)

Add an added/removed/changed listener

getFilenameFilterback to summary
public FilenameFilter getFilenameFilter()

Get any filter applied to files in the scan dir.

getRecursiveback to summary
public boolean getRecursive()
getScanDirback to summary
public File getScanDir()

Deprecated

use getScanDirs() instead

Get the location of the directory to scan

getScanDirsback to summary
public List<E> getScanDirs()
getScanIntervalback to summary
public int getScanInterval()

Get the scan interval

Returns:int

interval between scans in seconds

newTimerback to summary
public Timer newTimer()
newTimerTaskback to summary
public TimerTask newTimerTask()
removeListenerback to summary
public synchronized void removeListener(Scanner.Listener listener)

Remove a registered listener

Parameters
listener:Scanner.Listener

the Listener to be removed

reportAdditionback to summary
private void reportAddition(String filename)

Report a file addition to the registered FileAddedListeners

reportBulkChangesback to summary
private void reportBulkChanges(List<E> filenames)
reportChangeback to summary
private void reportChange(String filename)

Report a file change to the FileChangedListeners

reportDifferencesback to summary
public void reportDifferences(Map<K, V> currentScan, Map<K, V> oldScan)

Report the adds/changes/removes to the registered listeners

Parameters
currentScan:Map<K, V>

the info from the most recent pass

oldScan:Map<K, V>

info from the previous pass

reportRemovalback to summary
private void reportRemoval(String filename)

Report a file removal to the FileRemovedListeners

scanback to summary
public void scan()

Perform a pass of the scanner and report changes

scanFileback to summary
private void scanFile(File f, Map<K, V> scanInfoMap)

Get last modified time on a single file or recurse if the file is a directory.

Parameters
f:File

file or directory

scanInfoMap:Map<K, V>

map of filenames to last modified times

scanFilesback to summary
public void scanFiles()

Recursively scan all files in the designated directories.

Returns:void

Map of name of file to last modified time

scheduleback to summary
public void schedule()
setFilenameFilterback to summary
public void setFilenameFilter(FilenameFilter filter)

Apply a filter to files found in the scan directory. Only files matching the filter will be reported as added/changed/removed.

setRecursiveback to summary
public void setRecursive(boolean recursive)
setReportExistingFilesOnStartupback to summary
public void setReportExistingFilesOnStartup(boolean reportExisting)

Whether or not an initial scan will report all files as being added.

Parameters
reportExisting:boolean

if true, all files found on initial scan will be reported as being added, otherwise not

setScanDirback to summary
public void setScanDir(File dir)

Deprecated

use setScanDirs(List dirs) instead

Set the location of the directory to scan.

setScanDirsback to summary
public void setScanDirs(List<E> dirs)
setScanIntervalback to summary
public synchronized void setScanInterval(int scanInterval)

Set the scan interval

Parameters
scanInterval:int

pause between scans in seconds

startback to summary
public synchronized void start()

Start the scanning action.

stopback to summary
public synchronized void stop()

Stop the scanning.

warnback to summary
private void warn(Object listener, String filename, Throwable th)
org.mortbay.util back to summary

public Interface Scanner.BulkListener

extends Listener

Method Summary

Modifier and TypeMethod and Description
public void
filesChanged(List<E> filenames)

Method Detail

filesChangedback to summary
public void filesChanged(List<E> filenames) throws Exception
org.mortbay.util back to summary

public Interface Scanner.DiscreteListener

extends Listener

Method Summary

Modifier and TypeMethod and Description
public void
fileAdded(String filename)

public void
fileChanged(String filename)

public void
fileRemoved(String filename)

Method Detail

fileAddedback to summary
public void fileAdded(String filename) throws Exception
fileChangedback to summary
public void fileChanged(String filename) throws Exception
fileRemovedback to summary
public void fileRemoved(String filename) throws Exception
org.mortbay.util back to summary

public Interface Scanner.Listener

Known Direct Subinterfaces
org.mortbay.util.Scanner.DiscreteListener, org.mortbay.util.Scanner.BulkListener

Listener Marker for notifications re file changes.