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 booleanm_AtomicMovewhether to perform an atomic move.protected WatchEventKind[]m_Eventsthe events to look for.protected booleanm_MoveFileswhether to move the files before transmitting them.protected BaseRegExpm_RegExpthe regular expression to match the file names against.protected RunnableWithLoggingm_Runnablewaits for events.protected PlaceholderDirectorym_Sourcethe directory to watch.protected PlaceholderDirectorym_Targetthe directory to move the files to.protected intm_WaitPollthe waiting period in msec before polling again.protected WatchServicem_Watchthe watch service.protected Pathm_WatchedDirthe 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 StringatomicMoveTipText()Returns the tip text for this property.Stringcheck()Hook method for performing checks.protected StringcheckActors(Actor[] actors)Checks the actors before they are set via the setActors method.voiddefineOptions()Adds options to the internal list of options.protected StringdoExecute()Executes the flow item.StringeventsTipText()Returns the tip text for this property.booleangetAtomicMove()Returns whether to attempt atomic move operation.WatchEventKind[]getEvents()Returns the events to report.booleangetMoveFiles()Returns whether to move the files to the specified target directory before transmitting them.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.BaseRegExpgetRegExp()Returns the regular expression to match the filenames against (name only, not path).PlaceholderDirectorygetSource()Returns the incoming directory.PlaceholderDirectorygetTarget()Returns the move-to directory.intgetWaitPoll()Returns the number of milli-seconds to wait before polling again whether files have arrived.StringglobalInfo()Returns a string describing the object.protected booleanhandlesEvent(WatchKey e)Checks whether the event is being handled.StringmoveFilesTipText()Returns the tip text for this property.protected String[]preProcessEvent(WatchKey key)Preprocesses the event.StringregExpTipText()Returns the tip text for this property.protected voidreset()Resets the scheme.voidsetAtomicMove(boolean value)Sets whether to attempt atomic move operation.voidsetEvents(WatchEventKind[] value)Sets the events to report.voidsetMoveFiles(boolean value)Sets whether to move the files to the specified target directory before transmitting them.voidsetRegExp(BaseRegExp value)Sets the regular expression to match the filenames against (name only, not path).voidsetSource(PlaceholderDirectory value)Sets the incoming directory.voidsetTarget(PlaceholderDirectory value)Sets the move-to directory.voidsetWaitPoll(int value)Sets the number of milli-seconds to wait before polling whether files have arrived.StringsourceTipText()Returns the tip text for this property.voidstopExecution()Stops the execution.protected voidstopWatchService()Stops the watch service, if active.StringtargetTipText()Returns the tip text for this property.protected booleanusePreProcessedAsInput()Returns whether the preprocessed event is used as input token.StringwaitPollTipText()Returns the tip text for this property.voidwrapUp()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:
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 classAbstractMutableActorDaemonEvent<WatchKey,String[]>
-
reset
protected void reset()
Resets the scheme.- Overrides:
resetin 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:
setAtomicMovein interfaceAtomicMoveSupporter- Parameters:
value- if true then attempt atomic move operation
-
getAtomicMove
public boolean getAtomicMove()
Returns whether to attempt atomic move operation.- Specified by:
getAtomicMovein interfaceAtomicMoveSupporter- Returns:
- true if to attempt atomic move operation
-
atomicMoveTipText
public String atomicMoveTipText()
Returns the tip text for this property.- Specified by:
atomicMoveTipTextin 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:
getQuickInfoin interfaceActor- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin 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:
checkin interfaceActorHandler- Overrides:
checkin 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:
checkActorsin 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:
handlesEventin 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:
preProcessEventin 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:
usePreProcessedAsInputin classAbstractMutableActorDaemonEvent<WatchKey,String[]>- Returns:
- always false
-
doExecute
protected String doExecute()
Executes the flow item.- Overrides:
doExecutein 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:
stopExecutionin interfaceActor- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractMutableActorDaemonEvent<WatchKey,String[]>
-
-