Skip to main content

Pentaho+ documentation has moved!

The new product documentation portal is here. Check it out now at docs.hitachivantara.com

 

Hitachi Vantara Lumada and Pentaho Documentation

Execution

pentaho.action Execution

The action.Execution class represents a certain model of action execution.

This class manages the execution of an action and enforces the multiple phases by which all actions, generically, go through, which are: "init", "will", "do", and "finally".

Synchronous or Asynchronous

The associated action can be synchronous or asynchronous, as determined by the type property, pentaho.action.Base.isSync. The execution of a synchronous action is completed synchronously. while that of an asynchronous action only completes asynchronously, due to its asynchronous "do" phase.

The execute method handles the execution of both types of actions. When the associated action is asynchronous, or it is not know if it is synchronous or asynchronous, after calling execute, obtain the value of the promise property and wait for its resolution.

Execution model

The following is a detailed description of the action execution model:

  1. When an action execution is constructed, it is in the unstarted state.

    The action's label and description properties, and any other property which defines what it ultimately does, can still be freely modified.

    In this state, the execution cannot be settled by marking it done or rejected.

  2. When the execute method is called, the execution enters the init phase:

    • the state is set to init;
    • the _onPhaseInit method is called.

    The action's label and description properties, and any other property which defines what it ultimately does, can be freely modified at this stage.

    The execution can be settled by marking it rejected in which case it transits to the finally phase.

    Otherwise, if the associated action is not valid, the execution is automatically rejected with the first reported validation error.

    Otherwise, the execution automatically transits to the will phase.

  3. In the will phase, what the associated action will do is already determined and cannot change anymore:

    • the state is set to will;
    • the associated action is frozen, using Object.freeze, and should not be modified anymore (e.g. by modifying nested objects); trying to modify direct properties of the action will throw a TypeError;
    • the _onPhaseWill method is called.

    From this point on, an execution can be canceled based on what exactly the associated action will do.

    The execution can be settled by marking it rejected, in which case it transits to the finally phase.

    Otherwise, the execution automatically transits to the do phase.

  4. In the do phase, the execution, proper, is carried out:

    • the state is set to do;
    • the _onPhaseDo method is called.
    • if after calling _onPhaseDo, the execution is not yet done or rejected, the _doDefault method is called, allowing the action execution class to clearly handle a default behaviour.

    The execution can be settled by marking it rejected or, alternatively, done.

    In either case, the execution transits to the finally phase.

  5. In the beginning of the finally phase, the execution is considered settled, with or without success.

    If this phase was entered due to a rejection, the execution is in one of the states canceled or failed, depending on the type of rejection reason, isRejected is true, and an error may be available.

    Otherwise, the execution was successful and it is in the did state. Property isDone now returns true and a result may be available.

    The _onPhaseFinally method is called.

    The finished state bit is set to on. Property isFinished now returns true.

AMD Module

require(["pentaho/action/Execution"], function(Execution) { /* code goes here */ });

Extends

Constructor

Name Description
new Execution()
Abstract

Creates an action execution instance for a given action and target.

Members

Name Description
__isInside :  boolean

Indicates if currently calling any of the methods: execute, executeWill, _onPhaseFinally__executePhaseFinally.

action :  pentaho.type.action.Base
Abstract

Gets the action of the action execution.

base :  function
Protected

If a method has been overridden, then the base method provides access to the overridden method.

error :  Error | pentaho.lang.UserError

Gets the reason for a rejected action execution, or null.

isCanceled :  boolean

Gets a value that indicates if the action execution has been canceled.

isDone :  boolean

Gets a value that indicates if the action execution completed successfully.

isExecuting :  boolean

Gets a value that indicates if the action execution is executing.

isFailed :  boolean

Gets a value that indicates if the action execution has failed.

isFinished :  boolean

Gets a value that indicates if the action execution has finished.

isRejected :  boolean

Gets a value that indicates if the action execution has been rejected.

isSettled :  boolean

Gets a value that indicates if the action execution has been settled.

isSync :  boolean

Gets a value that indicates if the execution is synchronous.

isUnstarted :  boolean

Gets a value that indicates if the action execution is in the unstarted state.

promise :  Promise

Gets a promise for the result (or error) of this action execution.

result :  *

Gets the result of a successful action execution, if any.

state :  pentaho.type.action.States

Gets the current action execution state.

target :  pentaho.type.action.ITarget
Abstract

Gets the target of the action execution.

Methods

Name Description
_doDefault() : Promise
Protected

Performs the default "execution" for the associated action.

_lockAction()
Protected

Locks the action.

_onPhaseDo() : Promise
Protected

Called during the action's do phase.

_onPhaseFinally()
Protected

Called during the action's finally phase.

_onPhaseInit()
Protected

Called during the action execution's initialize phase.

_onPhaseWill()
Protected

Called during the action execution's will phase.

_validate() : Array.<Error>
Protected

Validates that the action execution is valid for entering the will phase.

done(result) : pentaho.type.action.Execution

Called from an action observer to settle the action execution as being done, optionally giving a result value.

execute() : pentaho.type.action.Execution

Executes the action.

executeWill() : pentaho.type.action.Execution

Executes up to the 'will' phase of the action.

extend(source, keyArgs) : object

Extend an object with the properties of another.

reject(reason) : pentaho.type.action.Execution

Called to settle the action execution as rejected.

Constructor Details

new Execution()
Abstract

Creates an action execution instance for a given action and target.

Source: javascript/web/pentaho/action/Execution.js, line 182

Members Details

__isInside:  boolean

Indicates if currently calling any of the methods: execute, executeWill, _onPhaseFinally__executePhaseFinally.

Source: javascript/web/pentaho/action/Execution.js, line 202

Default Value: false

See also: pentaho.action.Execution#__callInside

action:  pentaho.type.action.Base
Abstract

Gets the action of the action execution.

Once the action execution enters the will phase, this object gets frozen and can no longer be modified.

Source: javascript/web/pentaho/action/Execution.js, line 229

base:  function
Protected

If a method has been overridden, then the base method provides access to the overridden method.

Can also be called from within a constructor function.

Source: javascript/web/pentaho/lang/Base.js, line 299

Inherited From: pentaho.lang.Base#base

error:  Error | pentaho.lang.UserError

Gets the reason for a rejected action execution, or null.

This property only returns a non-null value if isRejected is true.

Source: javascript/web/pentaho/action/Execution.js, line 323

isCanceled:  boolean

Gets a value that indicates if the action execution has been canceled.

An action execution is considered canceled if its state has the canceled bit on.

Source: javascript/web/pentaho/action/Execution.js, line 391

See also: pentaho.type.action.Execution#isRejected

isDone:  boolean

Gets a value that indicates if the action execution completed successfully.

An action execution is considered done if its state has the did bit on.

Source: javascript/web/pentaho/action/Execution.js, line 440

See also: pentaho.type.action.Execution#isSettled , pentaho.type.action.Execution#result

isExecuting:  boolean

Gets a value that indicates if the action execution is executing.

An action execution is considered executing if it has started but not yet finished, i.e., if its state is not the unstarted state or any of the finished states.

Source: javascript/web/pentaho/action/Execution.js, line 424

See also: pentaho.type.action.Execution#isUnstarted , pentaho.type.action.Execution#isFinished

isFailed:  boolean

Gets a value that indicates if the action execution has failed.

An action execution is considered failed if its state has the failed bit on.

Source: javascript/web/pentaho/action/Execution.js, line 406

See also: pentaho.type.action.Execution#isRejected

isFinished:  boolean

Gets a value that indicates if the action execution has finished.

An action execution is considered finished if its state has the finished bit on.

When finished, one of the bits did, canceled or failed must also be on.

Source: javascript/web/pentaho/action/Execution.js, line 462

See also: pentaho.type.action.Execution#isSettled

isRejected:  boolean

Gets a value that indicates if the action execution has been rejected.

An action execution is considered rejected if its state has one of the following bits on: canceled or failed.

Source: javascript/web/pentaho/action/Execution.js, line 376

See also: pentaho.type.action.Execution#isCanceled , pentaho.type.action.Execution#isFailed , pentaho.type.action.Execution#isDone , pentaho.type.action.Execution#isSettled , pentaho.type.action.Execution#error

isSettled:  boolean

Gets a value that indicates if the action execution has been settled.

An action execution is considered settled if its state has one of the following bits on: did, failed or canceled.

When an execution is settled it may not yet be [finished]{@see pentaho.type.action.Execution#isFinished}.

Source: javascript/web/pentaho/action/Execution.js, line 356

See also: pentaho.type.action.Execution#isCanceled , pentaho.type.action.Execution#isFailed , pentaho.type.action.Execution#isDone

isSync:  boolean

Gets a value that indicates if the execution is synchronous.

Source: javascript/web/pentaho/action/Execution.js, line 248

isUnstarted:  boolean

Gets a value that indicates if the action execution is in the unstarted state.

Source: javascript/web/pentaho/action/Execution.js, line 334

promise:  Promise

Gets a promise for the result (or error) of this action execution.

This promise can be requested anytime, before the execution has started, during execution, or after execution has finished. It can also be requested whether or not the associated action is synchronous or asynchronous.

The promise is fulfilled with the action execution's result or rejected with the action execution's error.

Source: javascript/web/pentaho/action/Execution.js, line 485

result:  *

Gets the result of a successful action execution, if any.

This property only returns a non-undefined value if isDone is true.

Source: javascript/web/pentaho/action/Execution.js, line 310

state:  pentaho.type.action.States

Gets the current action execution state.

Source: javascript/web/pentaho/action/Execution.js, line 279

See also: pentaho.type.action.Execution#isUnstarted , pentaho.type.action.Execution#isExecuting , pentaho.type.action.Execution#isSettled , pentaho.type.action.Execution#isDone , pentaho.type.action.Execution#isRejected , pentaho.type.action.Execution#isCanceled , pentaho.type.action.Execution#isFailed , pentaho.type.action.Execution#isFinished

target:  pentaho.type.action.ITarget
Abstract

Gets the target of the action execution.

Source: javascript/web/pentaho/action/Execution.js, line 252

Methods Details

_doDefault() : Promise
Protected

Performs the default "execution" for the associated action.

When the associated action is asynchronous, this method may return a promise. If the promise gets rejected, the action is rejected with the same rejection reason. However, if the promise gets fulfilled, its value is always ignored.

Source: javascript/web/pentaho/action/Execution.js, line 615

Returns:
Name Description
Promise
  • A promise for the completion of the default execution of an asynchronous action, or null.
_lockAction()
Protected

Locks the action.

The default implementation locks the action by using the Object.freeze() method.

Source: javascript/web/pentaho/action/Execution.js, line 891

_onPhaseDo() : Promise
Protected

Called during the action's do phase.

The default implementation does nothing.

Source: javascript/web/pentaho/action/Execution.js, line 1052

Returns:
Name Description
Promise | null

A promise to the completion of the asynchronous do listener, of an asynchronous action, or null.

_onPhaseFinally()
Protected

Called during the action's finally phase.

The default implementation does nothing.

Source: javascript/web/pentaho/action/Execution.js, line 1063

_onPhaseInit()
Protected

Called during the action execution's initialize phase.

The default implementation does nothing.

Source: javascript/web/pentaho/action/Execution.js, line 1029

_onPhaseWill()
Protected

Called during the action execution's will phase.

The default implementation does nothing.

Source: javascript/web/pentaho/action/Execution.js, line 1039

_validate() : Array.<Error>
Protected

Validates that the action execution is valid for entering the will phase.

The default implementation validates the action.

Source: javascript/web/pentaho/action/Execution.js, line 903

Returns:
Name Description
Array.<Error> | null

A non-empty array of errors, if any; otherwise null.

done(result) : pentaho.type.action.Execution

Called from an action observer to settle the action execution as being done, optionally giving a result value.

Source: javascript/web/pentaho/action/Execution.js, line 631

Parameters:
Name Default Value Summary
result : *
Optional

The result of the action execution, if any.

Returns:
Name Description
pentaho.type.action.Execution

The value of this.

Throws:
Name Description
pentaho.lang.OperationInvalidError

When the action execution is not in the do state.

execute() : pentaho.type.action.Execution

Executes the action.

When the associated action is asynchronous, or it is not know if it is synchronous or asynchronous, upon return of this method, obtain the value of the promise property and wait for its resolution.

Source: javascript/web/pentaho/action/Execution.js, line 540

Returns:
Name Description
pentaho.type.action.Execution

The value of this.

executeWill() : pentaho.type.action.Execution

Executes up to the 'will' phase of the action.

Source: javascript/web/pentaho/action/Execution.js, line 562

Returns:
Name Description
pentaho.type.action.Execution

The value of this.

extend(source, keyArgs) : object

Extend an object with the properties of another.

Methods that are overridden are accessible through this.base.

This object is extended, but its class doesn't change.

Source: javascript/web/pentaho/lang/Base.js, line 1040

Inherited From: pentaho.lang.Base#extend

Parameters:
Name Default Value Summary
source : object

The instance specification.

keyArgs : object
Optional

The keyword arguments.

Parameters:
Name Default Value Summary
exclude : object
Optional

A map of property names to exclude from source.

Returns:
Name Description
object

This object.

reject(reason) : pentaho.type.action.Execution

Called to settle the action execution as rejected.

The execution is considered failed if reason is an instance of Error (which is not an instance of UserError) or if it is an instance of RuntimeError.

Otherwise, the execution is considered canceled if reason is a string or an instance of UserError (which is not an instance of RuntimeError).

When unstarted, the execution's 'finally' phase is run. Otherwise, it is run later, when the execution reaches that phase.

Source: javascript/web/pentaho/action/Execution.js, line 704

Parameters:
Name Default Value Summary
reason : string | Error
Optional

The reason for the rejection.

Returns:
Name Description
pentaho.type.action.Execution

The value of this.

Throws:
Name Description
pentaho.lang.OperationInvalidError

When the action execution is not in one of the states unstarted, init, will or do.

See also: pentaho.type.action.Execution#isRejected , pentaho.type.action.Execution#isCanceled , pentaho.type.action.Execution#isFailed , pentaho.type.action.Execution#error

Example

define([
 "pentaho/lang/UserError",
 "pentaho/lang/RuntimeError"
], function(UserError, RuntimeError) {

 // ...

 target.on("fly", {
 will: function(event) {

 // Canceling the action execution
 // - Method 1
 event.reject("Cannot do this action now.");

 // - Method 2
 event.reject(new UserError("Cannot do this action now."));

 // Failing the action execution
 // - Method 1 (message is not adequate to be shown to the user):
 event.reject(new Error("Null Pointer Exception."));

 // - Method 2 (message is adequate to be shown to the user):
 event.reject(new RuntimeError("The server is currently unreachable."));
 }
 });

 // ...
});