|
16 | 16 | package com.navercorp.pinpoint.realtime.dto.mapper;
|
17 | 17 |
|
18 | 18 | import com.google.protobuf.GeneratedMessageV3;
|
19 |
| -import com.navercorp.pinpoint.grpc.trace.PActiveThreadDump; |
20 |
| -import com.navercorp.pinpoint.grpc.trace.PActiveThreadLightDump; |
21 |
| -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadCountRes; |
22 |
| -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDumpRes; |
23 |
| -import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDumpRes; |
24 |
| -import com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse; |
25 |
| -import com.navercorp.pinpoint.grpc.trace.PMonitorInfo; |
26 |
| -import com.navercorp.pinpoint.grpc.trace.PThreadDump; |
27 |
| -import com.navercorp.pinpoint.grpc.trace.PThreadLightDump; |
28 |
| -import com.navercorp.pinpoint.grpc.trace.PThreadState; |
29 |
| -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; |
30 |
| -import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadLightDump; |
31 |
| -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes; |
32 |
| -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDumpRes; |
33 |
| -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDumpRes; |
34 |
| -import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; |
35 |
| -import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo; |
36 |
| -import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; |
37 |
| -import com.navercorp.pinpoint.thrift.dto.command.TThreadLightDump; |
| 19 | +import com.navercorp.pinpoint.grpc.trace.*; |
| 20 | +import com.navercorp.pinpoint.thrift.dto.command.*; |
38 | 21 | import org.apache.thrift.TBase;
|
39 | 22 |
|
40 | 23 | import java.util.ArrayList;
|
@@ -64,78 +47,134 @@ public static GeneratedMessageV3 convert(TBase<?, ?> s) {
|
64 | 47 | }
|
65 | 48 |
|
66 | 49 | private static PCmdActiveThreadDumpRes convert(TCmdActiveThreadDumpRes s) {
|
67 |
| - return PCmdActiveThreadDumpRes.newBuilder() |
68 |
| - .setSubType(s.getSubType()) |
69 |
| - .setType(s.getType()) |
70 |
| - .setVersion(s.getVersion()) |
71 |
| - .addAllThreadDump(mapList(s.getThreadDumps(), ThriftToGrpcConverter::convert)) |
72 |
| - .build(); |
| 50 | + PCmdActiveThreadDumpRes.Builder builder = PCmdActiveThreadDumpRes.newBuilder(); |
| 51 | + if (s.getSubType() != null) { |
| 52 | + builder.setSubType(s.getSubType()); |
| 53 | + } |
| 54 | + if (s.getType() != null) { |
| 55 | + builder.setType(s.getType()); |
| 56 | + } |
| 57 | + if (s.getVersion() != null) { |
| 58 | + builder.setVersion(s.getVersion()); |
| 59 | + } |
| 60 | + builder.addAllThreadDump(mapList(s.getThreadDumps(), ThriftToGrpcConverter::convert)); |
| 61 | + return builder.build(); |
73 | 62 | }
|
74 | 63 |
|
75 |
| - private static PActiveThreadDump convert(TActiveThreadDump s2) { |
76 |
| - final TThreadDump s3 = s2.getThreadDump(); |
77 |
| - return PActiveThreadDump.newBuilder() |
78 |
| - .setStartTime(s2.getStartTime()) |
79 |
| - .setLocalTraceId(s2.getLocalTraceId()) |
80 |
| - .setSampled(s2.isSampled()) |
81 |
| - .setTransactionId(s2.getTransactionId()) |
82 |
| - .setEntryPoint(s2.getEntryPoint()) |
83 |
| - .setThreadDump(PThreadDump.newBuilder() |
84 |
| - .setThreadName(s3.getThreadName()) |
85 |
| - .setThreadId(s3.getThreadId()) |
86 |
| - .setBlockedTime(s3.getBlockedTime()) |
87 |
| - .setBlockedCount(s3.getBlockedCount()) |
88 |
| - .setWaitedTime(s3.getWaitedTime()) |
89 |
| - .setWaitedCount(s3.getWaitedCount()) |
90 |
| - .setLockName(s3.getLockName()) |
91 |
| - .setLockOwnerId(s3.getLockOwnerId()) |
92 |
| - .setLockOwnerName(s3.getLockOwnerName()) |
93 |
| - .setInNative(s3.isInNative()) |
94 |
| - .setSuspended(s3.isSuspended()) |
95 |
| - .setThreadState(PThreadState.forNumber(s3.getThreadState().getValue())) |
96 |
| - .addAllStackTrace(nonNullList(s3.getStackTrace())) |
97 |
| - .addAllLockedSynchronizer(nonNullList(s3.getLockedSynchronizers())) |
98 |
| - .addAllLockedMonitor(mapList(s3.getLockedMonitors(), ThriftToGrpcConverter::convert)) |
99 |
| - .build()) |
100 |
| - .build(); |
| 64 | + private static PActiveThreadDump convert(TActiveThreadDump s) { |
| 65 | + final PActiveThreadDump.Builder builder = PActiveThreadDump.newBuilder() |
| 66 | + .setStartTime(s.getStartTime()) |
| 67 | + .setLocalTraceId(s.getLocalTraceId()) |
| 68 | + .setSampled(s.isSampled()); |
| 69 | + |
| 70 | + if (s.getThreadDump() != null) { |
| 71 | + builder.setThreadDump(buildPThreadDump(s.getThreadDump())); |
| 72 | + } |
| 73 | + if (s.getTransactionId() != null) { |
| 74 | + builder.setTransactionId(s.getTransactionId()); |
| 75 | + } |
| 76 | + if (s.getEntryPoint() != null) { |
| 77 | + builder.setEntryPoint(s.getEntryPoint()); |
| 78 | + } |
| 79 | + |
| 80 | + return builder.build(); |
| 81 | + } |
| 82 | + |
| 83 | + private static PThreadDump buildPThreadDump(TThreadDump s) { |
| 84 | + PThreadDump.Builder builder = PThreadDump.newBuilder() |
| 85 | + .setThreadId(s.getThreadId()) |
| 86 | + .setBlockedTime(s.getBlockedTime()) |
| 87 | + .setBlockedCount(s.getBlockedCount()) |
| 88 | + .setWaitedTime(s.getWaitedTime()) |
| 89 | + .setWaitedCount(s.getWaitedCount()) |
| 90 | + .setLockOwnerId(s.getLockOwnerId()) |
| 91 | + .setInNative(s.isInNative()) |
| 92 | + .setSuspended(s.isSuspended()); |
| 93 | + |
| 94 | + if (s.getThreadName() != null) { |
| 95 | + builder.setThreadName(s.getThreadName()); |
| 96 | + } |
| 97 | + if (s.getLockName() != null) { |
| 98 | + builder.setLockName(s.getLockName()); |
| 99 | + } |
| 100 | + if (s.getLockOwnerName() != null) { |
| 101 | + builder.setLockOwnerName(s.getLockOwnerName()); |
| 102 | + } |
| 103 | + if (s.getThreadState() != null) { |
| 104 | + builder.setThreadState(PThreadState.forNumber(s.getThreadState().getValue())); |
| 105 | + } |
| 106 | + if (s.getStackTrace() != null) { |
| 107 | + builder.addAllStackTrace(nonNullList(s.getStackTrace())); |
| 108 | + } |
| 109 | + if (s.getLockedMonitors() != null) { |
| 110 | + builder.addAllLockedMonitor(mapList(s.getLockedMonitors(), ThriftToGrpcConverter::convert)); |
| 111 | + } |
| 112 | + if (s.getLockedSynchronizers() != null) { |
| 113 | + builder.addAllLockedSynchronizer(nonNullList(s.getLockedSynchronizers())); |
| 114 | + } |
| 115 | + return builder.build(); |
101 | 116 | }
|
102 | 117 |
|
103 | 118 | private static PMonitorInfo convert(TMonitorInfo s) {
|
104 |
| - return PMonitorInfo.newBuilder() |
105 |
| - .setStackDepth(s.getStackDepth()) |
106 |
| - .setStackFrame(s.getStackFrame()) |
107 |
| - .build(); |
| 119 | + PMonitorInfo.Builder builder = PMonitorInfo.newBuilder() |
| 120 | + .setStackDepth(s.getStackDepth()); |
| 121 | + if (s.getStackFrame() != null) { |
| 122 | + builder.setStackFrame(s.getStackFrame()); |
| 123 | + } |
| 124 | + return builder.build(); |
108 | 125 | }
|
109 | 126 |
|
110 | 127 | private static PCmdActiveThreadLightDumpRes convert(TCmdActiveThreadLightDumpRes s) {
|
111 |
| - final PCmdActiveThreadLightDumpRes.Builder builder = PCmdActiveThreadLightDumpRes.newBuilder() |
112 |
| - .setSubType(s.getSubType()) |
113 |
| - .setType(s.getType()) |
114 |
| - .setVersion(s.getVersion()) |
| 128 | + PCmdActiveThreadLightDumpRes.Builder builder = PCmdActiveThreadLightDumpRes.newBuilder() |
115 | 129 | .addAllThreadDump(mapList(s.getThreadDumps(), ThriftToGrpcConverter::convert));
|
| 130 | + if (s.getSubType() != null) { |
| 131 | + builder.setSubType(s.getSubType()); |
| 132 | + } |
| 133 | + if (s.getType() != null) { |
| 134 | + builder.setType(s.getType()); |
| 135 | + } |
| 136 | + if (s.getVersion() != null) { |
| 137 | + builder.setVersion(s.getVersion()); |
| 138 | + } |
116 | 139 | return builder.build();
|
117 | 140 | }
|
118 | 141 |
|
119 | 142 | private static PActiveThreadLightDump convert(TActiveThreadLightDump s) {
|
120 |
| - final TThreadLightDump s2 = s.getThreadDump(); |
121 |
| - return PActiveThreadLightDump.newBuilder() |
| 143 | + PActiveThreadLightDump.Builder builder = PActiveThreadLightDump.newBuilder() |
122 | 144 | .setStartTime(s.getStartTime())
|
123 | 145 | .setLocalTraceId(s.getLocalTraceId())
|
124 | 146 | .setSampled(s.isSampled())
|
125 |
| - .setTransactionId(s.getTransactionId()) |
126 |
| - .setEntryPoint(s.getEntryPoint()) |
127 |
| - .setThreadDump(PThreadLightDump.newBuilder() |
128 |
| - .setThreadName(s2.getThreadName()) |
129 |
| - .setThreadId(s2.getThreadId()) |
130 |
| - .setThreadState(PThreadState.forNumber(s2.getThreadState().getValue())) |
131 |
| - .build()) |
132 |
| - .build(); |
| 147 | + .setTransactionId(s.getTransactionId()); |
| 148 | + if (s.getTransactionId() != null) { |
| 149 | + builder.setTransactionId(s.getTransactionId()); |
| 150 | + } |
| 151 | + if (s.getEntryPoint() != null) { |
| 152 | + builder.setEntryPoint(s.getEntryPoint()); |
| 153 | + } |
| 154 | + if (s.getThreadDump() != null) { |
| 155 | + builder.setThreadDump(buildPThreadLightDump(s.getThreadDump())); |
| 156 | + } |
| 157 | + return builder.build(); |
| 158 | + } |
| 159 | + |
| 160 | + private static PThreadLightDump buildPThreadLightDump(TThreadLightDump s) { |
| 161 | + PThreadLightDump.Builder builder = PThreadLightDump.newBuilder() |
| 162 | + .setThreadId(s.getThreadId()); |
| 163 | + if (s.getThreadName() != null) { |
| 164 | + builder.setThreadName(s.getThreadName()); |
| 165 | + } |
| 166 | + if (s.getThreadState() != null) { |
| 167 | + builder.setThreadState(PThreadState.forNumber(s.getThreadState().getValue())); |
| 168 | + } |
| 169 | + return builder.build(); |
133 | 170 | }
|
134 | 171 |
|
135 | 172 | private static PCmdEchoResponse convert(TCommandEcho s) {
|
136 |
| - return PCmdEchoResponse.newBuilder() |
137 |
| - .setMessage(s.getMessage()) |
138 |
| - .build(); |
| 173 | + PCmdEchoResponse.Builder builder = PCmdEchoResponse.newBuilder(); |
| 174 | + if (s.getMessage() != null) { |
| 175 | + builder.setMessage(s.getMessage()); |
| 176 | + } |
| 177 | + return builder.build(); |
139 | 178 | }
|
140 | 179 |
|
141 | 180 | private static PCmdActiveThreadCountRes convert(TCmdActiveThreadCountRes s) {
|
|
0 commit comments