bpmn-elements 5.1.3 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
@@ -4,205 +4,187 @@ import {getUniqueId} from '../shared';
4
4
  import {EventBroker} from '../EventBroker';
5
5
  import {FlowApi} from '../Api';
6
6
 
7
- export default function SequenceFlow(flowDef, {environment}) {
8
- const {id, type = 'sequenceflow', name, parent: originalParent, targetId, sourceId, isDefault, behaviour = {}} = flowDef;
9
- const parent = cloneParent(originalParent);
10
- const logger = environment.Logger(type.toLowerCase());
11
-
12
-
13
- const flowBase = {
14
- id,
15
- type,
16
- name,
17
- parent,
18
- behaviour,
19
- sourceId,
20
- targetId,
21
- isDefault,
22
- isSequenceFlow: true,
23
- environment,
24
- logger,
25
- };
26
-
27
- environment.registerScript({...flowBase});
28
-
29
- let counters = {
7
+ const countersSymbol = Symbol.for('counters');
8
+
9
+ export default SequenceFlow;
10
+
11
+ function SequenceFlow(flowDef, {environment}) {
12
+ const {id, type = 'sequenceflow', name, parent, targetId, sourceId, isDefault, behaviour = {}} = flowDef;
13
+
14
+ this.id = id;
15
+ this.type = type;
16
+ this.name = name;
17
+ this.parent = cloneParent(parent);
18
+ this.behaviour = behaviour;
19
+ this.sourceId = sourceId;
20
+ this.targetId = targetId;
21
+ this.isDefault = isDefault;
22
+ this.isSequenceFlow = true;
23
+ this.environment = environment;
24
+ const logger = this.logger = environment.Logger(type.toLowerCase());
25
+
26
+ this[countersSymbol] = {
30
27
  looped: 0,
31
28
  take: 0,
32
29
  discard: 0,
33
30
  };
34
31
 
35
- const flowApi = {
36
- ...flowBase,
37
- get counters() {
38
- return {...counters};
39
- },
40
- discard,
41
- evaluateCondition,
42
- getApi,
43
- getCondition,
44
- getState,
45
- recover,
46
- shake,
47
- stop,
48
- take,
49
- };
32
+ environment.registerScript(this);
33
+ const {broker, on, once, waitFor, emitFatal} = new EventBroker(this, {prefix: 'flow', durable: true, autoDelete: false});
34
+ this.broker = broker;
35
+ this.on = on;
36
+ this.once = once;
37
+ this.waitFor = waitFor;
38
+ this.emitFatal = emitFatal;
50
39
 
51
- const {broker, on, once, waitFor, emitFatal} = EventBroker(flowApi, {prefix: 'flow', durable: true, autoDelete: false});
40
+ logger.debug(`<${id}> init, <${sourceId}> -> <${targetId}>`);
41
+ }
52
42
 
53
- flowApi.on = on;
54
- flowApi.once = once;
55
- flowApi.waitFor = waitFor;
43
+ const proto = SequenceFlow.prototype;
56
44
 
57
- Object.defineProperty(flowApi, 'broker', {
58
- enumerable: true,
59
- get: () => broker,
60
- });
45
+ Object.defineProperty(proto, 'counters', {
46
+ enumerable: true,
47
+ get() {
48
+ return {...this[countersSymbol]};
49
+ },
50
+ });
61
51
 
62
- logger.debug(`<${id}> init, <${sourceId}> -> <${targetId}>`);
63
-
64
- return flowApi;
52
+ proto.take = function take(content = {}) {
53
+ this.looped = undefined;
65
54
 
66
- function take(content = {}) {
67
- flowApi.looped = undefined;
55
+ const {sequenceId} = content;
68
56
 
69
- const {sequenceId} = content;
57
+ this.logger.debug(`<${sequenceId} (${this.id})> take, target <${this.targetId}>`);
58
+ ++this[countersSymbol].take;
70
59
 
71
- logger.debug(`<${sequenceId} (${id})> take, target <${targetId}>`);
72
- ++counters.take;
60
+ this._publishEvent('take', content);
73
61
 
74
- publishEvent('take', content);
62
+ return true;
63
+ };
75
64
 
76
- return true;
65
+ proto.discard = function discard(content = {}) {
66
+ const {sequenceId = getUniqueId(this.id)} = content;
67
+ const discardSequence = content.discardSequence = (content.discardSequence || []).slice();
68
+ if (discardSequence.indexOf(this.targetId) > -1) {
69
+ ++this[countersSymbol].looped;
70
+ this.logger.debug(`<${this.id}> discard loop detected <${this.sourceId}> -> <${this.targetId}>. Stop.`);
71
+ return this._publishEvent('looped', content);
77
72
  }
78
73
 
79
- function discard(content = {}) {
80
- const {sequenceId = getUniqueId(id)} = content;
81
- const discardSequence = content.discardSequence = (content.discardSequence || []).slice();
82
- if (discardSequence.indexOf(targetId) > -1) {
83
- ++counters.looped;
84
- logger.debug(`<${id}> discard loop detected <${sourceId}> -> <${targetId}>. Stop.`);
85
- return publishEvent('looped', content);
86
- }
74
+ discardSequence.push(this.sourceId);
87
75
 
88
- discardSequence.push(sourceId);
89
-
90
- logger.debug(`<${sequenceId} (${id})> discard, target <${targetId}>`);
91
- ++counters.discard;
92
- publishEvent('discard', content);
93
- }
76
+ this.logger.debug(`<${sequenceId} (${this.id})> discard, target <${this.targetId}>`);
77
+ ++this[countersSymbol].discard;
78
+ this._publishEvent('discard', content);
79
+ };
94
80
 
95
- function publishEvent(action, content) {
96
- const eventContent = createMessage({
97
- action,
98
- ...content,
99
- });
81
+ proto.getState = function getState() {
82
+ return this.createMessage({
83
+ counters: this.counters,
84
+ broker: this.broker.getState(true),
85
+ });
86
+ };
100
87
 
101
- broker.publish('event', `flow.${action}`, eventContent, {type: action});
102
- }
88
+ proto.recover = function recover(state) {
89
+ Object.assign(this[countersSymbol], state.counters);
90
+ this.broker.recover(state.broker);
91
+ };
103
92
 
104
- function createMessage(override) {
105
- return {
106
- ...override,
107
- id,
108
- type,
109
- name,
110
- sourceId,
111
- targetId,
112
- isSequenceFlow: true,
113
- isDefault,
114
- parent: cloneParent(parent),
115
- };
116
- }
93
+ proto.getApi = function getApi(message) {
94
+ return FlowApi(this.broker, message || {content: this.createMessage()});
95
+ };
117
96
 
118
- function getState() {
119
- const result = {
120
- id,
121
- type,
122
- name,
123
- sourceId,
124
- targetId,
125
- isDefault,
126
- counters: {...counters},
127
- };
128
- result.broker = broker.getState();
129
- return result;
130
- }
97
+ proto.stop = function stop() {
98
+ this.broker.stop();
99
+ };
131
100
 
132
- function recover(state) {
133
- counters = {...counters, ...state.counters};
134
- broker.recover(state.broker);
135
- }
101
+ proto.shake = function shake(message) {
102
+ const content = cloneContent(message.content);
103
+ content.sequence = content.sequence || [];
104
+ content.sequence.push({id: this.id, type: this.type, isSequenceFlow: true, targetId: this.targetId});
136
105
 
137
- function getApi(message) {
138
- return FlowApi(broker, message || {content: createMessage()});
139
- }
106
+ if (content.id === this.targetId) return this.broker.publish('event', 'flow.shake.loop', content, {persistent: false, type: 'shake'});
140
107
 
141
- function stop() {
142
- broker.stop();
108
+ for (const s of message.content.sequence) {
109
+ if (s.id === this.id) return this.broker.publish('event', 'flow.shake.loop', content, {persistent: false, type: 'shake'});
143
110
  }
144
111
 
145
- function shake(message) {
146
- const content = cloneContent(message.content);
147
- content.sequence = content.sequence || [];
148
- content.sequence.push({id, type, isSequenceFlow: true, targetId});
112
+ this.broker.publish('event', 'flow.shake', content, {persistent: false, type: 'shake'});
113
+ };
149
114
 
150
- if (content.id === targetId) return broker.publish('event', 'flow.shake.loop', content, {persistent: false, type: 'shake'});
115
+ proto.getCondition = function getCondition() {
116
+ const conditionExpression = this.behaviour.conditionExpression;
117
+ if (!conditionExpression) return null;
151
118
 
152
- for (const s of message.content.sequence) {
153
- if (s.id === id) return broker.publish('event', 'flow.shake.loop', content, {persistent: false, type: 'shake'});
154
- }
155
-
156
- broker.publish('event', 'flow.shake', content, {persistent: false, type: 'shake'});
119
+ const {language} = conditionExpression;
120
+ const script = this.environment.getScript(language, this);
121
+ if (script) {
122
+ return new ScriptCondition(this, script, language);
157
123
  }
158
124
 
159
- function evaluateCondition(message, callback) {
160
- const condition = getCondition(message);
161
- if (!condition) return callback(null, true);
162
-
163
- return condition.execute(message, callback);
125
+ if (!conditionExpression.body) {
126
+ const msg = language ? `Condition expression script ${language} is unsupported or was not registered` : 'Condition expression without body is unsupported';
127
+ return this.emitFatal(new Error(msg), this.createMessage());
164
128
  }
165
129
 
166
- function getCondition() {
167
- const conditionExpression = behaviour.conditionExpression;
168
- if (!conditionExpression) return null;
130
+ return new ExpressionCondition(this, conditionExpression.body);
131
+ };
132
+
133
+ proto.createMessage = function createMessage(override) {
134
+ return {
135
+ ...override,
136
+ id: this.id,
137
+ type: this.type,
138
+ name: this.name,
139
+ sourceId: this.sourceId,
140
+ targetId: this.targetId,
141
+ isSequenceFlow: true,
142
+ isDefault: this.isDefault,
143
+ parent: cloneParent(this.parent),
144
+ };
145
+ };
169
146
 
170
- const {language} = conditionExpression;
171
- const script = environment.getScript(language, flowApi);
172
- if (script) {
173
- return ScriptCondition(script, language);
174
- }
147
+ proto._publishEvent = function publishEvent(action, content) {
148
+ const eventContent = this.createMessage({
149
+ action,
150
+ ...content,
151
+ });
175
152
 
176
- if (!conditionExpression.body) {
177
- const msg = language ? `Condition expression script ${language} is unsupported or was not registered` : 'Condition expression without body is unsupported';
178
- return emitFatal(new Error(msg), createMessage());
179
- }
153
+ this.broker.publish('event', `flow.${action}`, eventContent, {type: action});
154
+ };
180
155
 
181
- return ExpressionCondition(conditionExpression.body);
182
- }
156
+ function ScriptCondition(owner, script, language) {
157
+ this.type = 'script';
158
+ this.language = language;
159
+ this._owner = owner;
160
+ this._script = script;
161
+ }
183
162
 
184
- function ScriptCondition(script, language) {
185
- return {
186
- language,
187
- execute(message, callback) {
188
- try {
189
- return script.execute(ExecutionScope(flowApi, message), callback);
190
- } catch (err) {
191
- if (!callback) throw err;
192
- logger.error(`<${id}>`, err);
193
- callback(err);
194
- }
195
- },
196
- };
163
+ ScriptCondition.prototype.execute = function execute(message, callback) {
164
+ const owner = this._owner;
165
+ try {
166
+ return this._script.execute(ExecutionScope(owner, message), callback);
167
+ } catch (err) {
168
+ if (!callback) throw err;
169
+ owner.logger.error(`<${owner.id}>`, err);
170
+ callback(err);
197
171
  }
172
+ };
198
173
 
199
- function ExpressionCondition(expression) {
200
- return {
201
- execute: (message, callback) => {
202
- const result = environment.resolveExpression(expression, createMessage(message));
203
- if (callback) return callback(null, result);
204
- return result;
205
- },
206
- };
207
- }
174
+ function ExpressionCondition(owner, expression) {
175
+ this.type = 'expression';
176
+ this.expression = expression;
177
+ this._owner = owner;
208
178
  }
179
+
180
+ ExpressionCondition.prototype.execute = function execute(message, callback) {
181
+ const owner = this._owner;
182
+ try {
183
+ const result = owner.environment.resolveExpression(this.expression, owner.createMessage(message));
184
+ if (callback) return callback(null, result);
185
+ return result;
186
+ } catch (err) {
187
+ if (callback) return callback(err);
188
+ throw err;
189
+ }
190
+ };
@@ -1,77 +1,84 @@
1
1
  import Activity from '../activity/Activity';
2
2
  import {cloneContent} from '../messageHelper';
3
3
 
4
+ const completedSymbol = Symbol.for('completed');
5
+ const targetsSymbol = Symbol.for('targets');
6
+
4
7
  export default function EventBasedGateway(activityDef, context) {
5
- return Activity(EventBasedGatewayBehaviour, {...activityDef}, context);
8
+ return new Activity(EventBasedGatewayBehaviour, activityDef, context);
6
9
  }
7
10
 
8
11
  export function EventBasedGatewayBehaviour(activity, context) {
9
- const {id, type, broker, logger, outbound: outboundSequenceFlows = []} = activity;
10
- let executing = false;
11
-
12
- const source = {
13
- id,
14
- type,
15
- execute,
16
- };
17
-
18
- return source;
19
-
20
- function execute(executeMessage) {
21
- const isRedelivered = executeMessage.fields.redelivered;
22
- const content = executeMessage.content;
23
- const {executionId, outbound = [], outboundTaken} = content;
24
-
25
- const targets = [];
26
- for (let i = 0; i < outboundSequenceFlows.length; i++) {
27
- const flow = outboundSequenceFlows[i];
28
- targets.push(context.getActivityById(flow.targetId));
29
- outbound.push({id: flow.id, action: 'take'});
30
- }
31
-
32
- if (!targets.length) return complete(content);
33
-
34
- if (executing && outboundTaken) return;
35
-
36
- const targetConsumerTag = `_gateway-listener-${id}`;
37
-
38
- targets.forEach((target) => {
39
- target.broker.subscribeOnce('event', 'activity.end', onTargetCompleted, {consumerTag: targetConsumerTag});
40
- });
41
-
42
- broker.subscribeOnce('api', `activity.stop.${executionId}`, stop, {noAck: true, consumerTag: `_api-stop-${executionId}`});
43
-
44
- executing = true;
45
- if (!isRedelivered) return broker.publish('execution', 'execute.outbound.take', cloneContent(content, {outboundTaken: true}));
46
-
47
- function onTargetCompleted(_, message, owner) {
48
- const {id: targetId, exexutionId: targetExecutionId} = message.content;
49
- logger.debug(`<${executionId} (${id})> <${targetExecutionId}> completed run, discarding the rest`);
50
- targets.forEach((target) => {
51
- if (target === owner) return;
52
- target.broker.cancel(targetConsumerTag);
53
- target.discard();
54
- });
55
-
56
- const completedContent = cloneContent(executeMessage.content, {taken: {
57
- id: targetId,
58
- executionId: targetExecutionId,
59
- }, ignoreOutbound: true});
60
-
61
- complete(completedContent);
62
- }
63
-
64
- function complete(completedContent) {
65
- broker.publish('execution', 'execute.completed', completedContent);
66
- }
67
-
68
- function stop() {
69
- executing = false;
70
- targets.forEach((target) => {
71
- target.broker.cancel(targetConsumerTag);
72
- });
73
- broker.cancel(`_api-stop-${executionId}`);
74
- }
75
- }
12
+ this.id = activity.id;
13
+ this.type = activity.type;
14
+ this.activity = activity;
15
+ this.broker = activity.broker;
16
+ this.context = context;
17
+ this[targetsSymbol] = activity.outbound.map((flow) => context.getActivityById(flow.targetId));
76
18
  }
77
19
 
20
+ EventBasedGatewayBehaviour.prototype.execute = function execute(executeMessage) {
21
+ const executeContent = executeMessage.content;
22
+ const {executionId, outbound = [], outboundTaken} = executeContent;
23
+
24
+ const targets = this[targetsSymbol];
25
+ this[completedSymbol] = false;
26
+ if (!targets.length) return this._complete(executeContent);
27
+
28
+ for (const flow of this.activity.outbound) {
29
+ outbound.push({id: flow.id, action: 'take'});
30
+ }
31
+
32
+ if (!this[completedSymbol] && outboundTaken) return;
33
+
34
+ const targetConsumerTag = `_gateway-listener-${this.id}`;
35
+
36
+ const onTargetCompleted = this._onTargetCompleted.bind(this, executeMessage);
37
+ for (const target of this[targetsSymbol]) {
38
+ target.broker.subscribeOnce('event', 'activity.end', onTargetCompleted, {consumerTag: targetConsumerTag});
39
+ }
40
+
41
+ const broker = this.activity.broker;
42
+ broker.subscribeOnce('api', `activity.stop.${executionId}`, () => this._stop(), {
43
+ noAck: true,
44
+ consumerTag: '_api-stop-execution',
45
+ });
46
+
47
+ this[completedSymbol] = false;
48
+ if (!executeMessage.fields.redelivered) return broker.publish('execution', 'execute.outbound.take', cloneContent(executeContent, {outboundTaken: true}));
49
+ };
50
+
51
+ EventBasedGatewayBehaviour.prototype._onTargetCompleted = function onTargetCompleted(executeMessage, _, message, owner) {
52
+ const {id: targetId, exexutionId: targetExecutionId} = message.content;
53
+ const executeContent = executeMessage.content;
54
+ const executionId = executeContent.executionId;
55
+ this.activity.logger.debug(`<${executionId} (${this.id})> <${targetExecutionId}> completed run, discarding the rest`);
56
+
57
+ this._stop();
58
+ for (const target of this[targetsSymbol]) {
59
+ if (target === owner) continue;
60
+ target.discard();
61
+ }
62
+
63
+ const completedContent = cloneContent(executeContent, {
64
+ taken: {
65
+ id: targetId,
66
+ executionId: targetExecutionId,
67
+ },
68
+ ignoreOutbound: true,
69
+ });
70
+
71
+ this._complete(completedContent);
72
+ };
73
+
74
+ EventBasedGatewayBehaviour.prototype._complete = function complete(completedContent) {
75
+ this[completedSymbol] = true;
76
+ this.broker.publish('execution', 'execute.completed', cloneContent(completedContent));
77
+ };
78
+
79
+ EventBasedGatewayBehaviour.prototype._stop = function stop() {
80
+ const targetConsumerTag = `_gateway-listener-${this.id}`;
81
+ for (const target of this[targetsSymbol]) target.broker.cancel(targetConsumerTag);
82
+ this.broker.cancel('_api-stop-execution');
83
+ };
84
+
@@ -2,21 +2,16 @@ import Activity from '../activity/Activity';
2
2
  import {cloneContent} from '../messageHelper';
3
3
 
4
4
  export default function ExclusiveGateway(activityDef, context) {
5
- return Activity(ExclusiveGatewayBehaviour, activityDef, context);
5
+ return new Activity(ExclusiveGatewayBehaviour, activityDef, context);
6
6
  }
7
7
 
8
8
  export function ExclusiveGatewayBehaviour(activity) {
9
9
  const {id, type, broker} = activity;
10
-
11
- const source = {
12
- id,
13
- type,
14
- execute,
15
- };
16
-
17
- return source;
18
-
19
- function execute({content}) {
20
- broker.publish('execution', 'execute.completed', cloneContent(content, {outboundTakeOne: true}));
21
- }
10
+ this.id = id;
11
+ this.type = type;
12
+ this.broker = broker;
22
13
  }
14
+
15
+ ExclusiveGatewayBehaviour.prototype.execute = function execute({content}) {
16
+ this.broker.publish('execution', 'execute.completed', cloneContent(content, {outboundTakeOne: true}));
17
+ };
@@ -2,21 +2,16 @@ import Activity from '../activity/Activity';
2
2
  import {cloneContent} from '../messageHelper';
3
3
 
4
4
  export default function InclusiveGateway(activityDef, context) {
5
- return Activity(InclusiveGatewayBehaviour, activityDef, context);
5
+ return new Activity(InclusiveGatewayBehaviour, activityDef, context);
6
6
  }
7
7
 
8
8
  export function InclusiveGatewayBehaviour(activity) {
9
9
  const {id, type, broker} = activity;
10
-
11
- const source = {
12
- id,
13
- type,
14
- execute,
15
- };
16
-
17
- return source;
18
-
19
- function execute({content}) {
20
- broker.publish('execution', 'execute.completed', cloneContent(content));
21
- }
10
+ this.id = id;
11
+ this.type = type;
12
+ this.broker = broker;
22
13
  }
14
+
15
+ InclusiveGatewayBehaviour.prototype.execute = function execute({content}) {
16
+ this.broker.publish('execution', 'execute.completed', cloneContent(content));
17
+ };
@@ -2,21 +2,16 @@ import Activity from '../activity/Activity';
2
2
  import {cloneContent} from '../messageHelper';
3
3
 
4
4
  export default function ParallelGateway(activityDef, context) {
5
- return Activity(ParallelGatewayBehaviour, {...activityDef, isParallelGateway: true}, context);
5
+ return new Activity(ParallelGatewayBehaviour, {...activityDef, isParallelGateway: true}, context);
6
6
  }
7
7
 
8
8
  export function ParallelGatewayBehaviour(activity) {
9
9
  const {id, type, broker} = activity;
10
-
11
- const source = {
12
- id,
13
- type,
14
- execute,
15
- };
16
-
17
- return source;
18
-
19
- function execute({content}) {
20
- broker.publish('execution', 'execute.completed', cloneContent(content));
21
- }
10
+ this.id = id;
11
+ this.type = type;
12
+ this.broker = broker;
22
13
  }
14
+
15
+ ParallelGatewayBehaviour.prototype.execute = function execute({content}) {
16
+ this.broker.publish('execution', 'execute.completed', cloneContent(content));
17
+ };