Revision 41620
Added by Michele Artini about 8 years ago
Token.java | ||
---|---|---|
3 | 3 |
import java.util.UUID; |
4 | 4 |
|
5 | 5 |
import com.google.common.base.Throwables; |
6 |
|
|
6 | 7 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
7 | 8 |
import eu.dnetlib.msro.workflows.graph.Arc; |
8 | 9 |
import eu.dnetlib.msro.workflows.util.NodeTokenCallback; |
9 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
10 | 10 |
|
11 | 11 |
/** |
12 | 12 |
* Created by michele on 19/11/15. |
... | ... | |
22 | 22 |
private long endDate = 0; |
23 | 23 |
private String nextArc = Arc.DEFAULT_ARC; |
24 | 24 |
private boolean active = true; |
25 |
private String error = ""; |
|
26 |
private String errorStackTrace = ""; |
|
25 | 27 |
|
26 | 28 |
public Token(final String nodeName, final NodeTokenCallback callback) { |
27 | 29 |
this.id = "token-" + UUID.randomUUID(); |
... | ... | |
31 | 33 |
} |
32 | 34 |
|
33 | 35 |
public String getId() { |
34 |
return id; |
|
36 |
return this.id;
|
|
35 | 37 |
} |
36 | 38 |
|
37 | 39 |
public Env getEnv() { |
38 |
return env; |
|
40 |
return this.env;
|
|
39 | 41 |
} |
40 | 42 |
|
41 | 43 |
public long getStartDate() { |
42 |
return startDate; |
|
44 |
return this.startDate;
|
|
43 | 45 |
} |
44 | 46 |
|
45 | 47 |
public long getEndDate() { |
46 |
return endDate; |
|
48 |
return this.endDate;
|
|
47 | 49 |
} |
48 | 50 |
|
49 | 51 |
public void setEndDate(final long endDate) { |
... | ... | |
51 | 53 |
} |
52 | 54 |
|
53 | 55 |
public String getNextArc() { |
54 |
return nextArc; |
|
56 |
return this.nextArc;
|
|
55 | 57 |
} |
56 | 58 |
|
57 | 59 |
public void setNextArc(final String nextArc) { |
... | ... | |
59 | 61 |
} |
60 | 62 |
|
61 | 63 |
public boolean isActive() { |
62 |
return active; |
|
64 |
return this.active;
|
|
63 | 65 |
} |
64 | 66 |
|
65 | 67 |
public void setActive(final boolean active) { |
... | ... | |
67 | 69 |
} |
68 | 70 |
|
69 | 71 |
public boolean isFailed() { |
70 |
return failed; |
|
72 |
return this.failed;
|
|
71 | 73 |
} |
72 | 74 |
|
73 | 75 |
public void setFailed(final boolean failed) { |
... | ... | |
78 | 80 |
setNextArc(arcName); |
79 | 81 |
setEndDate(DateUtils.now()); |
80 | 82 |
setActive(false); |
81 |
if (callback != null) { |
|
82 |
callback.onSuccess(this); |
|
83 |
if (this.callback != null) {
|
|
84 |
this.callback.onSuccess(this);
|
|
83 | 85 |
} |
84 | 86 |
} |
85 | 87 |
|
86 | 88 |
public void release() { |
87 | 89 |
setEndDate(DateUtils.now()); |
88 | 90 |
setActive(false); |
89 |
if (callback != null) { |
|
90 |
callback.onSuccess(this); |
|
91 |
if (this.callback != null) {
|
|
92 |
this.callback.onSuccess(this);
|
|
91 | 93 |
} |
92 | 94 |
} |
93 | 95 |
|
... | ... | |
95 | 97 |
setEndDate(DateUtils.now()); |
96 | 98 |
setActive(false); |
97 | 99 |
setFailed(true); |
98 |
env.setAttribute(WorkflowsConstants.SYSTEM_ERROR, e.getMessage());
|
|
99 |
env.setAttribute(WorkflowsConstants.SYSTEM_ERROR_STACKTRACE, Throwables.getStackTraceAsString(e));
|
|
100 |
if (callback != null) { |
|
101 |
callback.onFail(this); |
|
100 |
setError(e.getMessage());
|
|
101 |
setErrorStackTrace(Throwables.getStackTraceAsString(e));
|
|
102 |
if (this.callback != null) {
|
|
103 |
this.callback.onFail(this);
|
|
102 | 104 |
} |
103 | 105 |
} |
104 | 106 |
|
... | ... | |
106 | 108 |
setEndDate(DateUtils.now()); |
107 | 109 |
setActive(false); |
108 | 110 |
setFailed(true); |
109 |
env.setAttribute(WorkflowsConstants.SYSTEM_ERROR, error);
|
|
110 |
if (callback != null) { |
|
111 |
callback.onFail(this); |
|
111 |
setError(error);
|
|
112 |
if (this.callback != null) {
|
|
113 |
this.callback.onFail(this);
|
|
112 | 114 |
} |
113 | 115 |
} |
114 | 116 |
|
115 | 117 |
public String getNodeName() { |
116 |
return nodeName; |
|
118 |
return this.nodeName;
|
|
117 | 119 |
} |
120 |
|
|
121 |
public String getError() { |
|
122 |
return this.error; |
|
123 |
} |
|
124 |
|
|
125 |
public void setError(final String error) { |
|
126 |
this.error = error; |
|
127 |
} |
|
128 |
|
|
129 |
public String getErrorStackTrace() { |
|
130 |
return this.errorStackTrace; |
|
131 |
} |
|
132 |
|
|
133 |
public void setErrorStackTrace(final String errorStackTrace) { |
|
134 |
this.errorStackTrace = errorStackTrace; |
|
135 |
} |
|
118 | 136 |
} |
Also available in: Unified diff
WF errors management