Skip to content

Commit

Permalink
[#noissue] Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Aug 30, 2022
1 parent dbc6b31 commit 0606338
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public JvmInfoBo map(final PJvmInfo jvmInfo) {
final short version = (short) jvmInfo.getVersion();
final String jvmVersion = jvmInfo.getVmVersion();
final String gcTypeName = this.jvmGcTypeMapper.map(jvmInfo.getGcType()).name();
final JvmInfoBo jvmInfoBo = new JvmInfoBo(version);
jvmInfoBo.setJvmVersion(jvmVersion);
jvmInfoBo.setGcTypeName(gcTypeName);
return jvmInfoBo;
return new JvmInfoBo(version, jvmVersion, gcTypeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ public GrpcDeadlockBoMapper(GrpcThreadDumpBoMapper threadDumpBoMapper) {
}

public DeadlockBo map(final PDeadlock deadlock) {
final DeadlockBo deadlockBo = new DeadlockBo();
deadlockBo.setDeadlockedThreadCount(deadlock.getCount());
List<ThreadDumpBo> threadDumpBoList = getThreadDumpList(deadlock);
return new DeadlockBo(deadlock.getCount(), threadDumpBoList);
}

private List<ThreadDumpBo> getThreadDumpList(PDeadlock deadlock) {
final List<PThreadDump> threadDumpList = deadlock.getThreadDumpList();
if (CollectionUtils.hasLength(threadDumpList)) {
final List<ThreadDumpBo> threadDumpBoList = new ArrayList<>();
final List<ThreadDumpBo> threadDumpBoList = new ArrayList<>(threadDumpList.size());
for (PThreadDump threadDump : threadDumpList) {
final ThreadDumpBo threadDumpBo = this.threadDumpBoMapper.map(threadDump);
threadDumpBoList.add(threadDumpBo);
}
deadlockBo.setThreadDumpBoList(threadDumpBoList);
return threadDumpBoList;
}

return deadlockBo;
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
public class GrpcMonitorInfoBoMapper {

public MonitorInfoBo map(final PMonitorInfo monitorInfo) {
final MonitorInfoBo monitorInfoBo = new MonitorInfoBo();
monitorInfoBo.setStackDepth(monitorInfo.getStackDepth());
monitorInfoBo.setStackFrame(monitorInfo.getStackFrame());
return monitorInfoBo;
return new MonitorInfoBo(monitorInfo.getStackDepth(), monitorInfo.getStackFrame());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public JvmInfoBo map(TJvmInfo thriftObject) {
short version = thriftObject.getVersion();
String jvmVersion = thriftObject.getVmVersion();
String gcTypeName = this.jvmGcTypeMapper.map(thriftObject.getGcType()).name();
JvmInfoBo jvmInfoBo = new JvmInfoBo(version);
jvmInfoBo.setJvmVersion(jvmVersion);
jvmInfoBo.setGcTypeName(gcTypeName);
return jvmInfoBo;
return new JvmInfoBo(version, jvmVersion, gcTypeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ public ThriftDeadlockBoMapper(ThriftThreadDumpBoMapper threadDumpBoMapper) {
}

public DeadlockBo map(final TDeadlock tDeadlock) {
final DeadlockBo deadlockBo = new DeadlockBo();
deadlockBo.setDeadlockedThreadCount(tDeadlock.getDeadlockedThreadCount());
List<ThreadDumpBo> threadDumpList = getThreadDumpList(tDeadlock);
return new DeadlockBo(tDeadlock.getDeadlockedThreadCount(), threadDumpList);
}

private List<ThreadDumpBo> getThreadDumpList(TDeadlock tDeadlock) {
if (tDeadlock.isSetDeadlockedThreadList()) {
final List<ThreadDumpBo> threadDumpBoList = new ArrayList<>();
for (TThreadDump threadDump : tDeadlock.getDeadlockedThreadList()) {
final ThreadDumpBo threadDumpBo = this.threadDumpBoMapper.map(threadDump);
threadDumpBoList.add(threadDumpBo);
}
deadlockBo.setThreadDumpBoList(threadDumpBoList);
return threadDumpBoList;
}

return deadlockBo;
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
public class ThriftMonitorInfoBoMapper implements ThriftBoMapper<MonitorInfoBo, TMonitorInfo> {

public MonitorInfoBo map(final TMonitorInfo monitorInfo) {
final MonitorInfoBo monitorInfoBo = new MonitorInfoBo();
monitorInfoBo.setStackDepth(monitorInfo.getStackDepth());
monitorInfoBo.setStackFrame(monitorInfo.getStackFrame());
return monitorInfoBo;
return new MonitorInfoBo(monitorInfo.getStackDepth(), monitorInfo.getStackFrame());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

Expand All @@ -58,8 +60,7 @@ public void simpleTest1() {
final long eventTimestamp = startTimestamp;
final TAgentStat agentStat = createAgentStat(agentId, startTimestamp, eventTimestamp, 2);

DeadlockBo deadlockBo = new DeadlockBo();
deadlockBo.setDeadlockedThreadCount(agentStat.getDeadlock().getDeadlockedThreadCount());
DeadlockBo deadlockBo = new DeadlockBo(agentStat.getDeadlock().getDeadlockedThreadCount(), List.of());
DeadlockEventBo expectedEventBo = new DeadlockEventBo(agentId, startTimestamp, eventTimestamp, AgentEventType.AGENT_DEADLOCK_DETECTED, deadlockBo);

when(this.deadlockEventBoMapper.map(agentId, startTimestamp, startTimestamp, agentStat.getDeadlock())).thenReturn(expectedEventBo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.FixedBuffer;

import java.util.Objects;

/**
* @author HyunGil Jeong
*/
public class JvmInfoBo {

private final byte version;
private String jvmVersion;
private String gcTypeName;
private final String jvmVersion;
private final String gcTypeName;

public JvmInfoBo(int version) {
public JvmInfoBo(int version, String jvmVersion, String gcTypeName) {
if (version < 0 || version > 255) {
throw new IllegalArgumentException("version out of range (0~255)");
}
this.version = (byte) (version & 0xFF);
this.jvmVersion = Objects.requireNonNull(jvmVersion, "jvmVersion");
this.gcTypeName = Objects.requireNonNull(gcTypeName, "gcTypeName");
}

public JvmInfoBo(byte[] serializedJvmInfoBo) {
Expand All @@ -60,17 +64,11 @@ public String getJvmVersion() {
return jvmVersion;
}

public void setJvmVersion(String jvmVersion) {
this.jvmVersion = jvmVersion;
}

public String getGcTypeName() {
return gcTypeName;
}

public void setGcTypeName(String gcTypeName) {
this.gcTypeName = gcTypeName;
}

public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@
package com.navercorp.pinpoint.common.server.bo.event;

import java.util.List;
import java.util.Objects;

/**
* @author jaehong.kim
*/
public class DeadlockBo {
public static final int UNCOLLECTED_INT_VALUE = -1;

private int deadlockedThreadCount = UNCOLLECTED_INT_VALUE;
private List<ThreadDumpBo> threadDumpBoList;
private final int deadlockedThreadCount;
private final List<ThreadDumpBo> threadDumpBoList;

public int getDeadlockedThreadCount() {
return deadlockedThreadCount;
public DeadlockBo() {
this.deadlockedThreadCount = UNCOLLECTED_INT_VALUE;
this.threadDumpBoList = List.of();
}

public void setDeadlockedThreadCount(int deadlockedThreadCount) {
public DeadlockBo(int deadlockedThreadCount, List<ThreadDumpBo> threadDumpBoList) {
this.deadlockedThreadCount = deadlockedThreadCount;
this.threadDumpBoList = Objects.requireNonNull(threadDumpBoList, "threadDumpBoList");
}

public List<ThreadDumpBo> getThreadDumpBoList() {
return threadDumpBoList;
public int getDeadlockedThreadCount() {
return deadlockedThreadCount;
}

public void setThreadDumpBoList(List<ThreadDumpBo> threadDumpBoList) {
this.threadDumpBoList = threadDumpBoList;
public List<ThreadDumpBo> getThreadDumpBoList() {
return threadDumpBoList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,23 @@
* @author jaehong.kim
*/
public class MonitorInfoBo {
private int stackDepth;
private String stackFrame;
private final int stackDepth;
private final String stackFrame;

public MonitorInfoBo(int stackDepth, String stackFrame) {
this.stackDepth = stackDepth;
this.stackFrame = stackFrame;
}

public int getStackDepth() {
return stackDepth;
}

public void setStackDepth(int stackDepth) {
this.stackDepth = stackDepth;
}

public String getStackFrame() {
return stackFrame;
}

public void setStackFrame(String stackFrame) {
this.stackFrame = stackFrame;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("MonitorInfoBo{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ private DeadlockBo deserializeDeadlockBo(final byte[] eventBody) {
threadDumpBoList.add(readThreadDumpBo(buffer));
}

final DeadlockBo deadlockBo = new DeadlockBo();
deadlockBo.setDeadlockedThreadCount(deadlockedThreadCount);
deadlockBo.setThreadDumpBoList(threadDumpBoList);
return deadlockBo;
return new DeadlockBo(deadlockedThreadCount, threadDumpBoList);
}

private ThreadDumpBo readThreadDumpBo(final Buffer buffer) {
Expand Down Expand Up @@ -133,9 +130,6 @@ private MonitorInfoBo readMonitorInfoBo(final Buffer buffer) {
final int stackDepth = buffer.readInt();
final String stackFrame = buffer.readPrefixedString();

final MonitorInfoBo monitorInfoBo = new MonitorInfoBo();
monitorInfoBo.setStackDepth(stackDepth);
monitorInfoBo.setStackFrame(stackFrame);
return monitorInfoBo;
return new MonitorInfoBo(stackDepth, stackFrame);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class AgentEventMessageSerializerV1Test {
public void serialize() throws Exception {
AgentEventMessageSerializerV1 serializer = new AgentEventMessageSerializerV1();
// Mock
final DeadlockBo deadlockBo = new DeadlockBo();
deadlockBo.setDeadlockedThreadCount(1);
List<ThreadDumpBo> threadDumpBoList = new ArrayList<>();
ThreadDumpBo threadDumpBo = new ThreadDumpBo();
threadDumpBo.setThreadName("threadName");
Expand All @@ -57,15 +55,13 @@ public void serialize() throws Exception {
threadDumpBo.setStackTraceList(Arrays.asList("foo", "bar"));

List<MonitorInfoBo> monitorInfoBoList = new ArrayList<>();
MonitorInfoBo monitorInfoBo = new MonitorInfoBo();
monitorInfoBo.setStackDepth(9);
monitorInfoBo.setStackFrame("Frame");
MonitorInfoBo monitorInfoBo = new MonitorInfoBo(9, "Frame");
monitorInfoBoList.add(monitorInfoBo);
threadDumpBo.setLockedMonitorInfoList(monitorInfoBoList);
threadDumpBo.setLockedSynchronizerList(Arrays.asList("foo", "bar"));

threadDumpBoList.add(threadDumpBo);
deadlockBo.setThreadDumpBoList(threadDumpBoList);
final DeadlockBo deadlockBo = new DeadlockBo(1, threadDumpBoList);

byte[] bytes = serializer.serialize(AgentEventType.AGENT_DEADLOCK_DETECTED, deadlockBo);

Expand Down

0 comments on commit 0606338

Please sign in to comment.