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 org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import nextgrid.api.pom.Process;
24 import nextgrid.api.pom.ProcessException;
25
26
27
28
29 class EnactionWorker extends Thread {
30
31
32
33
34 protected static final Log ENACTOR_LOG = LogFactory.getLog("ENACTOR");
35
36
37
38
39 private final ProcessContext ctx;
40
41
42 private final Enactable enactable;
43
44
45 private Throwable error;
46
47
48
49
50
51
52
53 public EnactionWorker(ProcessContext ctx, Enactable e) {
54 super("Process-Id:" + (e.getId() == null ? "null" : e.getId().toString()));
55 this.ctx = ctx;
56 this.enactable = e;
57 }
58
59
60
61
62 @Override public void run() {
63 String name;
64 if (enactable instanceof Process) {
65 name = ((Process)enactable).getName();
66 } else {
67 name = this.getName();
68 }
69
70 ENACTOR_LOG.debug("Process '" + name + "': started");
71 try {
72 enactable.run(this.ctx);
73
74 if (ctx.isRunning()) {
75 ENACTOR_LOG.debug("Process '" + name + "': finished");
76 }
77 } catch (ProcessException e) {
78 ENACTOR_LOG.warn("Process '" + name + "': error", e);
79 error = e;
80 } catch (Throwable t) {
81 ENACTOR_LOG.error("Process '" + name + "': unexpected error", t);
82 error = t;
83 }
84 }
85
86
87
88
89
90
91 public void checkError() throws ProcessException {
92 if (error instanceof ProcessException) {
93 throw (ProcessException)error;
94 } else if (error instanceof RuntimeException) {
95 throw (RuntimeException)error;
96 } else if (error instanceof Error) {
97 throw (Error)error;
98 } else if (error != null) {
99 throw new ProcessException(error);
100 }
101 }
102 }