From d31845e23e80bdeebc21e982f79caecd2f7bc992 Mon Sep 17 00:00:00 2001 From: koo-taejin Date: Tue, 19 Aug 2014 11:28:08 +0900 Subject: [PATCH] =?UTF-8?q?#4=20Profiler=20-=20Collector=EA=B0=84=EC=9D=98?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) 클라이언트 상태 코드 변경 2) Agent에 의존적인 코드 삭제 3) 테스트 코드 변경 --- .../rpc/client/PinpointSocketHandler.java | 2 +- .../com/nhn/pinpoint/rpc/client/State.java | 40 +++++++------- .../pinpoint/rpc/server/ChannelContext.java | 5 -- .../rpc/server/PinpointServerSocket.java | 50 ----------------- .../pinpoint/rpc/server/AgentProperties.java | 3 -- .../rpc/server/AgentPropertiesType.java | 3 -- .../rpc/server/MessageListenerTest.java | 53 ++++++++++++++++++- 7 files changed, 72 insertions(+), 84 deletions(-) rename src/{main => test}/java/com/nhn/pinpoint/rpc/server/AgentProperties.java (93%) rename src/{main => test}/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java (92%) diff --git a/src/main/java/com/nhn/pinpoint/rpc/client/PinpointSocketHandler.java b/src/main/java/com/nhn/pinpoint/rpc/client/PinpointSocketHandler.java index 48a8da45b..8c764741b 100644 --- a/src/main/java/com/nhn/pinpoint/rpc/client/PinpointSocketHandler.java +++ b/src/main/java/com/nhn/pinpoint/rpc/client/PinpointSocketHandler.java @@ -204,7 +204,7 @@ public class PinpointSocketHandler extends SimpleChannelHandler implements Socke return; } - if (state.getState() == State.RUN_WITHOUT_REGISTER) { + if (state.getState() == State.RUN) { sendEnableWorkerPacket(); reservationEnableWorkerPacketJob(this); } diff --git a/src/main/java/com/nhn/pinpoint/rpc/client/State.java b/src/main/java/com/nhn/pinpoint/rpc/client/State.java index 6eef93027..69c4b1dd4 100644 --- a/src/main/java/com/nhn/pinpoint/rpc/client/State.java +++ b/src/main/java/com/nhn/pinpoint/rpc/client/State.java @@ -18,8 +18,8 @@ public class State { // 0 핸드쉐이크 안함.. 1은 동작중, 2는 closed public static final int INIT_RECONNECT = -1; public static final int INIT = 0; - public static final int RUN_WITHOUT_REGISTER = 1; - public static final int RUN = 2; + public static final int RUN = 1; + public static final int RUN_DUPLEX_COMMUNICATION = 2; public static final int CLOSED = 3; // 이 상태가 있어야 되나? public static final int RECONNECT = 4; @@ -33,11 +33,11 @@ public class State { public boolean isRun() { int code = state.get(); - return code == RUN_WITHOUT_REGISTER || code == RUN; + return code == RUN || code == RUN_DUPLEX_COMMUNICATION; } public boolean isRun(int code) { - return code == RUN_WITHOUT_REGISTER || code == RUN; + return code == RUN || code == RUN_DUPLEX_COMMUNICATION; } public boolean isClosed() { @@ -45,29 +45,29 @@ public class State { } public boolean changeRunWithoutRegister() { - logger.debug("State Will Be Changed {}.", getString(RUN_WITHOUT_REGISTER)); - final int current = state.get(); - if (current == INIT) { - return this.state.compareAndSet(INIT, RUN_WITHOUT_REGISTER); - } else if(current == INIT_RECONNECT) { - return this.state.compareAndSet(INIT_RECONNECT, RUN_WITHOUT_REGISTER); - } - throw new IllegalStateException("InvalidState current:" + getString(current) + " change:" + getString(RUN_WITHOUT_REGISTER)); - } - - public boolean changeRun() { logger.debug("State Will Be Changed {}.", getString(RUN)); final int current = state.get(); if (current == INIT) { return this.state.compareAndSet(INIT, RUN); } else if(current == INIT_RECONNECT) { return this.state.compareAndSet(INIT_RECONNECT, RUN); - } else if (current == RUN_WITHOUT_REGISTER) { - return this.state.compareAndSet(RUN_WITHOUT_REGISTER, RUN); } throw new IllegalStateException("InvalidState current:" + getString(current) + " change:" + getString(RUN)); } + public boolean changeRun() { + logger.debug("State Will Be Changed {}.", getString(RUN_DUPLEX_COMMUNICATION)); + final int current = state.get(); + if (current == INIT) { + return this.state.compareAndSet(INIT, RUN_DUPLEX_COMMUNICATION); + } else if(current == INIT_RECONNECT) { + return this.state.compareAndSet(INIT_RECONNECT, RUN_DUPLEX_COMMUNICATION); + } else if (current == RUN) { + return this.state.compareAndSet(RUN, RUN_DUPLEX_COMMUNICATION); + } + throw new IllegalStateException("InvalidState current:" + getString(current) + " change:" + getString(RUN_DUPLEX_COMMUNICATION)); + } + public boolean changeClosed(int before) { logger.debug("State Will Be Changed {} -> {}.", getString(before), getString(CLOSED)); return this.state.compareAndSet(before, CLOSED); @@ -75,7 +75,7 @@ public class State { public boolean changeClosed() { logger.debug("State Will Be Changed {}.", getString(CLOSED)); - return this.state.compareAndSet(RUN_WITHOUT_REGISTER, CLOSED); + return this.state.compareAndSet(RUN, CLOSED); } public void setClosed() { @@ -91,10 +91,10 @@ public class State { switch (stateCode) { case INIT: return "INIT"; - case RUN_WITHOUT_REGISTER: - return "RUN_WITHOUT_REGISTER"; case RUN: return "RUN"; + case RUN_DUPLEX_COMMUNICATION: + return "RUN_DUPLEX_COMMUNICATION"; case CLOSED: return "CLOSED"; case RECONNECT: diff --git a/src/main/java/com/nhn/pinpoint/rpc/server/ChannelContext.java b/src/main/java/com/nhn/pinpoint/rpc/server/ChannelContext.java index b52b64431..81fa529ef 100644 --- a/src/main/java/com/nhn/pinpoint/rpc/server/ChannelContext.java +++ b/src/main/java/com/nhn/pinpoint/rpc/server/ChannelContext.java @@ -7,7 +7,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.nhn.pinpoint.rpc.util.CopyUtils; -import com.nhn.pinpoint.rpc.util.MapUtils; public class ChannelContext { @@ -97,10 +96,6 @@ public class ChannelContext { stateChangeEventListener.eventPerformed(this, PinpointServerSocketStateCode.ERROR_UNKOWN); } } - - public String getVersion() { - return MapUtils.get(channelProperties, AgentPropertiesType.VERSION.getName(), String.class, "UNKNOWN"); - } public Map getChannelProperties() { return channelProperties; diff --git a/src/main/java/com/nhn/pinpoint/rpc/server/PinpointServerSocket.java b/src/main/java/com/nhn/pinpoint/rpc/server/PinpointServerSocket.java index f19a14407..f9b152dc2 100644 --- a/src/main/java/com/nhn/pinpoint/rpc/server/PinpointServerSocket.java +++ b/src/main/java/com/nhn/pinpoint/rpc/server/PinpointServerSocket.java @@ -3,7 +3,6 @@ package com.nhn.pinpoint.rpc.server; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -556,54 +555,5 @@ public class PinpointServerSocket extends SimpleChannelHandler { return channelContextList; } - public ChannelContext getDuplexChannelContext(String applicationName, String agentId, long startTimeMillis) { - if (applicationName == null) { - return null; - } - - if (agentId == null) { - return null; - } - - if (startTimeMillis <= 0) { - return null; - } - - List channelContextList = new ArrayList(); - - for (Channel channel : channelGroup) { - ChannelContext context = getChannelContext(channel); - - if (context.getCurrentStateCode() == PinpointServerSocketStateCode.RUN_DUPLEX_COMMUNICATION) { - Map agentProperties = context.getChannelProperties(); - - if (!applicationName.equals(agentProperties.get(AgentPropertiesType.APPLICATION_NAME.getName()))) { - continue; - } - - if (!agentId.equals(agentProperties.get(AgentPropertiesType.AGENT_ID.getName()))) { - continue; - } - - if (startTimeMillis != (Long) agentProperties.get(AgentPropertiesType.START_TIMESTAMP.getName())) { - continue; - } - - channelContextList.add(context); - } - } - - if (channelContextList.size() == 0) { - return null; - } - - if (channelContextList.size() == 1) { - return channelContextList.get(0); - } else { - logger.warn("Ambiguous Channel Context {}, {}, {} (Valid Agent list={}).", applicationName, agentId, startTimeMillis, channelContextList); - return null; - } - } - } diff --git a/src/main/java/com/nhn/pinpoint/rpc/server/AgentProperties.java b/src/test/java/com/nhn/pinpoint/rpc/server/AgentProperties.java similarity index 93% rename from src/main/java/com/nhn/pinpoint/rpc/server/AgentProperties.java rename to src/test/java/com/nhn/pinpoint/rpc/server/AgentProperties.java index 08722574c..fbda10801 100644 --- a/src/main/java/com/nhn/pinpoint/rpc/server/AgentProperties.java +++ b/src/test/java/com/nhn/pinpoint/rpc/server/AgentProperties.java @@ -4,9 +4,6 @@ import java.util.Map; import com.nhn.pinpoint.rpc.util.ClassUtils; -/** - * @author koo.taejin - */ public class AgentProperties { public static final String KEY_HOSTNAME = "hostName"; diff --git a/src/main/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java b/src/test/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java similarity index 92% rename from src/main/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java rename to src/test/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java index 2bff81683..6a24a3697 100644 --- a/src/main/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java +++ b/src/test/java/com/nhn/pinpoint/rpc/server/AgentPropertiesType.java @@ -4,9 +4,6 @@ import java.util.Map; import com.nhn.pinpoint.rpc.util.ClassUtils; -/** - * @author koo.taejin - */ public enum AgentPropertiesType { HOSTNAME("hostName", String.class), diff --git a/src/test/java/com/nhn/pinpoint/rpc/server/MessageListenerTest.java b/src/test/java/com/nhn/pinpoint/rpc/server/MessageListenerTest.java index 8b8b34598..f58cfd3dd 100644 --- a/src/test/java/com/nhn/pinpoint/rpc/server/MessageListenerTest.java +++ b/src/test/java/com/nhn/pinpoint/rpc/server/MessageListenerTest.java @@ -150,10 +150,10 @@ public class MessageListenerTest { Thread.sleep(500); - ChannelContext channelContext = ss.getDuplexChannelContext("application", "agent", (Long) params.get(AgentPropertiesType.START_TIMESTAMP.getName())); + ChannelContext channelContext = getChannelContext("application", "agent", (Long) params.get(AgentPropertiesType.START_TIMESTAMP.getName()), ss.getDuplexCommunicationChannelContext()); Assert.assertNotNull(channelContext); - channelContext = ss.getDuplexChannelContext("application", "agent", (Long) params.get(AgentPropertiesType.START_TIMESTAMP.getName()) + 1); + channelContext = getChannelContext("application", "agent", (Long) params.get(AgentPropertiesType.START_TIMESTAMP.getName()) + 1, ss.getDuplexCommunicationChannelContext()); Assert.assertNull(channelContext); socket.close(); @@ -221,5 +221,54 @@ public class MessageListenerTest { } } + + + private ChannelContext getChannelContext(String applicationName, String agentId, long startTimeMillis, List duplexChannelContextList) { + if (applicationName == null) { + return null; + } + + if (agentId == null) { + return null; + } + + if (startTimeMillis <= 0) { + return null; + } + + List channelContextList = new ArrayList(); + + for (ChannelContext eachContext : duplexChannelContextList) { + if (eachContext.getCurrentStateCode() == PinpointServerSocketStateCode.RUN_DUPLEX_COMMUNICATION) { + Map agentProperties = eachContext.getChannelProperties(); + + if (!applicationName.equals(agentProperties.get(AgentPropertiesType.APPLICATION_NAME.getName()))) { + continue; + } + + if (!agentId.equals(agentProperties.get(AgentPropertiesType.AGENT_ID.getName()))) { + continue; + } + + if (startTimeMillis != (Long) agentProperties.get(AgentPropertiesType.START_TIMESTAMP.getName())) { + continue; + } + + channelContextList.add(eachContext); + } + } + + + if (channelContextList.size() == 0) { + return null; + } + + if (channelContextList.size() == 1) { + return channelContextList.get(0); + } else { + logger.warn("Ambiguous Channel Context {}, {}, {} (Valid Agent list={}).", applicationName, agentId, startTimeMillis, channelContextList); + return null; + } + } }