Package adams.flow.standalone
Class DirWatch
-
- All Implemented Interfaces:
AdditionalInformationHandler
,AtomicMoveSupporter
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,VariableChangeListener
,Actor
,ActorHandler
,DaemonEvent
,ErrorHandler
,Event
,Flushable
,MutableActorHandler
,Serializable
,Comparable
public class DirWatch extends AbstractMutableActorDaemonEvent<WatchKey,String[]> implements AtomicMoveSupporter
- 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_AtomicMove
whether to perform an atomic move.protected WatchEventKind[]
m_Events
the events to look for.protected boolean
m_MoveFiles
whether to move the files before transmitting them.protected BaseRegExp
m_RegExp
the regular expression to match the file names against.protected RunnableWithLogging
m_Runnable
waits for events.protected PlaceholderDirectory
m_Source
the directory to watch.protected PlaceholderDirectory
m_Target
the directory to move the files to.protected int
m_WaitPoll
the waiting period in msec before polling again.protected WatchService
m_Watch
the watch service.protected Path
m_WatchedDir
the watched directory.-
Fields inherited from class adams.flow.standalone.AbstractMutableActorDaemonEvent
BUSY, m_Actors, m_ExecutingActors, m_NoDiscard, NO_OUTPUT
-
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 DirWatch()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
atomicMoveTipText()
Returns the tip text for this property.String
check()
Hook method for performing checks.protected String
checkActors(Actor[] actors)
Checks the actors before they are set via the setActors method.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.String
eventsTipText()
Returns the tip text for this property.boolean
getAtomicMove()
Returns whether to attempt atomic move operation.WatchEventKind[]
getEvents()
Returns the events to report.boolean
getMoveFiles()
Returns whether to move the files to the specified target directory before transmitting them.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.BaseRegExp
getRegExp()
Returns the regular expression to match the filenames against (name only, not path).PlaceholderDirectory
getSource()
Returns the incoming directory.PlaceholderDirectory
getTarget()
Returns the move-to directory.int
getWaitPoll()
Returns the number of milli-seconds to wait before polling again whether files have arrived.String
globalInfo()
Returns a string describing the object.protected boolean
handlesEvent(WatchKey e)
Checks whether the event is being handled.String
moveFilesTipText()
Returns the tip text for this property.protected String[]
preProcessEvent(WatchKey key)
Preprocesses the event.String
regExpTipText()
Returns the tip text for this property.protected void
reset()
Resets the scheme.void
setAtomicMove(boolean value)
Sets whether to attempt atomic move operation.void
setEvents(WatchEventKind[] value)
Sets the events to report.void
setMoveFiles(boolean value)
Sets whether to move the files to the specified target directory before transmitting them.void
setRegExp(BaseRegExp value)
Sets the regular expression to match the filenames against (name only, not path).void
setSource(PlaceholderDirectory value)
Sets the incoming directory.void
setTarget(PlaceholderDirectory value)
Sets the move-to directory.void
setWaitPoll(int value)
Sets the number of milli-seconds to wait before polling whether files have arrived.String
sourceTipText()
Returns the tip text for this property.void
stopExecution()
Stops the execution.protected void
stopWatchService()
Stops the watch service, if active.String
targetTipText()
Returns the tip text for this property.protected boolean
usePreProcessedAsInput()
Returns whether the preprocessed event is used as input token.String
waitPollTipText()
Returns the tip text for this property.void
wrapUp()
Cleans up after the execution has finished.-
Methods inherited from class adams.flow.standalone.AbstractMutableActorDaemonEvent
active, actorsTipText, add, add, cleanUp, firstActive, flushExecution, forceVariables, get, getActorHandlerInfo, getActors, getNoDiscard, indexOf, initialize, lastActive, noDiscardTipText, processEvent, remove, removeAll, set, setActors, setLoggingLevel, setNoDiscard, setUp, size, updateParent
-
Methods inherited from class adams.flow.standalone.AbstractStandalone
preExecute
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, 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, isFinished, 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
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, isFinished, 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_Source
protected PlaceholderDirectory m_Source
the directory to watch.
-
m_Events
protected WatchEventKind[] m_Events
the events to look for.
-
m_WaitPoll
protected int m_WaitPoll
the waiting period in msec before polling again.
-
m_RegExp
protected BaseRegExp m_RegExp
the regular expression to match the file names against.
-
m_MoveFiles
protected boolean m_MoveFiles
whether to move the files before transmitting them.
-
m_AtomicMove
protected boolean m_AtomicMove
whether to perform an atomic move.
-
m_Target
protected PlaceholderDirectory m_Target
the directory to move the files to.
-
m_WatchedDir
protected transient Path m_WatchedDir
the watched directory.
-
m_Watch
protected transient WatchService m_Watch
the watch service.
-
m_Runnable
protected transient RunnableWithLogging m_Runnable
waits for events.
-
-
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 classAbstractMutableActorDaemonEvent<WatchKey,String[]>
-
reset
protected void reset()
Resets the scheme.- Overrides:
reset
in classAbstractActor
-
setSource
public void setSource(PlaceholderDirectory value)
Sets the incoming directory.- Parameters:
value
- the incoming directory
-
getSource
public PlaceholderDirectory getSource()
Returns the incoming directory.- Returns:
- the incoming directory.
-
sourceTipText
public String sourceTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setEvents
public void setEvents(WatchEventKind[] value)
Sets the events to report.- Parameters:
value
- the events
-
getEvents
public WatchEventKind[] getEvents()
Returns the events to report.- Returns:
- the events
-
eventsTipText
public String eventsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setWaitPoll
public void setWaitPoll(int value)
Sets the number of milli-seconds to wait before polling whether files have arrived.- Parameters:
value
- the number of milli-seconds
-
getWaitPoll
public int getWaitPoll()
Returns the number of milli-seconds to wait before polling again whether files have arrived.- Returns:
- the number of milli-seconds
-
waitPollTipText
public String waitPollTipText()
Returns the tip text for this property. VariableChangedEvent.java- 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 to match the filenames against (name only, not path).- Parameters:
value
- the expression
-
getRegExp
public BaseRegExp getRegExp()
Returns the regular expression to match the filenames against (name only, not path).- Returns:
- the 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.
-
setMoveFiles
public void setMoveFiles(boolean value)
Sets whether to move the files to the specified target directory before transmitting them.- Parameters:
value
- true if to move files
-
getMoveFiles
public boolean getMoveFiles()
Returns whether to move the files to the specified target directory before transmitting them.- Returns:
- true if to move files
-
moveFilesTipText
public String moveFilesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setAtomicMove
public void setAtomicMove(boolean value)
Sets whether to attempt atomic move operation.- Specified by:
setAtomicMove
in interfaceAtomicMoveSupporter
- Parameters:
value
- if true then attempt atomic move operation
-
getAtomicMove
public boolean getAtomicMove()
Returns whether to attempt atomic move operation.- Specified by:
getAtomicMove
in interfaceAtomicMoveSupporter
- Returns:
- true if to attempt atomic move operation
-
atomicMoveTipText
public String atomicMoveTipText()
Returns the tip text for this property.- Specified by:
atomicMoveTipText
in interfaceAtomicMoveSupporter
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setTarget
public void setTarget(PlaceholderDirectory value)
Sets the move-to directory.- Parameters:
value
- the move-to directory
-
getTarget
public PlaceholderDirectory getTarget()
Returns the move-to directory.- Returns:
- the move-to directory.
-
targetTipText
public String targetTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
check
public String check()
Hook method for performing checks. Makes sure that directories exist.- Specified by:
check
in interfaceActorHandler
- Overrides:
check
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
- Returns:
- null if everything OK, otherwise error message
-
checkActors
protected String checkActors(Actor[] actors)
Checks the actors before they are set via the setActors method. Returns an error message if the actors are not acceptable, null otherwise.- Specified by:
checkActors
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
- Parameters:
actors
- the actors to check- Returns:
- null if accepted, otherwise error message
-
handlesEvent
protected boolean handlesEvent(WatchKey e)
Checks whether the event is being handled.- Specified by:
handlesEvent
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
- Parameters:
e
- the event to check- Returns:
- true if being handled
-
preProcessEvent
protected String[] preProcessEvent(WatchKey key)
Preprocesses the event.- Specified by:
preProcessEvent
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
- Parameters:
key
- the event to preprocess- Returns:
- the output of the preprocessing
-
usePreProcessedAsInput
protected boolean usePreProcessedAsInput()
Returns whether the preprocessed event is used as input token.- Specified by:
usePreProcessedAsInput
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
- Returns:
- always false
-
doExecute
protected String doExecute()
Executes the flow item.- Overrides:
doExecute
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
- Returns:
- null if successful, otherwise error message
-
stopWatchService
protected void stopWatchService()
Stops the watch service, if active.
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecution
in interfaceActor
- Specified by:
stopExecution
in interfaceStoppable
- Overrides:
stopExecution
in classAbstractMutableActorDaemonEvent<WatchKey,String[]>
-
-