Package adams.flow.source
Class AbstractPythonExecution
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.flow.core.AbstractActor
-
- adams.flow.source.AbstractSource
-
- adams.flow.source.AbstractPythonExecution
-
- All Implemented Interfaces:
AdditionalInformationHandler,CleanUpHandler,Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,QuickInfoSupporter,ShallowCopySupporter<Actor>,SizeOfHandler,Stoppable,StoppableWithFeedback,VariablesInspectionHandler,VariableChangeListener,Actor,ErrorHandler,OutputProducer,com.github.fracpete.processoutput4j.core.StreamingProcessOwner,Serializable,Comparable
- Direct Known Subclasses:
PipExec,PythonExec,PythonVenvExec
public abstract class AbstractPythonExecution extends AbstractSource implements com.github.fracpete.processoutput4j.core.StreamingProcessOwner
Ancestor for sources that execute a Python executable.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PythonEnvironmentm_Environmentthe environment in use.protected IllegalStateExceptionm_ExecutionFailurein case an exception occurred executing the command (gets rethrown).protected RunnableWithLoggingm_Monitorthe runnable executing the command.protected Listm_Outputthe tokens to forward.protected com.github.fracpete.processoutput4j.core.StreamingProcessOutputTypem_OutputTypewhether to output stderr instead of stdout or both.protected Stringm_PrefixStdErrthe stderr prefix.protected Stringm_PrefixStdOutthe stdout prefix.protected com.github.fracpete.processoutput4j.output.StreamingProcessOutputm_ProcessOutputthe process monitor.protected intm_TimeOutthe time out in seconds.-
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 AbstractPythonExecution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddefineOptions()Adds options to the internal list of options.Class[]generates()Returns the class of objects that it generates.com.github.fracpete.processoutput4j.core.StreamingProcessOutputTypegetOutputType()Returns what output from the process to forward.StringgetPrefixStdErr()Returns the (optional) prefix to use for output from stderr.StringgetPrefixStdOut()Returns the (optional) prefix to use for output from stdout.intgetTimeOut()Returns the time out for the process.booleanhasPendingOutput()Checks whether there is pending output to be collected after executing the flow item.protected voidinitialize()Initializes the members.protected Stringlaunch(List<String> cmd, String workingDir)Launches the command.Tokenoutput()Returns the generated token.StringoutputTypeTipText()Returns the tip text for this property.StringprefixStdErrTipText()Returns the tip text for this property.StringprefixStdOutTipText()Returns the tip text for this property.voidprocessOutput(String line, boolean stdout)Adds the line from the output to the internal list of lines to output.protected voidreset()Resets the scheme.voidsetOutputType(com.github.fracpete.processoutput4j.core.StreamingProcessOutputType value)Sets what output from the process to forward.voidsetPrefixStdErr(String value)Sets the (optional) prefix to use for output from stderr.voidsetPrefixStdOut(String value)Sets the (optional) prefix to use for output from stdout.voidsetTimeOut(int value)Sets the time out for the process.StringsetUp()Initializes the item for flow execution.voidstopExecution()Stops the execution.StringtimeOutTipText()Returns the tip text for this property.-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, doExecute, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getQuickInfo, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, preExecute, pruneBackup, pruneBackup, restoreState, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged, wrapUp
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, setLoggingLevel, 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
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getQuickInfo, 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, wrapUp
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
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_OutputType
protected com.github.fracpete.processoutput4j.core.StreamingProcessOutputType m_OutputType
whether to output stderr instead of stdout or both.
-
m_PrefixStdOut
protected String m_PrefixStdOut
the stdout prefix.
-
m_PrefixStdErr
protected String m_PrefixStdErr
the stderr prefix.
-
m_Output
protected List m_Output
the tokens to forward.
-
m_ProcessOutput
protected transient com.github.fracpete.processoutput4j.output.StreamingProcessOutput m_ProcessOutput
the process monitor.
-
m_Monitor
protected RunnableWithLogging m_Monitor
the runnable executing the command.
-
m_ExecutionFailure
protected IllegalStateException m_ExecutionFailure
in case an exception occurred executing the command (gets rethrown).
-
m_TimeOut
protected int m_TimeOut
the time out in seconds.
-
m_Environment
protected PythonEnvironment m_Environment
the environment in use.
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractActor
-
reset
protected void reset()
Resets the scheme.- Overrides:
resetin classAbstractActor
-
setOutputType
public void setOutputType(com.github.fracpete.processoutput4j.core.StreamingProcessOutputType value)
Sets what output from the process to forward.- Parameters:
value- the output type
-
getOutputType
public com.github.fracpete.processoutput4j.core.StreamingProcessOutputType getOutputType()
Returns what output from the process to forward.- Specified by:
getOutputTypein interfacecom.github.fracpete.processoutput4j.core.StreamingProcessOwner- Returns:
- the output type
-
outputTypeTipText
public String outputTypeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPrefixStdOut
public void setPrefixStdOut(String value)
Sets the (optional) prefix to use for output from stdout.- Parameters:
value- the prefix
-
getPrefixStdOut
public String getPrefixStdOut()
Returns the (optional) prefix to use for output from stdout.- Returns:
- the prefix
-
prefixStdOutTipText
public String prefixStdOutTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPrefixStdErr
public void setPrefixStdErr(String value)
Sets the (optional) prefix to use for output from stderr.- Parameters:
value- the prefix
-
getPrefixStdErr
public String getPrefixStdErr()
Returns the (optional) prefix to use for output from stderr.- Returns:
- the prefix
-
prefixStdErrTipText
public String prefixStdErrTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setTimeOut
public void setTimeOut(int value)
Sets the time out for the process.- Parameters:
value- the time out in seconds
-
getTimeOut
public int getTimeOut()
Returns the time out for the process.- Returns:
- the time out in seconds
-
timeOutTipText
public String timeOutTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Specified by:
generatesin interfaceOutputProducer- Returns:
- java.lang.String.class
-
setUp
public String setUp()
Initializes the item for flow execution.- Specified by:
setUpin interfaceActor- Overrides:
setUpin classAbstractActor- Returns:
- null if everything is fine, otherwise error message
- See Also:
AbstractActor.reset()
-
launch
protected String launch(List<String> cmd, String workingDir)
Launches the command.- Parameters:
cmd- the command and its optionsworkingDir- the working directory, ignored if empty- Returns:
- null if everything is fine, otherwise error message
-
processOutput
public void processOutput(String line, boolean stdout)
Adds the line from the output to the internal list of lines to output.- Specified by:
processOutputin interfacecom.github.fracpete.processoutput4j.core.StreamingProcessOwner- Parameters:
line- the line to addstdout- whether stdout or stderr
-
output
public Token output()
Returns the generated token.- Specified by:
outputin interfaceOutputProducer- Returns:
- the generated token
-
hasPendingOutput
public boolean hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.- Specified by:
hasPendingOutputin interfaceOutputProducer- Returns:
- true if there is pending output
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecutionin interfaceActor- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractActor
-
-