]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStep.java
Move SLC API
[gpl/argeo-slc.git] / org.argeo.slc.api / src / org / argeo / slc / execution / ExecutionStep.java
diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStep.java b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStep.java
new file mode 100644 (file)
index 0000000..628a3b6
--- /dev/null
@@ -0,0 +1,111 @@
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.execution;\r
+\r
+import java.io.Serializable;\r
+import java.util.Date;\r
+\r
+/**\r
+ * An atomic step to be notified in during an {@link ExecutionProcess}. Can be a\r
+ * log or the start/end of a phase, etc.\r
+ */\r
+public class ExecutionStep implements Serializable {\r
+       private static final long serialVersionUID = 798640526532912161L;\r
+\r
+       public final static String PHASE_START = "PHASE_START";\r
+       public final static String PHASE_END = "PHASE_END";\r
+       public final static String ERROR = "ERROR";\r
+       public final static String WARNING = "WARNING";\r
+       public final static String INFO = "INFO";\r
+       public final static String DEBUG = "DEBUG";\r
+       public final static String TRACE = "TRACE";\r
+\r
+       /** @deprecated */\r
+       public final static String START = "START";\r
+       /** @deprecated */\r
+       public final static String END = "END";\r
+\r
+       // TODO make the fields final and private when we don't need POJO support\r
+       // anymore (that\r
+       // is when SlcExecutionStep is removed)\r
+       protected String type;\r
+       protected String thread;\r
+       protected Date timestamp;\r
+       protected String log;\r
+\r
+       private String location;\r
+\r
+       /** Empty constructor */\r
+       public ExecutionStep() {\r
+               Thread currentThread = Thread.currentThread();\r
+               thread = currentThread.getName();\r
+       }\r
+\r
+       /** Creates a step at the current date */\r
+       public ExecutionStep(String location, String type, String log) {\r
+               this(location, new Date(), type, log);\r
+       }\r
+\r
+       /** Creates a step of the given type. */\r
+       public ExecutionStep(String location, Date timestamp, String type,\r
+                       String log) {\r
+               this(location, timestamp, type, log, Thread.currentThread().getName());\r
+       }\r
+\r
+       public ExecutionStep(String location, Date timestamp, String type,\r
+                       String log, String thread) {\r
+               this.location = location;\r
+               this.type = type;\r
+               this.timestamp = timestamp;\r
+               this.thread = thread;\r
+               this.log = addLog(log);\r
+       }\r
+\r
+       public String getType() {\r
+               return type;\r
+       }\r
+\r
+       public Date getTimestamp() {\r
+               return timestamp;\r
+       }\r
+\r
+       public String getThread() {\r
+               return thread;\r
+       }\r
+\r
+       /**\r
+        * Return the string that should be stored in the log field. Can be null if\r
+        * another mechanism is used to store log lines.\r
+        */\r
+       protected String addLog(String log) {\r
+               return log;\r
+       }\r
+\r
+       public String getLog() {\r
+               return log;\r
+       }\r
+\r
+       @Override\r
+       public String toString() {\r
+               return "Execution step, thread=" + thread + ", type=" + type;\r
+       }\r
+\r
+       /** Typically the logging category */\r
+       public String getLocation() {\r
+               return location;\r
+       }\r
+\r
+}\r