public abstract class AbstractOsProcessTask<C extends ApplicationContext> extends AbstractAsyncTask<C>
setNotifyConsoleOutput(boolean)
to enable doOnConsoleOutput(String)
being called for each output line.
setNotifyFileSystemChange(boolean)
to enable doOnFileSystemChange(ChangeType, File)
being called for each file system change discovered in the working directory.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
OUTPUT_TYPE_CONSOLE |
childTaskRef, isTestMode, monitorController, resultRef, stateFlag
Constructor and Description |
---|
AbstractOsProcessTask(C ctx,
LogChannel logCh,
java.lang.String taskName) |
AbstractOsProcessTask(C ctx,
LogChannel logCh,
java.lang.String taskName,
TaskType taskType) |
AbstractOsProcessTask(C ctx,
java.lang.String taskName) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Flags the task as being cancelled.
|
protected void |
checkExitStatus(int status)
Checks whether the process exit status is OK, a 0 is considered to be successful
|
protected java.io.InputStream |
createStandardInput()
May be overridden to provide an input stream that is passed to the process
via stdin (if for instance the process needs to read an input file).
|
protected java.io.PrintWriter |
createStandardOutput()
Create an output channel where the process console output is written to.
|
protected java.io.File |
createStandardOutputFile()
Creates a File in the process working directory for logging the process console output.
|
protected void |
doOnConsoleOutput(java.lang.String outputLine)
Is called whenever the OS-process prints an output line to the system console.
|
protected void |
doOnFileSystemChange(ChangeType changeType,
java.io.File file)
Is called whenever a file system change is discovered.
|
protected void |
doOnFinish()
Is called in ANY CASE when the task has finished.
|
void |
executeAsync()
Must be overridden to perform the async part.
|
java.lang.String |
getCommandBaseName()
Returns the first argument of the command string.
|
java.lang.String |
getCommandString() |
java.lang.ProcessBuilder |
getProcessBuilder() |
java.io.File |
getStandardOutputFile() |
java.io.File |
getWorkingDir() |
boolean |
isNotifyConsoleOutput()
Tells whether a progress should be sent for each process console output line.
|
void |
putEnv(java.lang.String key,
java.lang.String value) |
void |
setCommand(java.lang.String... command) |
void |
setNotifyConsoleOutput(boolean isNotify)
If set to true, then this task calls
doOnConsoleOutput(String) for text line which the OS-process
prints to the system console. |
void |
setNotifyFileSystemChange(boolean isNotify)
If set to true, then the process starts a watch-service on the working-directory in order
to detect file system changes.
|
void |
setStandardOutputFile(java.io.File standardOutputFile)
Sets the file to be used for standard output.
|
void |
setWorkingDir(java.io.File workingDir) |
TaskId |
submit()
Submits this task for execution to the default application thread pool
|
TaskId |
submit(java.util.concurrent.ExecutorService pool)
Submits this task for execution to the given thread pool
|
DumpString |
toDumpString(DumpString s)
This method allows subclasses to add values to the existing DumpString of the superclass.
|
awaitFinished, awaitFinished, awaitStarted, createTaskId, deregisterTask, doOnStart, doOnSuccess, executeChildTask, executeChildTask, getCurrentFuture, getMaxChildTasks, getPriority, getProcessingDuration, getStartTime, getStopWatch, handleFinish, handleStart, handleSuccess, isRegisterForCancel, isRunning, notifyProceeded, registerTask, releaseStart, run, setCurrentFuture, setMaxChildTasks, setPriority, setRegisterForCancel, setReleaseTimeout, submitInternal, toString, wasSucceeded
addMonitor, checkCancelled, checkForErrorAndRethrow, clearMonitors, createRunStateFlag, doOnCancel, doOnFailure, execute, executeSubTask, getError, getMaxProgressSteps, getMonitorCount, getMonitors, getName, getProgressStepCount, getResult, getRunStateFlag, getTaskId, getType, handleCancellation, handleFailure, hasError, hasMonitor, isCancellable, registerTaskStateChange, removeMonitor, resetProgress, setCancellable, setLogLevel, setMaxProgressSteps, setMonitor, setName, setName, setResult, setRunStateFlag, setTaskId, setType, shouldFireMonitor, sleepChecked, wasCancelled
getApplicationContext, getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel
configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
checkCancelled, checkForErrorAndRethrow, executeSubTask, getName, getResult, getRunStateFlag, getTaskId, getType, handleCancellation, handleFailure, isCancellable, setCancellable, setName, setResult, setRunStateFlag, sleepChecked
getApplicationContext
execute
addMonitor, clearMonitors, getMonitorCount, getMonitors, hasMonitor, removeMonitor
getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel
wasCancelled
getTaskId
toDumpString, toString
public static final java.lang.String OUTPUT_TYPE_CONSOLE
public AbstractOsProcessTask(C ctx, java.lang.String taskName)
public AbstractOsProcessTask(C ctx, LogChannel logCh, java.lang.String taskName)
public AbstractOsProcessTask(C ctx, LogChannel logCh, java.lang.String taskName, TaskType taskType)
public TaskId submit() throws java.lang.Exception
AsyncTask
submit
in interface AsyncTask<C extends ApplicationContext>
submit
in class AbstractAsyncTask<C extends ApplicationContext>
java.lang.Exception
- if the pool is busypublic TaskId submit(java.util.concurrent.ExecutorService pool) throws java.lang.Exception
AsyncTask
submit
in interface AsyncTask<C extends ApplicationContext>
submit
in class AbstractAsyncTask<C extends ApplicationContext>
java.lang.Exception
- if the pool is busypublic void setNotifyFileSystemChange(boolean isNotify)
public final void setNotifyConsoleOutput(boolean isNotify)
doOnConsoleOutput(String)
for text line which the OS-process
prints to the system console.public final boolean isNotifyConsoleOutput()
public final void setWorkingDir(java.io.File workingDir)
public final java.io.File getWorkingDir()
public final void setCommand(java.lang.String... command)
public java.lang.String getCommandString()
public final java.lang.String getCommandBaseName()
public final java.lang.ProcessBuilder getProcessBuilder()
public final void putEnv(java.lang.String key, java.lang.String value)
public void executeAsync() throws java.lang.Exception
AbstractAsyncTask
AbstractAsyncTask.notifyProceeded(Object, int, int, String)
in order to notify
about task progress. Note: the running task should periodically call
AbstractAsyncExecutable.checkCancelled()
in order to detect cancellation.executeAsync
in interface AsyncExecutable<C extends ApplicationContext>
executeAsync
in class AbstractAsyncTask<C extends ApplicationContext>
java.lang.Exception
for synchronous execution
protected void doOnFinish()
AbstractAsyncTask
doOnFinish
in class AbstractAsyncTask<C extends ApplicationContext>
protected void doOnConsoleOutput(java.lang.String outputLine) throws java.lang.Exception
java.lang.Exception
setNotifyConsoleOutput(boolean)
protected void doOnFileSystemChange(ChangeType changeType, java.io.File file)
setNotifyFileSystemChange(boolean)
protected void checkExitStatus(int status) throws ErroneousExitStatusException
ErroneousExitStatusException
public final java.io.File getStandardOutputFile()
public void setStandardOutputFile(java.io.File standardOutputFile)
standardOutputFile
- the standardOutputFile to setprotected java.io.InputStream createStandardInput() throws java.lang.Exception
java.lang.Exception
protected java.io.PrintWriter createStandardOutput() throws java.lang.Exception
createStandardOutputFile()
.java.lang.Exception
protected java.io.File createStandardOutputFile()
proc__.log
.
May be overridden to provide a different output filename. If null is returned, then
the output is not written to a file.public void cancel()
AbstractAsyncTask
AbstractAsyncExecutable.checkCancelled()
will
result a CancellationException
being thrown. As a result
AbstractAsyncExecutable.doOnCancel()
is being called on the task.cancel
in interface LocalCancellableTask
cancel
in class AbstractAsyncTask<C extends ApplicationContext>
public DumpString toDumpString(DumpString s)
Dumpable
toDumpString
in interface Dumpable
toDumpString
in class DumpableObject
Copyright © 2014 EsprIT-Systems. All Rights Reserved.