|
2 | 2 |
|
3 | 3 | import com.rollbar.api.json.JsonSerializable;
|
4 | 4 | import com.rollbar.api.truncation.StringTruncatable;
|
| 5 | +import com.rollbar.api.truncation.TruncationHelper; |
5 | 6 |
|
6 | 7 | import java.util.HashMap;
|
| 8 | +import java.util.List; |
7 | 9 | import java.util.Map;
|
8 | 10 | import java.util.Objects;
|
9 | 11 |
|
10 | 12 | public class RollbarThread implements JsonSerializable, StringTruncatable<RollbarThread> {
|
11 |
| - private final Thread thread; |
12 |
| - private final BodyContent bodyContent; |
| 13 | + private final String name; |
| 14 | + private final String id; |
| 15 | + private final String priority; |
| 16 | + private final String state; |
| 17 | + private final Group group; |
13 | 18 |
|
14 |
| - public RollbarThread(Thread thread, BodyContent bodyContent) { |
15 |
| - this.thread = thread; |
16 |
| - this.bodyContent = bodyContent; |
| 19 | + public RollbarThread(Thread thread, Group group) { |
| 20 | + name = thread.getName(); |
| 21 | + id = String.valueOf(thread.getId()); |
| 22 | + priority = String.valueOf(thread.getPriority()); |
| 23 | + state = thread.getState().toString(); |
| 24 | + this.group = group; |
| 25 | + } |
| 26 | + |
| 27 | + private RollbarThread( |
| 28 | + String name, |
| 29 | + String id, |
| 30 | + String priority, |
| 31 | + String state, |
| 32 | + Group group |
| 33 | + ) { |
| 34 | + this.name = name; |
| 35 | + this.id = id; |
| 36 | + this.priority = priority; |
| 37 | + this.state = state; |
| 38 | + this.group = group; |
17 | 39 | }
|
18 | 40 |
|
19 | 41 | @Override
|
20 | 42 | public Object asJson() {
|
21 | 43 | Map<String, Object> values = new HashMap<>();
|
22 |
| - values.put("name", getThreadName()); |
23 |
| - values.put("id", getThreadId()); |
24 |
| - values.put("priority", getThreadPriority()); |
25 |
| - values.put("state", getThreadState()); |
26 |
| - if (bodyContent != null) { |
27 |
| - values.put(bodyContent.getKeyName(), bodyContent); |
28 |
| - } |
| 44 | + values.put("name", name); |
| 45 | + values.put("id", id); |
| 46 | + values.put("priority", priority); |
| 47 | + values.put("state", state); |
| 48 | + values.put("group", group); |
29 | 49 | return values;
|
30 | 50 | }
|
31 | 51 |
|
32 | 52 | @Override
|
33 | 53 | public RollbarThread truncateStrings(int maxLength) {
|
34 |
| - return new RollbarThread(thread, bodyContent.truncateStrings(maxLength)); |
| 54 | + return new RollbarThread( |
| 55 | + name, |
| 56 | + id, |
| 57 | + priority, |
| 58 | + state, |
| 59 | + group.truncateStrings(maxLength) |
| 60 | + ); |
35 | 61 | }
|
36 | 62 |
|
37 | 63 | @Override
|
38 | 64 | public String toString() {
|
39 | 65 | return "RollbarThread{" +
|
40 |
| - "name='" + getThreadName() + '\'' + |
41 |
| - ", id='" + getThreadId() + '\'' + |
42 |
| - ", priority='" + getThreadPriority() + '\'' + |
43 |
| - ", state='" + getThreadState() + '\'' + |
44 |
| - ", " + bodyContent.getKeyName() + "=" + bodyContent + |
45 |
| - '}'; |
| 66 | + "name='" + name + '\'' + |
| 67 | + ", id='" + id + '\'' + |
| 68 | + ", priority='" + priority + '\'' + |
| 69 | + ", state='" + state + '\'' + |
| 70 | + ", group='" + group + |
| 71 | + '}'; |
46 | 72 | }
|
47 | 73 |
|
48 |
| - private String getThreadName() { |
49 |
| - return thread.getName(); |
50 |
| - } |
51 |
| - |
52 |
| - private String getThreadId() { |
53 |
| - return String.valueOf(thread.getId()); |
54 |
| - } |
55 |
| - |
56 |
| - private String getThreadPriority() { |
57 |
| - return String.valueOf(thread.getPriority()); |
58 |
| - } |
59 |
| - |
60 |
| - private String getThreadState() { |
61 |
| - return thread.getState().toString(); |
62 |
| - } |
63 | 74 |
|
64 | 75 | @Override
|
65 | 76 | public boolean equals(Object o) {
|
66 |
| - if (!(o instanceof RollbarThread)) return false; |
| 77 | + if (o == null || getClass() != o.getClass()) return false; |
67 | 78 | RollbarThread that = (RollbarThread) o;
|
68 |
| - return Objects.equals(thread, that.thread) && Objects.equals(bodyContent, that.bodyContent); |
| 79 | + return Objects.equals(name, that.name) && Objects.equals(id, that.id) && Objects.equals(priority, that.priority) && Objects.equals(state, that.state) && Objects.equals(group, that.group); |
69 | 80 | }
|
70 | 81 |
|
71 | 82 | @Override
|
72 | 83 | public int hashCode() {
|
73 |
| - return Objects.hash(thread, bodyContent); |
| 84 | + return Objects.hash(name, id, priority, state, group); |
74 | 85 | }
|
75 | 86 | }
|
0 commit comments