Package adams.flow.sink
Class Exec
-
- All Implemented Interfaces:
AdditionalInformationHandler,CleanUpHandler,Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,EnvironmentVariablesHandler,WorkingDirectoryHandler,OptionHandler,QuickInfoSupporter,ShallowCopySupporter<Actor>,SizeOfHandler,Stoppable,StoppableWithFeedback,VariablesInspectionHandler,VariableChangeListener,Actor,ErrorHandler,InputConsumer,Serializable,Comparable
public class Exec extends AbstractSink implements EnvironmentVariablesHandler, WorkingDirectoryHandler
Pipes the incoming data, after converting it using the provided conversion scheme, into the started process.
Input/output:
- accepts:
adams.flow.core.Unknown
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-name <java.lang.String> (property: name) The name of the actor. default: Exec
-annotation <adams.core.base.BaseAnnotation> (property: annotations) The annotations to attach to this actor. default:
-skip <boolean> (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is. default: false
-stop-flow-on-error <boolean> (property: stopFlowOnError) If set to true, the flow execution at this level gets stopped in case this actor encounters an error; the error gets propagated; useful for critical actors. default: false
-silent <boolean> (property: silent) If enabled, then no errors are output in the console; Note: the enclosing actor handler must have this enabled as well. default: false
-cmd <adams.core.base.BaseText> (property: command) The external command to pipe the data into. default: mysql test
-working-directory <java.lang.String> (property: workingDirectory) The current working directory for the command. default:
-env-var <adams.core.base.BaseKeyValuePair> [-env-var ...] (property: envVars) The environment variables to overlay on top of the current ones. default:
-conversion <adams.data.conversion.ConversionToString> (property: conversion) The conversion scheme to apply to the input tokens. default: adams.data.conversion.AnyToString
-delimiter <java.lang.String> (property: delimiter) The delimiter string to forward to the process after each token; uses backquoted strings, ie you can use \n for new line and \r for carriage return. default: \\n
-finished-signal <java.lang.String> (property: finishedSignal) The string to signal the process that the processing has finished; gets ignored if empty string; you can use \\uXXXX for unicode characters (with XXXX being a hexadecimal number), eg \\u001a for EOF. default:
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringBACKUP_OUTPUTPROCESSOR_STDERRthe key for storing the stderr output processor.static StringBACKUP_OUTPUTPROCESSOR_STDOUTthe key for storing the stdout output processor.static StringBACKUP_PROCESSthe key for storing the process in the backup.static StringBACKUP_WRITERthe key for storing the writer in the backup.protected BaseTextm_Commandthe command to run.protected ConversionToStringm_Conversionthe conversion scheme to turn the input into strings.protected Stringm_Delimiterthe string to forward to the process after each token.protected BaseKeyValuePair[]m_EnvVarsenvironment variables.protected Stringm_FinishedSignalthe string to signal the process that flow has finished.protected Processm_Processthe process to pipe the data in.protected OutputProcessStreamm_Stderrfor outputting stderr of the process.protected OutputProcessStreamm_Stdoutfor outputting stdout of the process.protected Stringm_WorkingDirectorythe current working directory.protected BufferedWriterm_Writerfor writing to stdin of the process.-
Fields inherited from class adams.flow.sink.AbstractSink
BACKUP_INPUT, m_InputToken
-
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 Exec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]accepts()Returns the class that the consumer accepts.protected Hashtable<String,Object>backupState()Backs up the current state of the actor before update the variables.StringcommandTipText()Returns the tip text for this property.StringconversionTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.StringdelimiterTipText()Returns the tip text for this property.protected StringdoExecute()Executes the flow item.StringenvVarsTipText()Returns the tip text for this property.StringfinishedSignalTipText()Returns the tip text for this property.protected StringgetActualFinishedSignal()Returns the "end of execution" signal string to send to the process.BaseTextgetCommand()Returns the command to run.ConversionToStringgetConversion()Returns the conversion to apply to the input.StringgetDelimiter()Returns the delimiter to write to the process after each token.BaseKeyValuePair[]getEnvVars()Returns the environment variables to overlay on top of the current ones.StringgetFinishedSignal()Returns the string to signal the process the end of flow execution.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.StringgetWorkingDirectory()Returns the current working directory for the command.StringglobalInfo()Returns a string describing the object.protected voidpruneBackup()Removes entries from the backup.protected voidrestoreState(Hashtable<String,Object> state)Restores the state of the actor before the variables got updated.voidsetCommand(BaseText value)Sets the command to run.voidsetConversion(ConversionToString value)Sets the conversion to apply to the input.voidsetDelimiter(String value)Sets the delimiter to write to forward to the process after each token.voidsetEnvVars(BaseKeyValuePair[] value)Sets the environment variables to overlay on top of the current ones.voidsetFinishedSignal(String value)Sets the string to send to the process when the flow finishes.voidsetWorkingDirectory(String value)Sets the current working directory for the command.StringworkingDirectoryTipText()Returns the tip text for this property.voidwrapUp()Cleans up after the execution has finished.-
Methods inherited from class adams.flow.sink.AbstractSink
currentInput, hasInput, input, postExecute
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, 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, initialize, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, preExecute, pruneBackup, reset, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, 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, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, stopExecution, toCommandLine, variableChanged
-
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
-
BACKUP_PROCESS
public static final String BACKUP_PROCESS
the key for storing the process in the backup.- See Also:
- Constant Field Values
-
BACKUP_WRITER
public static final String BACKUP_WRITER
the key for storing the writer in the backup.- See Also:
- Constant Field Values
-
BACKUP_OUTPUTPROCESSOR_STDOUT
public static final String BACKUP_OUTPUTPROCESSOR_STDOUT
the key for storing the stdout output processor.- See Also:
- Constant Field Values
-
BACKUP_OUTPUTPROCESSOR_STDERR
public static final String BACKUP_OUTPUTPROCESSOR_STDERR
the key for storing the stderr output processor.- See Also:
- Constant Field Values
-
m_Command
protected BaseText m_Command
the command to run.
-
m_WorkingDirectory
protected String m_WorkingDirectory
the current working directory.
-
m_EnvVars
protected BaseKeyValuePair[] m_EnvVars
environment variables.
-
m_Conversion
protected ConversionToString m_Conversion
the conversion scheme to turn the input into strings.
-
m_Delimiter
protected String m_Delimiter
the string to forward to the process after each token.
-
m_FinishedSignal
protected String m_FinishedSignal
the string to signal the process that flow has finished.
-
m_Process
protected Process m_Process
the process to pipe the data in.
-
m_Writer
protected BufferedWriter m_Writer
for writing to stdin of the process.
-
m_Stdout
protected OutputProcessStream m_Stdout
for outputting stdout of the process.
-
m_Stderr
protected OutputProcessStream m_Stderr
for outputting stderr of the process.
-
-
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 classAbstractActor
-
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
-
backupState
protected Hashtable<String,Object> backupState()
Backs up the current state of the actor before update the variables.- Overrides:
backupStatein classAbstractSink- Returns:
- the backup
- See Also:
AbstractActor.updateVariables(),AbstractActor.restoreState(Hashtable)
-
restoreState
protected void restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.- Overrides:
restoreStatein classAbstractSink- Parameters:
state- the backup of the state to restore from- See Also:
AbstractActor.updateVariables(),AbstractActor.backupState()
-
pruneBackup
protected void pruneBackup()
Removes entries from the backup.- Overrides:
pruneBackupin classAbstractActor- See Also:
AbstractActor.reset()
-
setCommand
public void setCommand(BaseText value)
Sets the command to run.- Parameters:
value- the command
-
getCommand
public BaseText getCommand()
Returns the command to run.- Returns:
- the command
-
commandTipText
public String commandTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setWorkingDirectory
public void setWorkingDirectory(String value)
Sets the current working directory for the command.- Specified by:
setWorkingDirectoryin interfaceWorkingDirectoryHandler- Parameters:
value- the directory, ignored if empty
-
getWorkingDirectory
public String getWorkingDirectory()
Returns the current working directory for the command.- Specified by:
getWorkingDirectoryin interfaceWorkingDirectoryHandler- Returns:
- the directory, ignored if empty
-
workingDirectoryTipText
public String workingDirectoryTipText()
Returns the tip text for this property.- Specified by:
workingDirectoryTipTextin interfaceWorkingDirectoryHandler- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setEnvVars
public void setEnvVars(BaseKeyValuePair[] value)
Sets the environment variables to overlay on top of the current ones.- Specified by:
setEnvVarsin interfaceEnvironmentVariablesHandler- Parameters:
value- the environment variables
-
getEnvVars
public BaseKeyValuePair[] getEnvVars()
Returns the environment variables to overlay on top of the current ones.- Specified by:
getEnvVarsin interfaceEnvironmentVariablesHandler- Returns:
- the environment variables
-
envVarsTipText
public String envVarsTipText()
Returns the tip text for this property.- Specified by:
envVarsTipTextin interfaceEnvironmentVariablesHandler- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setConversion
public void setConversion(ConversionToString value)
Sets the conversion to apply to the input.- Parameters:
value- the conversion
-
getConversion
public ConversionToString getConversion()
Returns the conversion to apply to the input.- Returns:
- the conversion
-
conversionTipText
public String conversionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setDelimiter
public void setDelimiter(String value)
Sets the delimiter to write to forward to the process after each token. Uses a backquoted string.- Parameters:
value- the delimiter
-
getDelimiter
public String getDelimiter()
Returns the delimiter to write to the process after each token. Backquoted string.- Returns:
- the delimiter
-
delimiterTipText
public String delimiterTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setFinishedSignal
public void setFinishedSignal(String value)
Sets the string to send to the process when the flow finishes. Uses a backquoted string.- Parameters:
value- the signal string, ignored if empty string
-
getFinishedSignal
public String getFinishedSignal()
Returns the string to signal the process the end of flow execution. Backquoted string.- Returns:
- the signal string, ignored if empty string
-
finishedSignalTipText
public String finishedSignalTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getActualFinishedSignal
protected String getActualFinishedSignal()
Returns the "end of execution" signal string to send to the process. Processes any unicode characters.- Returns:
- the string
-
accepts
public Class[] accepts()
Returns the class that the consumer accepts.- Specified by:
acceptsin interfaceInputConsumer- Returns:
- the Class of objects that can be processed
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecutein classAbstractActor- Returns:
- null if everything is fine, otherwise error message
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished. Graphical output is left untouched.- Specified by:
wrapUpin interfaceActor- Overrides:
wrapUpin classAbstractSink
-
-