Package gov.usgs.util
Class DirectoryPoller
- java.lang.Object
-
- gov.usgs.util.DirectoryPoller
-
public class DirectoryPoller extends java.lang.Object
Monitor a directory for files, notifying FileListenerInterfaces. Implementers of the FileListenerInterface should process files before returning, because these files may move or disappear.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DirectoryPoller.PollTask
The Polling Task.
-
Constructor Summary
Constructors Constructor Description DirectoryPoller(java.io.File pollDirectory, java.io.File storageDirectory)
Create a DirectoryPoller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFileListener(FileListenerInterface listener)
java.io.File
getPollDirectory()
java.io.File
getStorageDirectory()
void
notifyListeners(java.io.File file)
Notify all listeners that files exist and need to be processed.void
removeFileListener(FileListenerInterface listener)
void
start(long frequencyInMilliseconds)
Start polling in a background thread.void
stop()
Stop any currently scheduled polling.
-
-
-
Constructor Detail
-
DirectoryPoller
public DirectoryPoller(java.io.File pollDirectory, java.io.File storageDirectory)
Create a DirectoryPoller.- Parameters:
pollDirectory
- directory that is polled for new files.storageDirectory
- directory where polled files are moved. When null, polled files are deleted after calling listeners.
-
-
Method Detail
-
getPollDirectory
public java.io.File getPollDirectory()
- Returns:
- pollDirectory file
-
getStorageDirectory
public java.io.File getStorageDirectory()
- Returns:
- storageDirectory file
-
addFileListener
public void addFileListener(FileListenerInterface listener)
- Parameters:
listener
- FileListenerInterface to add
-
removeFileListener
public void removeFileListener(FileListenerInterface listener)
- Parameters:
listener
- FileListenerInterface to remove
-
start
public void start(long frequencyInMilliseconds)
Start polling in a background thread. Any previously scheduled polling is stopped before starting at this frequency. This schedules using fixed-delay (time between complete polls) as opposed to fixed-rate (how often to start polling).- Parameters:
frequencyInMilliseconds
- how often to poll.
-
stop
public void stop()
Stop any currently scheduled polling.
-
notifyListeners
public void notifyListeners(java.io.File file)
Notify all listeners that files exist and need to be processed.- Parameters:
file
- that needs to be processed
-
-