1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.gridsystems.nextgrid.api.pom;
19
20 import nextgrid.api.pom.AsyncProcess;
21 import nextgrid.api.pom.LoopProcess;
22 import nextgrid.api.pom.Process;
23 import nextgrid.api.pom.ProcessController;
24 import nextgrid.api.pom.ProcessException;
25
26
27
28
29
30
31
32
33
34
35 public final class AsyncProcessImpl extends ControlProcessImpl
36 implements AsyncProcess {
37
38
39
40
41 private static final long serialVersionUID = 8003088574283848405L;
42
43
44
45
46 public AsyncProcessImpl() {
47 super(-1);
48 }
49
50
51
52
53 @Override
54 protected void doValidate(ValidationType when) throws ProcessException {
55 if (when == ValidationType.BEFORE_CHILDREN) {
56 Process parent = this.getParent();
57 while (parent != null) {
58 if (parent instanceof LoopProcess) {
59 throw new ProcessException("Asynchronous processes inside loops not allowed");
60 } else {
61 parent = parent.getParent();
62 }
63 }
64 }
65 }
66
67
68
69
70 public void run(ProcessContext ctx) throws ProcessException, InterruptedException {
71 fireProcessStarted();
72 waitForInputs();
73
74 Process[] children = getChildren();
75
76 final int count = (children == null) ? 0 : children.length;
77 ProcessController[] controllers = new ProcessController[count];
78 for (int i = 0; i < count; i++) {
79 controllers[i] = children[i].enact(ctx);
80 controllers[i].start();
81 }
82
83 if (ctx.isRunning()) {
84 fireProcessFinished();
85 }
86 }
87
88
89
90
91 @Override protected void doReset() {
92 }
93
94
95
96
97 @Override public String toString() {
98 return "AsyncProcess#" + this.getId();
99 }
100 }