1
2
3
4 package org.jdiagnose.runtime;
5
6 import org.jdiagnose.Diagnostic;
7 import org.jdiagnose.DiagnosticException;
8 import org.jdiagnose.DiagnosticMessage;
9 import org.jdiagnose.MessageFactory;
10
11 /***
12 * @author jmccrindle
13 */
14 public class DefaultDiagnosticResult implements DiagnosticResult {
15
16 private Diagnostic diagnostic;
17 private ResultState state = ResultState.NOT_STARTED;
18 private long startTime;
19 private long finishTime;
20 private DiagnosticMessage message;
21 private MessageFactory messageFactory;
22
23 public DefaultDiagnosticResult(MessageFactory messageFactory, Diagnostic diagnostic) {
24 this.diagnostic = diagnostic;
25 this.messageFactory = messageFactory;
26 }
27
28
29
30
31 public String getName() {
32 return diagnostic.getName();
33 }
34
35
36
37
38 public ResultState getState() {
39 return state;
40 }
41
42
43
44
45 public long getDuration() {
46 return finishTime - startTime;
47 }
48
49
50
51
52 public long getStartTime() {
53 return startTime;
54 }
55
56
57
58
59 public long getFinishTime() {
60 return finishTime;
61 }
62
63
64
65
66 public synchronized void diagnose() {
67 finishTime = startTime = System.currentTimeMillis();
68 try {
69 state = ResultState.RUNNING;
70 diagnostic.diagnose();
71 state = ResultState.SUCCEEDED;
72 } catch (DiagnosticException e) {
73 state = ResultState.FAILED;
74 this.message = messageFactory.getMessage(e);
75 } finally {
76 finishTime = System.currentTimeMillis();
77 }
78 }
79
80 public Diagnostic getDiagnostic() {
81 return diagnostic;
82 }
83
84 public DiagnosticMessage getMessage() {
85 return message;
86 }
87
88 }