public abstract class Operation
extends com.sodius.mdw.internal.core.operations.InternalOperation
Operation
is a block of code that is executed and monitored by
an OperationRunner
.
An Operation
has an associated status that enables to monitor the execution state of the operation
and to query the execution result.
It can be decomposed into sub-operations.
When the operation execution is completed, a log can be generated by a StatusWriter
to have a complete execution trace.
Clients may extend this class.
OperationRunner
,
StatusWriter.Factory.createHTML()
Constructor and Description |
---|
Operation(String name)
Creates an new instance of
Operation . |
Modifier and Type | Method and Description |
---|---|
String |
getName()
Returns the name of the operation.
|
OperationStatus |
getStatus()
Returns the status of the operation.
|
protected boolean |
isCanceledOrFailed(org.eclipse.core.runtime.IProgressMonitor monitor)
Returns whether cancellation of current operation has been requested
or whether an error has occurred during the execution.
|
protected <R> R |
run(Function<R> function,
org.eclipse.core.runtime.IProgressMonitor monitor)
Requests the execution of the specified child function and returns the produced result, if any.
|
protected abstract void |
run(org.eclipse.core.runtime.IProgressMonitor monitor)
The
run() method is called either by the OperationRunner or by the parent operation. |
protected void |
run(Operation operation,
org.eclipse.core.runtime.IProgressMonitor monitor)
Requests the execution of the specified child operation.
|
public Operation(String name)
Operation
. The name of the operation is used as a message of the corresponding operation status.name
- the operation name.public final String getName()
getName
in class com.sodius.mdw.internal.core.operations.InternalOperation
public final OperationStatus getStatus()
OperationStatus
might be used to record additional information about the execution.
The operation status tree can be logged using a StatusWriter
.getStatus
in class com.sodius.mdw.internal.core.operations.InternalOperation
OperationStatus.add(IStatus)
,
StatusWriter.Factory.createHTML()
protected final void run(Operation operation, org.eclipse.core.runtime.IProgressMonitor monitor)
Before the child operation is executed, the method isCanceledOrFailed(monitor)
is called. If true
is returned, the
child operation is aborted.
The child operation status is automatically added to the parent operation status. If an error occurs during the child operation execution, the
error is recorded in the child operation status. Meaning this run()
call can never fail.
operation
- the child operation to execute.monitor
- the progress monitor used to report progress and to check for cancellation.protected final <R> R run(Function<R> function, org.eclipse.core.runtime.IProgressMonitor monitor)
Before the child function is executed, the method isCanceledOrFailed(monitor)
is called. If true
is returned, the
child function is aborted.
The child function status is automatically added to the parent operation status. If an error occurs during the child operation execution, the
error is recorded in the child operation status. Meaning this run()
call can never fail.
R
- the type of result produced by the function.function
- the child function to execute.monitor
- the progress monitor used to report progress and to check for cancellation.null
if either no result was set by the function or the function was not
executed (e.g. a cancel was requested).protected boolean isCanceledOrFailed(org.eclipse.core.runtime.IProgressMonitor monitor)
run(monitor)
method
is to abort its execution if either the user requested to cancel or
if the operation status severity is ERROR
.isCanceledOrFailed
in class com.sodius.mdw.internal.core.operations.InternalOperation
true
if cancellation has been requested
or the operation status severity is ERROR
,
and false
otherwiseIProgressMonitor.isCanceled()
,
IStatus.getSeverity()
protected abstract void run(org.eclipse.core.runtime.IProgressMonitor monitor)
run()
method is called either by the OperationRunner
or by the parent operation.
The general contract of the method run
is that it may
take any action whatsoever.
Progress messages might be sent to the end user by calling the IProgressMonitor.subTask(name)
method. Detailed execution
information might be recorded using the getOperationStatus()
method. Such status information is logged using a
StatusWriter
and is directed to the developer, for post-execution analysis.
The progress monitor should be consulted regularly to check for cancellation. It is recommended for that purpose to abort if a call
isCanceledOrFailed(monitor)
returns false
.
Sub operations might be called using the run(subOperation, monitor)
method.
run
in class com.sodius.mdw.internal.core.operations.InternalOperation
monitor
- the progress monitor used to report progress and to check for cancellation.OperationRunner.run(Operation, IProgressMonitor)
,
run(Operation, IProgressMonitor)
,
isCanceledOrFailed(IProgressMonitor)