1 package com.atlassian.scheduler.core.status;
2
3 import com.atlassian.scheduler.status.RunDetails;
4 import com.atlassian.scheduler.status.RunOutcome;
5
6 import javax.annotation.Nonnull;
7 import javax.annotation.Nullable;
8 import javax.annotation.concurrent.Immutable;
9 import java.util.Date;
10
11 import static com.atlassian.util.concurrent.Assertions.notNull;
12
13 @Immutable
14 public final class RunDetailsImpl implements RunDetails {
15 private final long startTime;
16 private final RunOutcome runOutcome;
17 private final long durationInMillis;
18 private final String message;
19
20 public RunDetailsImpl(final Date startTime, final RunOutcome runOutcome, final long durationInMillis,
21 @Nullable final String message) {
22 this.startTime = notNull("startTime", startTime).getTime();
23 this.runOutcome = notNull("runOutcome", runOutcome);
24 this.durationInMillis = (durationInMillis >= 0L) ? durationInMillis : 0L;
25 this.message = truncate(message);
26 }
27
28
29 @Override
30 @Nonnull
31 public Date getStartTime() {
32 return new Date(startTime);
33 }
34
35 @Override
36 public long getDurationInMillis() {
37 return durationInMillis;
38 }
39
40 @Override
41 @Nonnull
42 public RunOutcome getRunOutcome() {
43 return runOutcome;
44 }
45
46 @Override
47 @Nonnull
48 public String getMessage() {
49 return message;
50 }
51
52
53 @Override
54 public String toString() {
55 return "RunDetailsImpl[startTime=" + startTime +
56 ",runOutcome=" + runOutcome +
57 ",durationInMillis=" + durationInMillis +
58 ",message=" + message +
59 ']';
60 }
61
62
63 private static String truncate(@Nullable final String message) {
64 if (message == null) {
65 return "";
66 }
67 if (message.length() > MAXIMUM_MESSAGE_LENGTH) {
68 return message.substring(0, MAXIMUM_MESSAGE_LENGTH);
69 }
70 return message;
71 }
72 }