Class AbstractProcessRunnable

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    AbstractProcessReader

    public abstract class AbstractProcessRunnable
    extends java.lang.Object
    implements java.lang.Runnable
    Ancestor for runnables that use a Process object.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ErrorLogger m_ErrorLogger
      the error logger.
      protected int m_PollInterval
      the polling timeout interval in milliseconds.
      protected java.lang.Process m_Process
      the process to read from.
      protected java.util.concurrent.BlockingQueue<java.lang.Process> m_Queue
      the blocking queue for the process.
      protected boolean m_Running
      whether the runnable is still active.
      protected boolean m_Stopped
      whether the reader got stopped.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void doRun()
      The actual processing loop.
      java.lang.Process getProcess()
      Returns the underlying Process object.
      boolean isRunning()
      Returns whether the runnable is still active.
      boolean isStopped()
      Returns whether execution got stopped.
      protected void logError​(java.lang.String msg)
      Just outputs the message on stderr.
      protected void logError​(java.lang.String msg, java.lang.Throwable t)
      Just outputs message and throwable on stderr.
      void run()
      Reads the data from the process.
      void setProcess​(java.lang.Process value)
      Sets the process to monitor.
      void stopExecution()
      Stops the execution.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_PollInterval

        protected int m_PollInterval
        the polling timeout interval in milliseconds.
      • m_ErrorLogger

        protected ErrorLogger m_ErrorLogger
        the error logger.
      • m_Queue

        protected java.util.concurrent.BlockingQueue<java.lang.Process> m_Queue
        the blocking queue for the process.
      • m_Process

        protected java.lang.Process m_Process
        the process to read from.
      • m_Running

        protected boolean m_Running
        whether the runnable is still active.
      • m_Stopped

        protected boolean m_Stopped
        whether the reader got stopped.
    • Constructor Detail

      • AbstractProcessRunnable

        public AbstractProcessRunnable()
        Initializes the runnable.
      • AbstractProcessRunnable

        public AbstractProcessRunnable​(int pollInterval,
                                       ErrorLogger errorLogger)
        Initializes the runnable.
        Parameters:
        pollInterval - the timeout interval in milliseconds to use when polling for new output
        errorLogger - the error logger to use
    • Method Detail

      • stopExecution

        public void stopExecution()
        Stops the execution.
      • isStopped

        public boolean isStopped()
        Returns whether execution got stopped.
        Returns:
        true if stopped
      • isRunning

        public boolean isRunning()
        Returns whether the runnable is still active.
        Returns:
        true if active
      • setProcess

        public void setProcess​(java.lang.Process value)
        Sets the process to monitor.
        Parameters:
        value - the process object
      • getProcess

        public java.lang.Process getProcess()
        Returns the underlying Process object.
        Returns:
        the process object, null if none set
      • logError

        protected void logError​(java.lang.String msg)
        Just outputs the message on stderr.
        Parameters:
        msg - the message to output
      • logError

        protected void logError​(java.lang.String msg,
                                java.lang.Throwable t)
        Just outputs message and throwable on stderr.
        Parameters:
        msg - the message to output
        t - the exception
      • doRun

        protected abstract void doRun()
        The actual processing loop.
      • run

        public void run()
        Reads the data from the process.
        Specified by:
        run in interface java.lang.Runnable