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 boolean
m_AlwaysWait
whether to always wait between polls, even if other files are still present.protected LocalDirectoryLister
m_Lister
for listing the contents.protected boolean
m_PauseRequired
whether a pause before the next polling is required.protected boolean
m_UseForwardSlashes
whether to output forward slashes.protected int
m_Wait
the 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 String
alwaysWaitTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.boolean
getAlwaysWait()
Returns whether to always wait in between polls, even if there are still other files that could get processed.protected Class
getItemClass()
Returns the based class of the items.boolean
getListDirs()
Returns whether directories are listed.boolean
getListFiles()
Returns whether directories are listed.int
getMaxDepth()
Returns the maximum depth to search (in recursive mode).BaseDateTime
getMaxFileTimestamp()
Returns the maximum file timestamp that the files have to have.int
getMaxItems()
Returns the maximum number of items to return.BaseDateTime
getMinFileTimestamp()
Returns the minimum file timestamp that the files have to have.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.boolean
getRecursive()
Returns whether search is recursively.BaseRegExp
getRegExp()
Returns the regular expression for the files/dirs.boolean
getSkipLockedFiles()
Returns whether to skip locked files.boolean
getSortDescending()
Returns whether to sort descendingly.Sorting
getSorting()
Returns the type of sorting to perform.String
getStopFile()
Returns the name of the stop file.boolean
getUseForwardSlashes()
Returns whether to use forward slashes in the output.int
getWait()
Returns the number of seconds to wait before polling the directory again if no elements were retrieved.PlaceholderDirectory
getWatchDir()
Returns the incoming directory.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.boolean
isFinished()
Returns whether the item has finished.String
listDirsTipText()
Returns the tip text for this property.String
listFilesTipText()
Returns the tip text for this property.String
maxDepthTipText()
Returns the tip text for this property.String
maxFileTimestampTipText()
Returns the tip text for this property.String
maxItemsTipText()
Returns the tip text for this property.String
minFileTimestampTipText()
Returns the tip text for this property.String
outputArrayTipText()
Returns the tip text for this property.String
recursiveTipText()
Returns the tip text for this property.String
regExpTipText()
Returns the tip text for this property.protected void
reset()
Resets the actor.void
setAlwaysWait(boolean value)
Sets whether to always wait in between polls, even if there are still other files that could get processed.void
setListDirs(boolean value)
Sets whether to list directories.void
setListFiles(boolean value)
Sets whether to list files.void
setLoggingLevel(LoggingLevel value)
Sets the logging level.void
setMaxDepth(int value)
Sets the maximum depth to search (in recursive mode).void
setMaxFileTimestamp(BaseDateTime value)
Sets the maximum file timestamp that the files have to have.void
setMaxItems(int value)
Sets the maximum number of items to return.void
setMinFileTimestamp(BaseDateTime value)
Sets the minimum file timestamp that the files have to have.void
setRecursive(boolean value)
Sets whether to search recursively.void
setRegExp(BaseRegExp value)
Sets the regular expression for the files/dirs.void
setSkipLockedFiles(boolean value)
Sets whether to skip locked files.void
setSortDescending(boolean value)
Sets whether to sort descendingly.void
setSorting(Sorting value)
Sets the type of sorting to perform.void
setStopFile(String value)
Sets the name of the stop file.String
setUp()
Initializes the item for flow execution.void
setUseForwardSlashes(boolean value)
Sets whether to use forward slashes in the output.void
setWait(int value)
Sets the number of seconds to wait before polling the directory again if no elements were retrieved.void
setWatchDir(PlaceholderDirectory value)
Sets the incoming directory.String
skipLockedFilesTipText()
Returns the tip text for this property.String
sortDescendingTipText()
Returns the tip text for this property.String
sortingTipText()
Returns the tip text for this property.void
stopExecution()
Stops the execution.String
stopFileTipText()
Returns the tip text for this property.String
useForwardSlashesTipText()
Returns the tip text for this property.String
waitTipText()
Returns the tip text for this property.String
watchDirTipText()
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:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractArrayProvider
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractActor
-
reset
protected void reset()
Resets the actor.- Overrides:
reset
in classAbstractArrayProvider
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Specified by:
setLoggingLevel
in interfaceLoggingLevelHandler
- Overrides:
setLoggingLevel
in 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:
outputArrayTipText
in interfaceArrayProvider
- Specified by:
outputArrayTipText
in interfaceArrayProvider
- Specified by:
outputArrayTipText
in 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:
setUseForwardSlashes
in interfaceForwardSlashSupporter
- Parameters:
value
- if true then use forward slashes
-
getUseForwardSlashes
public boolean getUseForwardSlashes()
Returns whether to use forward slashes in the output.- Specified by:
getUseForwardSlashes
in interfaceForwardSlashSupporter
- Returns:
- true if forward slashes are used
-
useForwardSlashesTipText
public String useForwardSlashesTipText()
Returns the tip text for this property.- Specified by:
useForwardSlashesTipText
in 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:
getItemClass
in classAbstractArrayProvider
- Returns:
- the class
-
setUp
public String setUp()
Initializes the item for flow execution.- Specified by:
setUp
in interfaceActor
- Overrides:
setUp
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
- See Also:
AbstractActor.reset()
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in 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:
isFinished
in interfaceActor
- Overrides:
isFinished
in 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:
stopExecution
in interfaceActor
- Specified by:
stopExecution
in interfaceStoppable
- Overrides:
stopExecution
in classAbstractActor
-
-