AbstractProcess
is a abstract helper class to implement processes.
Most of the functionalities of Process are served well within
AbstractProcess
. Because of the situation that most processes are
simple executions AbstractProcess
allows easy implementations of
Process.
To use the advantage of AbstractProcess
simple extend it and
implement the run method.
It executes run at start and handles the exeuction of events and the correct states. If you wan't to stop your process pause and resume offer direct support.
Example for a process that can not be finished by return:
class MyProcess extends AbstractProcess {
public function run() {
// Xml that has to work
var xml:Xml = new Xml();
// helper for the call back.
var inst = this;
// Mtasc compatible return from loading
xml.onLoad = function() {
inst["finish"]();
}
// Flag to not finish automatically
working = true;
// Start of loading the xml file.
xml.load("test.xml");
}
}
public function setParentProcess(p:Process):Void
Setter for a parent process.
Validates if the passed-in Process
is this instance or has
this instance in its parent hierarchy (to prevent recursions).
p | Process to act as parent
|
IllegalArgumentException | if the applied process has the current instance in its parent hierarchy or it is the current instance |
public function getParentProcess(Void):Process
Returns the Process
that acts as parent for this process.
parent Process
if set, else null
public function startSubProcess(process:Process, args:Array, callBack:Executable):Void
Starts a sub-process.
This method allows to start a Process
. It registers itself as
parent of the passed-in process
and starts the process
if necessary.
If you add a sub-process it will be started immediately. This is important if you start more than one sub-process, because they won't get executed in a row like its handled within a Batch.
This process will not be finished until all subprocesses have finished.
On finish of the process
to start it will execute the passed-in
callBack
.
process | process to be used as sub-process |
args | arguments for the process start |
callBack | call back to be executed if the process finishes |
public function start()
Starts the process.
Any applied parameter will be passed to the run implementation.
(optional) result of run()
public function isPaused(Void):Boolean
Returns true
if the process is paused.
true
if the process is paused
public function isRunning(Void):Boolean
Returns true
if the process is running.
true
if the process is running
public function onProcessFinish(process:Process):Void
Method to be executed if a process finishes its execution.
process | Process that finished with execution |
onProcessFinish() in org.as2lib.app.exec.ProcessFinishListener
public function onProcessError(process:Process, error):Boolean
Method to be executed if a exception was thrown during the execution.
process | Process where a error occured |
error | error that occured |
true
if error was consumed
onProcessError() in org.as2lib.app.exec.ProcessErrorListener
public function hasError(Void):Boolean
Returns true
if a error occured.
true
if a error occured