Package adams.flow.source
Class DirectoryLister
-
- All Implemented Interfaces:
AdditionalInformationHandler,ArrayProvider,CleanUpHandler,Destroyable,GlobalInfoSupporter,ForwardSlashSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,QuickInfoSupporter,ShallowCopySupporter<Actor>,SizeOfHandler,Stoppable,StoppableWithFeedback,VariablesInspectionHandler,VariableChangeListener,Actor,ArrayProvider,ErrorHandler,OutputProducer,Serializable,Comparable
public class DirectoryLister extends AbstractArrayProvider implements ForwardSlashSupporter
Returns the contents of a directory (files/dirs).
Input/output:
- generates:
java.lang.String
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-name <java.lang.String> (property: name) The name of the actor. default: DirectoryLister
-annotation <adams.core.base.BaseAnnotation> (property: annotations) The annotations to attach to this actor. default:
-skip <boolean> (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is. default: false
-stop-flow-on-error <boolean> (property: stopFlowOnError) If set to true, the flow execution at this level gets stopped in case this actor encounters an error; the error gets propagated; useful for critical actors. default: false
-silent <boolean> (property: silent) If enabled, then no errors are output in the console; Note: the enclosing actor handler must have this enabled as well. default: false
-output-array <boolean> (property: outputArray) Whether to output the files as array or as single strings. default: false
-dir <adams.core.io.PlaceholderDirectory> (property: watchDir) The directory to watch for files/directories. default: ${CWD}-list-dirs <boolean> (property: listDirs) Whether to include directories in the output. default: false
-list-files <boolean> (property: listFiles) Whether to include files in the output. default: false
-max-items <int> (property: maxItems) The maximum number of items (files/dirs) to return (<= 0 is unlimited). default: -1
-regexp <adams.core.base.BaseRegExp> (property: regExp) The regular expression that the files/dirs must match (empty string matches all). default:
-sorting <NO_SORTING|SORT_BY_NAME|SORT_BY_LAST_MODIFIED> (property: sorting) The type of sorting to perform. default: NO_SORTING
-descending <boolean> (property: sortDescending) If set to true, the files are sorted in descending manner. default: false
-recursive <boolean> (property: recursive) Whether to search recursively or not. default: false
-max-depth <int> (property: maxDepth) The maximum depth to search in recursive mode (1 = only watch directory, -1 = infinite). default: -1
-stop-file <java.lang.String> (property: stopFile) The name of the file, that finishes the watching. default: STOP.txt
-wait <int> (property: wait) The number of seconds to wait before polling the directory again if no elements were retrieved; a value of -1 indicates that polling happens only once. default: -1
-always-wait <boolean> (property: alwaysWait) If set to true, then the waiting period is enforced between polls, even if there are files/dirs that could get processed. default: false
-skip-locked <boolean> (property: skipLockedFiles) If set to true, locked files are skipped. Depends on the underlying OS how this is implemented. Under Linux, a JVM would have to lock the file explicitly via java.nio.channels.FileChannel.lock(). Simply opening it for writing does not lock the file. default: false
-min-timestamp <adams.core.base.BaseDateTime> (property: minFileTimestamp) The minimum file timestamp that the files can have. default: -INF
-max-timestamp <adams.core.base.BaseDateTime> (property: maxFileTimestamp) The maximum file timestamp that the files can have. default: +INF
-use-forward-slashes <boolean> (property: useForwardSlashes) If enabled, forward slashes are used in the output (but the '\\' prefix of UNC paths is not converted). default: false
- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_AlwaysWaitwhether to always wait between polls, even if other files are still present.protected LocalDirectoryListerm_Listerfor listing the contents.protected booleanm_PauseRequiredwhether a pause before the next polling is required.protected booleanm_UseForwardSlasheswhether to output forward slashes.protected intm_Waitthe number of seconds to wait between polls without no entries.-
Fields inherited from class adams.flow.source.AbstractArrayProvider
m_Index, m_OutputArray, m_Queue
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description DirectoryLister()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringalwaysWaitTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.protected StringdoExecute()Executes the flow item.booleangetAlwaysWait()Returns whether to always wait in between polls, even if there are still other files that could get processed.protected ClassgetItemClass()Returns the based class of the items.booleangetListDirs()Returns whether directories are listed.booleangetListFiles()Returns whether directories are listed.intgetMaxDepth()Returns the maximum depth to search (in recursive mode). 1 = only watch directory, -1 = infinite.BaseDateTimegetMaxFileTimestamp()Returns the maximum file timestamp that the files have to have.intgetMaxItems()Returns the maximum number of items to return.BaseDateTimegetMinFileTimestamp()Returns the minimum file timestamp that the files have to have.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.booleangetRecursive()Returns whether search is recursively.BaseRegExpgetRegExp()Returns the regular expression for the files/dirs.booleangetSkipLockedFiles()Returns whether to skip locked files.booleangetSortDescending()Returns whether to sort descendingly.SortinggetSorting()Returns the type of sorting to perform.StringgetStopFile()Returns the name of the stop file.booleangetUseForwardSlashes()Returns whether to use forward slashes in the output.intgetWait()Returns the number of seconds to wait before polling the directory again if no elements were retrieved.PlaceholderDirectorygetWatchDir()Returns the incoming directory.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.booleanisFinished()Returns whether the item has finished.StringlistDirsTipText()Returns the tip text for this property.StringlistFilesTipText()Returns the tip text for this property.StringmaxDepthTipText()Returns the tip text for this property.StringmaxFileTimestampTipText()Returns the tip text for this property.StringmaxItemsTipText()Returns the tip text for this property.StringminFileTimestampTipText()Returns the tip text for this property.StringoutputArrayTipText()Returns the tip text for this property.StringrecursiveTipText()Returns the tip text for this property.StringregExpTipText()Returns the tip text for this property.protected voidreset()Resets the actor.voidsetAlwaysWait(boolean value)Sets whether to always wait in between polls, even if there are still other files that could get processed.voidsetListDirs(boolean value)Sets whether to list directories.voidsetListFiles(boolean value)Sets whether to list files.voidsetLoggingLevel(LoggingLevel value)Sets the logging level.voidsetMaxDepth(int value)Sets the maximum depth to search (in recursive mode). 1 = only watch directory, -1 = infinite.voidsetMaxFileTimestamp(BaseDateTime value)Sets the maximum file timestamp that the files have to have.voidsetMaxItems(int value)Sets the maximum number of items to return.voidsetMinFileTimestamp(BaseDateTime value)Sets the minimum file timestamp that the files have to have.voidsetRecursive(boolean value)Sets whether to search recursively.voidsetRegExp(BaseRegExp value)Sets the regular expression for the files/dirs.voidsetSkipLockedFiles(boolean value)Sets whether to skip locked files.voidsetSortDescending(boolean value)Sets whether to sort descendingly.voidsetSorting(Sorting value)Sets the type of sorting to perform.voidsetStopFile(String value)Sets the name of the stop file.StringsetUp()Initializes the item for flow execution.voidsetUseForwardSlashes(boolean value)Sets whether to use forward slashes in the output.voidsetWait(int value)Sets the number of seconds to wait before polling the directory again if no elements were retrieved.voidsetWatchDir(PlaceholderDirectory value)Sets the incoming directory.StringskipLockedFilesTipText()Returns the tip text for this property.StringsortDescendingTipText()Returns the tip text for this property.StringsortingTipText()Returns the tip text for this property.voidstopExecution()Stops the execution.StringstopFileTipText()Returns the tip text for this property.StringuseForwardSlashesTipText()Returns the tip text for this property.StringwaitTipText()Returns the tip text for this property.StringwatchDirTipText()Returns the tip text for this property.-
Methods inherited from class adams.flow.source.AbstractArrayProvider
generates, getOutputArray, hasPendingOutput, output, preExecute, setOutputArray, wrapUp
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, pruneBackup, pruneBackup, restoreState, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, toCommandLine, variableChanged
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
m_Lister
protected LocalDirectoryLister m_Lister
for listing the contents.
-
m_Wait
protected int m_Wait
the number of seconds to wait between polls without no entries.
-
m_AlwaysWait
protected boolean m_AlwaysWait
whether to always wait between polls, even if other files are still present.
-
m_PauseRequired
protected boolean m_PauseRequired
whether a pause before the next polling is required.
-
m_UseForwardSlashes
protected boolean m_UseForwardSlashes
whether to output forward slashes.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractArrayProvider
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfoin interfaceActor- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin classAbstractActor- Returns:
- null if no info available, otherwise short string
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractActor
-
reset
protected void reset()
Resets the actor.- Overrides:
resetin classAbstractArrayProvider
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Specified by:
setLoggingLevelin interfaceLoggingLevelHandler- Overrides:
setLoggingLevelin classAbstractOptionHandler- Parameters:
value- the level
-
setWatchDir
public void setWatchDir(PlaceholderDirectory value)
Sets the incoming directory.- Parameters:
value- the incoming directory
-
getWatchDir
public PlaceholderDirectory getWatchDir()
Returns the incoming directory.- Returns:
- the incoming directory.
-
watchDirTipText
public String watchDirTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMaxItems
public void setMaxItems(int value)
Sets the maximum number of items to return.- Parameters:
value- the maximum number
-
getMaxItems
public int getMaxItems()
Returns the maximum number of items to return.- Returns:
- the maximum number
-
maxItemsTipText
public String maxItemsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
outputArrayTipText
public String outputArrayTipText()
Returns the tip text for this property.- Specified by:
outputArrayTipTextin interfaceArrayProvider- Specified by:
outputArrayTipTextin interfaceArrayProvider- Specified by:
outputArrayTipTextin classAbstractArrayProvider- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRegExp
public void setRegExp(BaseRegExp value)
Sets the regular expression for the files/dirs.- Parameters:
value- the regular expression
-
getRegExp
public BaseRegExp getRegExp()
Returns the regular expression for the files/dirs.- Returns:
- the regular expression
-
regExpTipText
public String regExpTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStopFile
public void setStopFile(String value)
Sets the name of the stop file.- Parameters:
value- the regular expression
-
getStopFile
public String getStopFile()
Returns the name of the stop file.- Returns:
- the name
-
stopFileTipText
public String stopFileTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setListDirs
public void setListDirs(boolean value)
Sets whether to list directories.- Parameters:
value- true if directories are to be listed
-
getListDirs
public boolean getListDirs()
Returns whether directories are listed.- Returns:
- true if directories are listed
-
listDirsTipText
public String listDirsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setListFiles
public void setListFiles(boolean value)
Sets whether to list files.- Parameters:
value- true if files are to be listed
-
getListFiles
public boolean getListFiles()
Returns whether directories are listed.- Returns:
- true if directories are listed
-
listFilesTipText
public String listFilesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSorting
public void setSorting(Sorting value)
Sets the type of sorting to perform.- Parameters:
value- the type of sorting
-
getSorting
public Sorting getSorting()
Returns the type of sorting to perform.- Returns:
- the type of sorting
-
sortingTipText
public String sortingTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSortDescending
public void setSortDescending(boolean value)
Sets whether to sort descendingly.- Parameters:
value- true if sorting in descending order
-
getSortDescending
public boolean getSortDescending()
Returns whether to sort descendingly.- Returns:
- true if sorting in descending order
-
sortDescendingTipText
public String sortDescendingTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setWait
public void setWait(int value)
Sets the number of seconds to wait before polling the directory again if no elements were retrieved.- Parameters:
value- the number of seconds
-
getWait
public int getWait()
Returns the number of seconds to wait before polling the directory again if no elements were retrieved.- Returns:
- the number of seconds
-
waitTipText
public String waitTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setAlwaysWait
public void setAlwaysWait(boolean value)
Sets whether to always wait in between polls, even if there are still other files that could get processed.- Parameters:
value- if true then waiting period is enforced between polls
-
getAlwaysWait
public boolean getAlwaysWait()
Returns whether to always wait in between polls, even if there are still other files that could get processed.- Returns:
- true if waiting period is enforced between polls
-
alwaysWaitTipText
public String alwaysWaitTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRecursive
public void setRecursive(boolean value)
Sets whether to search recursively.- Parameters:
value- true if search is recursively
-
getRecursive
public boolean getRecursive()
Returns whether search is recursively.- Returns:
- true if search is recursively
-
recursiveTipText
public String recursiveTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMaxDepth
public void setMaxDepth(int value)
Sets the maximum depth to search (in recursive mode). 1 = only watch directory, -1 = infinite.- Parameters:
value- the maximum number of directory levels to traverse
-
getMaxDepth
public int getMaxDepth()
Returns the maximum depth to search (in recursive mode). 1 = only watch directory, -1 = infinite.- Returns:
- the maximum number of directory levels to traverse
-
maxDepthTipText
public String maxDepthTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSkipLockedFiles
public void setSkipLockedFiles(boolean value)
Sets whether to skip locked files. Depends on the underlying OS, whether a file is flagged as locked. E.g., in a JVM under Linux, one would have to lock the file explicitly usingjava.nio.channels.FileChannel.lock(), since simply opening it for writing does not lock it.- Parameters:
value- if true then locked files are skipped
-
getSkipLockedFiles
public boolean getSkipLockedFiles()
Returns whether to skip locked files.- Returns:
- true if locked files are skipped
-
skipLockedFilesTipText
public String skipLockedFilesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMinFileTimestamp
public void setMinFileTimestamp(BaseDateTime value)
Sets the minimum file timestamp that the files have to have.- Parameters:
value- the minimum file timestamp
-
getMinFileTimestamp
public BaseDateTime getMinFileTimestamp()
Returns the minimum file timestamp that the files have to have.- Returns:
- the minimum file timestamp
-
minFileTimestampTipText
public String minFileTimestampTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMaxFileTimestamp
public void setMaxFileTimestamp(BaseDateTime value)
Sets the maximum file timestamp that the files have to have.- Parameters:
value- the maximum file timestamp
-
getMaxFileTimestamp
public BaseDateTime getMaxFileTimestamp()
Returns the maximum file timestamp that the files have to have.- Returns:
- the maximum file timestamp
-
maxFileTimestampTipText
public String maxFileTimestampTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setUseForwardSlashes
public void setUseForwardSlashes(boolean value)
Sets whether to use forward slashes in the output.- Specified by:
setUseForwardSlashesin interfaceForwardSlashSupporter- Parameters:
value- if true then use forward slashes
-
getUseForwardSlashes
public boolean getUseForwardSlashes()
Returns whether to use forward slashes in the output.- Specified by:
getUseForwardSlashesin interfaceForwardSlashSupporter- Returns:
- true if forward slashes are used
-
useForwardSlashesTipText
public String useForwardSlashesTipText()
Returns the tip text for this property.- Specified by:
useForwardSlashesTipTextin interfaceForwardSlashSupporter- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getItemClass
protected Class getItemClass()
Returns the based class of the items.- Specified by:
getItemClassin classAbstractArrayProvider- Returns:
- the class
-
setUp
public String setUp()
Initializes the item for flow execution.- Specified by:
setUpin interfaceActor- Overrides:
setUpin classAbstractActor- Returns:
- null if everything is fine, otherwise error message
- See Also:
AbstractActor.reset()
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecutein classAbstractActor- Returns:
- null if everything is fine, otherwise error message
-
isFinished
public boolean isFinished()
Returns whether the item has finished. Theexecute()will be called as long as theisFinished()method returns false.- Specified by:
isFinishedin interfaceActor- Overrides:
isFinishedin classAbstractActor- Returns:
- true if finished, false if further calls to execute() are necessary. Only stops when directory lister encountered the stop file or m_Wait=-1.
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecutionin interfaceActor- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractActor
-
-