Class DirWatch

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.AtomicMoveSupporter, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<AbstractRatInput>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, RatInput, Serializable

    public class DirWatch
    extends AbstractRatInput
    implements adams.core.AtomicMoveSupporter
    Watches for file changes in a directory and forwards the affected files.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -source <adams.core.io.PlaceholderDirectory> (property: source)
        The directory to watch.
        default: ${CWD}
     
    -event <CREATE|MODIFY|DELETE> [-event ...] (property: events)
        The kind of events to report.
        default: CREATE
     
    -wait-poll <int> (property: waitPoll)
        The number of milli-seconds to wait before polling again whether files have 
        arrived.
        default: 50
        minimum: 0
     
    -wait-list <int> (property: waitList)
        The number of milli-seconds to wait after listing the files.
        default: 0
        minimum: 0
     
    -move-files <boolean> (property: moveFiles)
        If enabled, the files get moved to the specified directory first before 
        being transmitted (with their new filename).
        default: false
     
    -atomic-move <boolean> (property: atomicMove)
        If true, then an atomic move operation will be attempted (NB: not supported 
        by all operating systems).
        default: false
     
    -target <adams.core.io.PlaceholderDirectory> (property: target)
        The directory to move the files to before transmitting their names.
        default: ${CWD}
     
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Source

        protected adams.core.io.PlaceholderDirectory m_Source
        the directory to watch.
      • m_Events

        protected adams.core.io.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 adams.core.base.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 adams.core.io.PlaceholderDirectory m_Target
        the directory to move the files to.
      • m_Files

        protected List<String> m_Files
        the files that were picked up by the watch service.
      • m_Watch

        protected transient WatchService m_Watch
        the watch service.
    • Constructor Detail

      • DirWatch

        public DirWatch()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        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 interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class adams.core.option.AbstractOptionHandler
      • setSource

        public void setSource​(adams.core.io.PlaceholderDirectory value)
        Sets the incoming directory.
        Parameters:
        value - the incoming directory
      • getSource

        public adams.core.io.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​(adams.core.io.WatchEventKind[] value)
        Sets the events to report.
        Parameters:
        value - the events
      • getEvents

        public adams.core.io.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.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setRegExp

        public void setRegExp​(adams.core.base.BaseRegExp value)
        Sets the regular expression to match the filenames against (name only, not path).
        Parameters:
        value - the expression
      • getRegExp

        public adams.core.base.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 interface adams.core.AtomicMoveSupporter
        Parameters:
        value - if true then attempt atomic move operation
      • getAtomicMove

        public boolean getAtomicMove()
        Returns whether to attempt atomic move operation.
        Specified by:
        getAtomicMove in interface adams.core.AtomicMoveSupporter
        Returns:
        true if to attempt atomic move operation
      • atomicMoveTipText

        public String atomicMoveTipText()
        Returns the tip text for this property.
        Specified by:
        atomicMoveTipText in interface adams.core.AtomicMoveSupporter
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTarget

        public void setTarget​(adams.core.io.PlaceholderDirectory value)
        Sets the move-to directory.
        Parameters:
        value - the move-to directory
      • getTarget

        public adams.core.io.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 interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class AbstractRatInput
        Returns:
        null if no info available, otherwise short string
      • check

        public String check()
        Hook method for performing checks. Makes sure that directories exist.
        Overrides:
        check in class AbstractRatInput
        Returns:
        null if successful, otherwise error message
      • doReceive

        protected String doReceive()
        Performs the actual reception of data.
        Specified by:
        doReceive in class AbstractRatInput
        Returns:
        null if successful, otherwise error message
      • stopWatchService

        protected void stopWatchService()
        Stops the watch service, if active.