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
29
30
31
32
33
34 public class TimingResult extends EventObject implements ResultEvent {
35
36 private static final long serialVersionUID = 5335636381355236617L;
37
38 private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH.mm.ss.SSS");
39
40 private String type;
41 private DateTime start;
42 private DateTime end;
43 private ExecutionEnvironment environment;
44 private String description;
45 private Map<String, ?> resultDetails;
46
47
48
49
50
51
52
53
54
55
56 public TimingResult(String description, String type, Object source, ExecutionEnvironment environment, DateTime start, DateTime end){
57 super(source);
58 this.type = type;
59 this.environment = environment;
60 this.start = start;
61 this.end = end;
62 this.description = description;
63 }
64
65
66
67
68
69
70
71
72
73 public TimingResult(String type, Object source, ExecutionEnvironment environment, DateTime start, DateTime end){
74 super(source);
75 this.type = type;
76 this.environment = environment;
77 this.start = start;
78 this.end = end;
79 }
80
81
82
83
84
85 public Long getElapsedTimeInMilliseconds(){
86 return Long.valueOf(end.getMillis() - start.getMillis());
87 }
88
89 @Override
90 public ExecutionEnvironment getEnvironment(){
91 return environment;
92 };
93
94 @Override
95 public String toString(){
96 StringBuffer sb = new StringBuffer();
97 sb.append(fmt.print(end));
98 sb.append(" EventType: "+ type);
99 sb.append(" (Start = " + fmt.print(start));
100 sb.append(", End = " + fmt.print(end));
101 sb.append(", Elapsed Time = "+ getElapsedTimeInMilliseconds().toString());
102 sb.append(" milliseconds.)");
103 return sb.toString();
104 }
105
106 @Override
107 public Boolean getResult() {
108 return null;
109 }
110
111 @Override
112 public DateTime getTimestamp() {
113 return end;
114 }
115
116 @Override
117 public String getType() {
118 return type;
119 }
120
121
122
123
124
125 @Override
126 public Map<String, ?> getResultDetails() {
127 if (resultDetails == null) {
128 return Collections.emptyMap();
129 } else {
130 return Collections.unmodifiableMap(resultDetails);
131 }
132 }
133
134 @Override
135 public String getDescription() {
136 return description;
137 }
138 }