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.ProcessController;
21 import nextgrid.api.pom.ProcessException;
22
23
24
25
26 class ThreadController implements ProcessController {
27
28 private final ProcessContext ctx;
29
30 private final Enactable e;
31
32 private EnactionWorker worker;
33
34
35
36
37
38
39
40 public ThreadController(ProcessContext ctx, Enactable e) {
41 this.ctx = ctx;
42 this.e = e;
43 }
44
45
46
47
48 public void cancel() throws ProcessException, InterruptedException {
49 if (worker != null) {
50 ctx.cancel();
51 worker.join();
52 }
53 }
54
55
56
57
58 public State getState() {
59 return ctx.getState();
60 }
61
62
63
64
65 public void pause() throws ProcessException, InterruptedException {
66 if (worker != null) {
67 ctx.pause();
68 worker.join();
69 }
70 }
71
72
73
74
75 public void resume() throws ProcessException {
76 ctx.resume();
77 if (worker == null) {
78 worker = ctx.createWorkerThread(e);
79 worker.start();
80 }
81 }
82
83
84
85
86 public void start() {
87 if (worker == null) {
88 worker = ctx.createWorkerThread(e);
89 worker.start();
90 }
91 }
92
93
94
95
96 public void join() throws ProcessException, InterruptedException {
97 if (worker != null) {
98 worker.join();
99 worker.checkError();
100 }
101 }
102
103
104
105
106 public void run() throws ProcessException, InterruptedException {
107 start();
108 join();
109 }
110 }