1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework.engine.result;
17
18 import java.util.Collections;
19 import java.util.EventObject;
20 import java.util.Map;
21
22 import org.joda.time.DateTime;
23 import org.joda.time.format.DateTimeFormat;
24 import org.joda.time.format.DateTimeFormatter;
25 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
26 import org.kuali.rice.krms.api.engine.ResultEvent;
27
28 public class TimingResult extends EventObject implements ResultEvent {
29
30 private static final long serialVersionUID = 5335636381355236617L;
31
32 private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH.mm.ss.SSS");
33
34 private String type;
35 private DateTime start;
36 private DateTime end;
37 private ExecutionEnvironment environment;
38 private String description;
39 private Map<String, ?> resultDetails;
40
41 public TimingResult(String description, String type, Object source, ExecutionEnvironment environment, DateTime start, DateTime end){
42 super(source);
43 this.type = type;
44 this.environment = environment;
45 this.start = start;
46 this.end = end;
47 this.description = description;
48 }
49
50 public TimingResult(String type, Object source, ExecutionEnvironment environment, DateTime start, DateTime end){
51 super(source);
52 this.type = type;
53 this.environment = environment;
54 this.start = start;
55 this.end = end;
56 }
57
58 public Long getElapsedTimeInMilliseconds(){
59 return Long.valueOf(end.getMillis() - start.getMillis());
60 }
61
62 public ExecutionEnvironment getEnvironment(){
63 return environment;
64 };
65
66 public String toString(){
67 StringBuffer sb = new StringBuffer();
68 sb.append(fmt.print(end));
69 sb.append(" EventType: "+ type);
70 sb.append(" (Start = " + fmt.print(start));
71 sb.append(", End = " + fmt.print(end));
72 sb.append(", Elapsed Time = "+ getElapsedTimeInMilliseconds().toString());
73 sb.append(" milliseconds.)");
74 return sb.toString();
75 }
76
77 @Override
78 public Boolean getResult() {
79 return null;
80 }
81
82 @Override
83 public DateTime getTimestamp() {
84 return end;
85 }
86
87 @Override
88 public String getType() {
89 return type;
90 }
91
92 @Override
93 public Map<String, ?> getResultDetails() {
94 if (resultDetails == null) {
95 return Collections.emptyMap();
96 } else {
97 return Collections.unmodifiableMap(resultDetails);
98 }
99 }
100
101 @Override
102 public String getDescription() {
103 return description;
104 }
105 }