]> git.argeo.org Git - gpl/argeo-slc.git/blob - ExecutionStep.java
74201c0e2ff4cea0f08a3a16dab76cd3e24df3db
[gpl/argeo-slc.git] / ExecutionStep.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.execution;
18
19 import java.io.Serializable;
20 import java.util.Date;
21
22 /**
23 * An atomic step to be notified in during an {@link ExecutionProcess}. Can be a
24 * log or the start/end of a phase, etc.
25 */
26 public class ExecutionStep implements Serializable {
27 private static final long serialVersionUID = 798640526532912161L;
28
29 public final static String PHASE_START = "PHASE_START";
30 public final static String PHASE_END = "PHASE_END";
31 public final static String ERROR = "ERROR";
32 public final static String WARNING = "WARNING";
33 public final static String INFO = "INFO";
34 public final static String DEBUG = "DEBUG";
35 public final static String TRACE = "TRACE";
36
37 /** @deprecated */
38 public final static String START = "START";
39 /** @deprecated */
40 public final static String END = "END";
41
42 // TODO make the fields final and private when we don't need POJO support
43 // anymore (that
44 // is when SlcExecutionStep is removed)
45 protected String type;
46 protected String thread;
47 protected Date timestamp;
48 protected String log;
49
50 private String location;
51
52 /** Empty constructor */
53 public ExecutionStep() {
54 Thread currentThread = Thread.currentThread();
55 thread = currentThread.getName();
56 }
57
58 /** Creates a step at the current date */
59 public ExecutionStep(String location, String type, String log) {
60 this(location, new Date(), type, log);
61 }
62
63 /** Creates a step of the given type. */
64 public ExecutionStep(String location, Date timestamp, String type,
65 String log) {
66 this(location, timestamp, type, log, Thread.currentThread().getName());
67 }
68
69 public ExecutionStep(String location, Date timestamp, String type,
70 String log, String thread) {
71 this.location = location;
72 this.type = type;
73 this.timestamp = timestamp;
74 this.thread = thread;
75 this.log = addLog(log);
76 }
77
78 public String getType() {
79 return type;
80 }
81
82 public Date getTimestamp() {
83 return timestamp;
84 }
85
86 public String getThread() {
87 return thread;
88 }
89
90 /**
91 * Return the string that should be stored in the log field. Can be null if
92 * another mechanism is used to store log lines.
93 */
94 protected String addLog(String log) {
95 return log;
96 }
97
98 public String getLog() {
99 return log;
100 }
101
102 @Override
103 public String toString() {
104 return "Execution step, thread=" + thread + ", type=" + type;
105 }
106
107 /** Typically the logging category */
108 public String getLocation() {
109 return location;
110 }
111
112 }