]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecution.java
Document and improve execution model
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / process / SlcExecution.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.process;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Date;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.TreeMap;
25
26 import org.argeo.slc.execution.ExecutionProcess;
27
28 public class SlcExecution implements ExecutionProcess, Serializable {
29 private static final long serialVersionUID = -7607457971382118466L;
30
31 public final static String UNKOWN_HOST = "UNKOWN_HOST";
32
33 private String uuid;
34 private String host;
35 private String user;
36 private String type;
37 private String status = NEW;
38 private Map<String, String> attributes = new TreeMap<String, String>();
39
40 /** TODO: Synchronize */
41 private List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();
42 private List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
43
44 /** Attachment uuid. */
45 private String realizedFlowsXml = null;
46
47 public List<RealizedFlow> getRealizedFlows() {
48 return realizedFlows;
49 }
50
51 public void setRealizedFlows(List<RealizedFlow> realizedFlows) {
52 this.realizedFlows = realizedFlows;
53 }
54
55 public List<SlcExecutionStep> getSteps() {
56 return steps;
57 }
58
59 public void setSteps(List<SlcExecutionStep> steps) {
60 this.steps = steps;
61 }
62
63 public String getUuid() {
64 return uuid;
65 }
66
67 public void setUuid(String uuid) {
68 this.uuid = uuid;
69 }
70
71 public String getHost() {
72 return host;
73 }
74
75 public void setHost(String host) {
76 this.host = host;
77 }
78
79 public String getUser() {
80 return user;
81 }
82
83 public void setUser(String user) {
84 this.user = user;
85 }
86
87 public String getType() {
88 return type;
89 }
90
91 public void setType(String type) {
92 this.type = type;
93 }
94
95 public String getStatus() {
96 return status;
97 }
98
99 public void setStatus(String status) {
100 this.status = status;
101 }
102
103 public SlcExecutionStep currentStep() {
104 synchronized (steps) {
105 if (steps.size() > 0)
106 return steps.get(steps.size() - 1);
107 else
108 return null;
109 }
110 }
111
112 @Override
113 public boolean equals(Object obj) {
114 if (obj instanceof SlcExecution) {
115 return getUuid().equals(((SlcExecution) obj).getUuid());
116 }
117 return false;
118 }
119
120 @Override
121 public int hashCode() {
122 return getUuid().hashCode();
123 }
124
125 public Map<String, String> getAttributes() {
126 return attributes;
127 }
128
129 public void setAttributes(Map<String, String> attributes) {
130 this.attributes = attributes;
131 }
132
133 public String toString() {
134 StringBuffer buf = new StringBuffer(getClass().getSimpleName());
135 buf.append('#').append(uuid);
136 buf.append(" status=").append(status);
137 buf.append(" attributes=").append(attributes);
138 return buf.toString();
139 }
140
141 public Date getStartDate() {
142 synchronized (steps) {
143 if (steps.size() == 0)
144 return null;
145 else
146 return steps.get(0).getTimestamp();
147 }
148 }
149
150 public Date getEndDate() {
151 if (!status.equals(COMPLETED) && !status.equals(ERROR))
152 return null;
153
154 synchronized (steps) {
155 if (steps.size() == 0)
156 return null;
157 else
158 return steps.get(steps.size() - 1).getTimestamp();
159 }
160 }
161
162 /**
163 * Not (yet) a stable API, should not be relied upon!
164 *
165 * @return an id or an url allowing to retrieve the XML, not the XML itself!
166 */
167 public String getRealizedFlowsXml() {
168 return realizedFlowsXml;
169 }
170
171 /** Not (yet) a stable API, should not be relied upon! */
172 public void setRealizedFlowsXml(String realizedFlowsXml) {
173 this.realizedFlowsXml = realizedFlowsXml;
174 }
175
176 }