Class AbstractProcessRunnable
- java.lang.Object
-
- com.github.fracpete.processoutput4j.core.AbstractProcessRunnable
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
AbstractProcessReader
public abstract class AbstractProcessRunnable extends java.lang.Object implements java.lang.RunnableAncestor for runnables that use aProcessobject.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description protected ErrorLoggerm_ErrorLoggerthe error logger.protected intm_PollIntervalthe polling timeout interval in milliseconds.protected java.lang.Processm_Processthe process to read from.protected java.util.concurrent.BlockingQueue<java.lang.Process>m_Queuethe blocking queue for the process.protected booleanm_Runningwhether the runnable is still active.protected booleanm_Stoppedwhether the reader got stopped.
-
Constructor Summary
Constructors Constructor Description AbstractProcessRunnable()Initializes the runnable.AbstractProcessRunnable(int pollInterval, ErrorLogger errorLogger)Initializes the runnable.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voiddoRun()The actual processing loop.java.lang.ProcessgetProcess()Returns the underlyingProcessobject.booleanisRunning()Returns whether the runnable is still active.booleanisStopped()Returns whether execution got stopped.protected voidlogError(java.lang.String msg)Just outputs the message on stderr.protected voidlogError(java.lang.String msg, java.lang.Throwable t)Just outputs message and throwable on stderr.voidrun()Reads the data from the process.voidsetProcess(java.lang.Process value)Sets the process to monitor.voidstopExecution()Stops the execution.
-
-
-
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 outputerrorLogger- 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 underlyingProcessobject.- 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 outputt- the exception
-
doRun
protected abstract void doRun()
The actual processing loop.
-
run
public void run()
Reads the data from the process.- Specified by:
runin interfacejava.lang.Runnable
-
-