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 String
BACKUP_OUTPUTPROCESSOR_STDERR
the key for storing the stderr output processor.static String
BACKUP_OUTPUTPROCESSOR_STDOUT
the key for storing the stdout output processor.static String
BACKUP_PROCESS
the key for storing the process in the backup.static String
BACKUP_WRITER
the key for storing the writer in the backup.protected BaseText
m_Command
the command to run.protected ConversionToString
m_Conversion
the conversion scheme to turn the input into strings.protected String
m_Delimiter
the string to forward to the process after each token.protected BaseKeyValuePair[]
m_EnvVars
environment variables.protected String
m_FinishedSignal
the string to signal the process that flow has finished.protected Process
m_Process
the process to pipe the data in.protected OutputProcessStream
m_Stderr
for outputting stderr of the process.protected OutputProcessStream
m_Stdout
for outputting stdout of the process.protected String
m_WorkingDirectory
the current working directory.protected BufferedWriter
m_Writer
for 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.String
commandTipText()
Returns the tip text for this property.String
conversionTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.String
delimiterTipText()
Returns the tip text for this property.protected String
doExecute()
Executes the flow item.String
envVarsTipText()
Returns the tip text for this property.String
finishedSignalTipText()
Returns the tip text for this property.protected String
getActualFinishedSignal()
Returns the "end of execution" signal string to send to the process.BaseText
getCommand()
Returns the command to run.ConversionToString
getConversion()
Returns the conversion to apply to the input.String
getDelimiter()
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.String
getFinishedSignal()
Returns the string to signal the process the end of flow execution.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.String
getWorkingDirectory()
Returns the current working directory for the command.String
globalInfo()
Returns a string describing the object.protected void
pruneBackup()
Removes entries from the backup.protected void
restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.void
setCommand(BaseText value)
Sets the command to run.void
setConversion(ConversionToString value)
Sets the conversion to apply to the input.void
setDelimiter(String value)
Sets the delimiter to write to forward to the process after each token.void
setEnvVars(BaseKeyValuePair[] value)
Sets the environment variables to overlay on top of the current ones.void
setFinishedSignal(String value)
Sets the string to send to the process when the flow finishes.void
setWorkingDirectory(String value)
Sets the current working directory for the command.String
workingDirectoryTipText()
Returns the tip text for this property.void
wrapUp()
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:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- 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 interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in 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:
backupState
in 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:
restoreState
in 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:
pruneBackup
in 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:
setWorkingDirectory
in interfaceWorkingDirectoryHandler
- Parameters:
value
- the directory, ignored if empty
-
getWorkingDirectory
public String getWorkingDirectory()
Returns the current working directory for the command.- Specified by:
getWorkingDirectory
in interfaceWorkingDirectoryHandler
- Returns:
- the directory, ignored if empty
-
workingDirectoryTipText
public String workingDirectoryTipText()
Returns the tip text for this property.- Specified by:
workingDirectoryTipText
in 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:
setEnvVars
in interfaceEnvironmentVariablesHandler
- Parameters:
value
- the environment variables
-
getEnvVars
public BaseKeyValuePair[] getEnvVars()
Returns the environment variables to overlay on top of the current ones.- Specified by:
getEnvVars
in interfaceEnvironmentVariablesHandler
- Returns:
- the environment variables
-
envVarsTipText
public String envVarsTipText()
Returns the tip text for this property.- Specified by:
envVarsTipText
in 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:
accepts
in interfaceInputConsumer
- Returns:
- the Class of objects that can be processed
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in 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:
wrapUp
in interfaceActor
- Overrides:
wrapUp
in classAbstractSink
-
-