From 8b0f6e55bbfeb3e7c320bd77af65192813222fb4 Mon Sep 17 00:00:00 2001 From: emeroad Date: Thu, 11 Oct 2018 17:47:25 +0900 Subject: [PATCH] [#4661] Isolate domain model and transport model - Reduce thrift dependency in CommandService --- .../collector/cluster/ClusterPointRouter.java | 6 +- .../common/util/apache/IntHashMapUtils.java | 15 +++- .../pinpoint/profiler/AgentInfoSender.java | 10 +-- .../HeaderTBaseSerializerProvider.java | 8 +-- .../profiler/receiver/CommandDispatcher.java | 71 ++++++++++--------- .../profiler/receiver/CommandSerializer.java | 12 ++-- .../DefaultProfilerCommandServiceLocator.java | 65 +++++++---------- .../ProfilerCommandLocatorBuilder.java | 31 ++++---- .../receiver/ProfilerCommandService.java | 8 +-- .../ProfilerCommandServiceLocator.java | 18 ++--- .../ProfilerRequestCommandService.java | 10 ++- .../ProfilerSimpleCommandService.java | 10 ++- .../ProfilerStreamCommandService.java | 9 ++- .../service/ActiveThreadCountService.java | 16 ++--- .../service/ActiveThreadDumpService.java | 7 +- .../service/ActiveThreadLightDumpService.java | 11 +-- .../receiver/service/EchoService.java | 11 +-- .../receiver/service/ThreadDumpService.java | 11 +-- .../ProfilerCommandServiceLocatorTest.java | 54 +++++++------- .../pinpoint/io/header/HeaderEntity.java | 10 ++- .../pinpoint/io/request/DefaultMessage.java | 9 +++ .../pinpoint/io/request/EmptyMessage.java | 8 ++- .../pinpoint/thrift/io/TCommandType.java | 12 ++-- .../cluster/DefaultPinpointRouteResponse.java | 12 ++-- .../web/service/AgentServiceImpl.java | 14 ++-- .../websocket/ActiveThreadCountWorker.java | 5 +- 26 files changed, 236 insertions(+), 217 deletions(-) diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRouter.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRouter.java index 5f80c26e2246..d86c8de11eec 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRouter.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRouter.java @@ -20,7 +20,6 @@ import com.navercorp.pinpoint.collector.cluster.route.RequestEvent; import com.navercorp.pinpoint.collector.cluster.route.StreamEvent; import com.navercorp.pinpoint.collector.cluster.route.StreamRouteHandler; -import com.navercorp.pinpoint.io.request.EmptyMessage; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.rpc.MessageListener; import com.navercorp.pinpoint.rpc.PinpointSocket; @@ -173,7 +172,10 @@ private byte[] serialize(TBase result) { } private TBase deserialize(byte[] objectData) { - Message> deserialize = SerializationUtils.deserialize(objectData, commandDeserializerFactory, EmptyMessage.emptyMessage()); + final Message> deserialize = SerializationUtils.deserialize(objectData, commandDeserializerFactory, null); + if (deserialize == null) { + return null; + } return deserialize.getData(); } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMapUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMapUtils.java index 84eed2049891..8a1ba9bbc3e9 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMapUtils.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/apache/IntHashMapUtils.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -36,4 +36,15 @@ public static IntHashMap copy(Map target) { } return copyMap; } + + public static IntHashMap copyShortMap(Map target) { + if (target == null) { + throw new NullPointerException("target must not be null"); + } + final IntHashMap copyMap = new IntHashMap(); + for (Map.Entry entry : target.entrySet()) { + copyMap.put(entry.getKey(), entry.getValue()); + } + return copyMap; + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java index 309cd1275e13..ff6c0189cb25 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java @@ -198,13 +198,13 @@ private boolean sendAgentInfo() { } private boolean getResult(ResponseMessage responseMessage) { - byte[] message = responseMessage.getMessage(); - Message> deserialize = SerializationUtils.deserialize(message, HeaderTBaseDeserializerFactory.DEFAULT_FACTORY, EmptyMessage.INSTANCE); - TBase tbase = deserialize.getData(); - if (tbase == null) { - logger.warn("tbase is null"); + byte[] byteMessage = responseMessage.getMessage(); + Message> message = SerializationUtils.deserialize(byteMessage, HeaderTBaseDeserializerFactory.DEFAULT_FACTORY, null); + if (message == null) { + logger.warn("message is null"); return false; } + final TBase tbase = message.getData(); if (!(tbase instanceof TResult)) { logger.warn("Invalid response : {}", tbase.getClass()); return false; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/HeaderTBaseSerializerProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/HeaderTBaseSerializerProvider.java index 83dddc63c9e5..d351bac75bbd 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/HeaderTBaseSerializerProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/HeaderTBaseSerializerProvider.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,8 +18,6 @@ import com.google.inject.Inject; import com.google.inject.Provider; -import com.navercorp.pinpoint.rpc.client.PinpointClientFactory; -import com.navercorp.pinpoint.thrift.io.AgentEventTBaseLocator; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory; @@ -28,7 +26,7 @@ */ public class HeaderTBaseSerializerProvider implements Provider { - private static final HeaderTBaseSerializerFactory DEFAULT_FACTORY = new HeaderTBaseSerializerFactory(); + private final HeaderTBaseSerializerFactory serializerFactory = new HeaderTBaseSerializerFactory(); @Inject public HeaderTBaseSerializerProvider() { @@ -36,7 +34,7 @@ public HeaderTBaseSerializerProvider() { @Override public HeaderTBaseSerializer get() { - return DEFAULT_FACTORY.createSerializer(); + return serializerFactory.createSerializer(); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java index 69a00b15f7de..921682293383 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandDispatcher.java @@ -17,7 +17,7 @@ package com.navercorp.pinpoint.profiler.receiver; import com.google.inject.Inject; -import com.navercorp.pinpoint.io.request.EmptyMessage; +import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.rpc.MessageListener; import com.navercorp.pinpoint.rpc.PinpointSocket; @@ -43,15 +43,11 @@ public class CommandDispatcher implements MessageListener, ServerStreamChannelMe private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final ProfilerCommandServiceLocator commandServiceLocator; + private final ProfilerCommandServiceLocator, TBase> commandServiceLocator; @Inject - public CommandDispatcher(ProfilerCommandServiceLocator commandServiceLocator) { - if (commandServiceLocator == null) { - throw new NullPointerException("commandServiceLocator must not be null"); - } - - this.commandServiceLocator = commandServiceLocator; + public CommandDispatcher(ProfilerCommandServiceLocator, TBase> commandServiceLocator) { + this.commandServiceLocator = Assert.requireNonNull(commandServiceLocator, "commandServiceLocator must not be null"); } @Override @@ -63,49 +59,58 @@ public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) { public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) { logger.info("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress()); - final Message> deserialize = SerializationUtils.deserialize(requestPacket.getPayload(), CommandSerializer.DESERIALIZER_FACTORY, EmptyMessage.INSTANCE); - final TBase request = deserialize.getData(); - logger.debug("handleRequest request:{}, remote:{}", request, pinpointSocket.getRemoteAddress()); + final Message> message = SerializationUtils.deserialize(requestPacket.getPayload(), CommandSerializer.DESERIALIZER_FACTORY, null); + if (logger.isDebugEnabled()) { + logger.debug("handleRequest request:{}, remote:{}", message, pinpointSocket.getRemoteAddress()); + } + + final TBase response = processRequest(message); + + final byte[] payload = SerializationUtils.serialize(response, CommandSerializer.SERIALIZER_FACTORY, null); + if (payload != null) { + pinpointSocket.response(requestPacket.getRequestId(), payload); + } + } - TBase response; - if (request == null) { + private TBase processRequest(Message> message) { + if (message == null) { final TResult tResult = new TResult(false); tResult.setMessage("Unsupported ServiceTypeInfo."); - response = tResult; - } else { - final ProfilerRequestCommandService service = commandServiceLocator.getRequestService(request); - if (service == null) { - TResult tResult = new TResult(false); - tResult.setMessage("Can't find suitable service(" + request + ")."); - - response = tResult; - } else { - response = service.requestCommandService(request); - } + return tResult; } - final byte[] payload = SerializationUtils.serialize(response, CommandSerializer.SERIALIZER_FACTORY, null); - if (payload != null) { - pinpointSocket.response(requestPacket.getRequestId(), payload); + final short type = message.getHeader().getType(); + final ProfilerRequestCommandService, TBase> service = commandServiceLocator.getRequestService(type); + if (service == null) { + TResult tResult = new TResult(false); + tResult.setMessage("Can't find suitable service(" + message + ")."); + + return tResult; } + + final TBase request = message.getData(); + final TBase tResponse = service.requestCommandService(request); + return tResponse; } + @Override public StreamCode handleStreamCreate(ServerStreamChannelContext streamChannelContext, StreamCreatePacket packet) { logger.info("MessageReceived handleStreamCreate {} {}", packet, streamChannelContext); - final Message> deserialize = SerializationUtils.deserialize(packet.getPayload(), CommandSerializer.DESERIALIZER_FACTORY, EmptyMessage.INSTANCE); - final TBase request = deserialize.getData(); - if (request == null) { + final Message> message = SerializationUtils.deserialize(packet.getPayload(), CommandSerializer.DESERIALIZER_FACTORY, null); + if (message == null) { return StreamCode.TYPE_UNKNOWN; } - - final ProfilerStreamCommandService service = commandServiceLocator.getStreamService(request); + + final short type = message.getHeader().getType(); + final ProfilerStreamCommandService> service = commandServiceLocator.getStreamService(type); if (service == null) { return StreamCode.TYPE_UNSUPPORT; } - + + final TBase request = message.getData(); return service.streamCommandService(request, streamChannelContext); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandSerializer.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandSerializer.java index 325c110bf4de..d9005b667aeb 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandSerializer.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/CommandSerializer.java @@ -1,11 +1,11 @@ /* - * Copyright 2017 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,13 +18,17 @@ import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseDeserializerFactory; import com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseSerializerFactory; +import com.navercorp.pinpoint.thrift.io.DeserializerFactory; +import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer; +import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; +import com.navercorp.pinpoint.thrift.io.SerializerFactory; /** * @author Taejin Koo */ public class CommandSerializer { - public static final CommandHeaderTBaseSerializerFactory SERIALIZER_FACTORY = new CommandHeaderTBaseSerializerFactory(); - public static final CommandHeaderTBaseDeserializerFactory DESERIALIZER_FACTORY = new CommandHeaderTBaseDeserializerFactory(); + public static final SerializerFactory SERIALIZER_FACTORY = new CommandHeaderTBaseSerializerFactory(); + public static final DeserializerFactory DESERIALIZER_FACTORY = new CommandHeaderTBaseDeserializerFactory(); } \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java index b1314a24bab5..ce7f0bb66ec7 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/DefaultProfilerCommandServiceLocator.java @@ -1,11 +1,11 @@ /* - * Copyright 2017 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,9 @@ package com.navercorp.pinpoint.profiler.receiver; -import com.navercorp.pinpoint.thrift.io.TCommandType; -import org.apache.thrift.TBase; +import com.navercorp.pinpoint.common.util.apache.IntHashMap; +import com.navercorp.pinpoint.common.util.apache.IntHashMapUtils; -import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -29,27 +28,24 @@ */ public class DefaultProfilerCommandServiceLocator implements ProfilerCommandServiceLocator { - private final Map, ProfilerCommandService> profilerCommandServiceRepository; + private final IntHashMap profilerCommandServiceRepository; + private final Set codeSet; DefaultProfilerCommandServiceLocator(ProfilerCommandLocatorBuilder builder) { - this.profilerCommandServiceRepository = Collections.unmodifiableMap(builder.getProfilerCommandServiceRepository()); + Map commandServiceRepository = builder.getProfilerCommandServiceRepository(); + this.profilerCommandServiceRepository = IntHashMapUtils.copyShortMap(commandServiceRepository); + this.codeSet = buildCodeSet(commandServiceRepository); } @Override - public ProfilerCommandService getService(TBase tBase) { - if (tBase == null) { - return null; - } - return profilerCommandServiceRepository.get(tBase.getClass()); + public ProfilerCommandService getService(short commandCode) { + return profilerCommandServiceRepository.get(commandCode); } @Override - public ProfilerSimpleCommandService getSimpleService(TBase tBase) { - if (tBase == null) { - return null; - } + public ProfilerSimpleCommandService getSimpleService(short commandCode) { - final ProfilerCommandService service = profilerCommandServiceRepository.get(tBase.getClass()); + final ProfilerCommandService service = profilerCommandServiceRepository.get(commandCode); if (service instanceof ProfilerSimpleCommandService) { return (ProfilerSimpleCommandService) service; } @@ -58,12 +54,9 @@ public ProfilerSimpleCommandService getSimpleService(TBase tBase) { } @Override - public ProfilerRequestCommandService getRequestService(TBase tBase) { - if (tBase == null) { - return null; - } + public ProfilerRequestCommandService getRequestService(short commandCode) { - final ProfilerCommandService service = profilerCommandServiceRepository.get(tBase.getClass()); + final ProfilerCommandService service = profilerCommandServiceRepository.get(commandCode); if (service instanceof ProfilerRequestCommandService) { return (ProfilerRequestCommandService) service; } @@ -72,12 +65,9 @@ public ProfilerRequestCommandService getRequestService(TBase tBase) { } @Override - public ProfilerStreamCommandService getStreamService(TBase tBase) { - if (tBase == null) { - return null; - } + public ProfilerStreamCommandService getStreamService(short commandCode) { - final ProfilerCommandService service = profilerCommandServiceRepository.get(tBase.getClass()); + final ProfilerCommandService service = profilerCommandServiceRepository.get(commandCode); if (service instanceof ProfilerStreamCommandService) { return (ProfilerStreamCommandService) service; } @@ -85,23 +75,18 @@ public ProfilerStreamCommandService getStreamService(TBase tBase) { return null; } - @Override - public Set> getCommandServiceClasses() { - return profilerCommandServiceRepository.keySet(); + int getCommandServiceSize() { + return profilerCommandServiceRepository.size(); } @Override public Set getCommandServiceCodes() { - Set commandServiceCodes = new HashSet(profilerCommandServiceRepository.size()); - - Set> clazzSet = profilerCommandServiceRepository.keySet(); - for (Class clazz : clazzSet) { - TCommandType commandType = TCommandType.getType(clazz); - if (commandType != null) { - commandServiceCodes.add(commandType.getCode()); - } - } - return commandServiceCodes; + return this.codeSet; + } + + private Set buildCodeSet(Map codes) { + return new HashSet(codes.keySet()); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandLocatorBuilder.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandLocatorBuilder.java index c6087c2b87a5..085a1e76be48 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandLocatorBuilder.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandLocatorBuilder.java @@ -1,11 +1,11 @@ /* - * Copyright 2017 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.profiler.receiver; -import org.apache.thrift.TBase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,10 +29,10 @@ public class ProfilerCommandLocatorBuilder { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final Map, ProfilerCommandService> profilerCommandServiceRepository; + private final Map profilerCommandServiceRepository; public ProfilerCommandLocatorBuilder() { - profilerCommandServiceRepository = new HashMap, ProfilerCommandService>(); + this.profilerCommandServiceRepository = new HashMap(); } public void addService(ProfilerCommandServiceGroup serviceGroup) { @@ -50,33 +49,29 @@ public boolean addService(ProfilerCommandService service) { if (service == null) { throw new NullPointerException("service must not be null"); } - return addService(service.getCommandClazz(), service); + return addService(service.getCommandServiceCode(), service); } - public boolean addService(Class clazz, ProfilerCommandService service) { - if (clazz == null) { - throw new NullPointerException("clazz must not be null"); - } + boolean addService(short commandCode, ProfilerCommandService service) { if (service == null) { throw new NullPointerException("service must not be null"); } - boolean hasValue = profilerCommandServiceRepository.containsKey(clazz); - if (!hasValue) { - profilerCommandServiceRepository.put(clazz, service); - return true; - } else { - ProfilerCommandService registeredService = profilerCommandServiceRepository.get(clazz); - logger.warn("Already Register ServiceTypeInfo:{}, RegisteredService:{}.", clazz.getName(), registeredService); + final ProfilerCommandService exist = profilerCommandServiceRepository.get(commandCode); + if (exist != null) { + logger.warn("Already Register CommandCode:{}, RegisteredService:{}.", commandCode, exist); return false; } + + profilerCommandServiceRepository.put(commandCode, service); + return true; } public ProfilerCommandServiceLocator build() { return new DefaultProfilerCommandServiceLocator(this); } - protected Map, ProfilerCommandService> getProfilerCommandServiceRepository() { + protected Map getProfilerCommandServiceRepository() { return profilerCommandServiceRepository; } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandService.java index b3164dc6f560..df67bb840346 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandService.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,11 @@ package com.navercorp.pinpoint.profiler.receiver; -import org.apache.thrift.TBase; - /** * @author koo.taejin */ public interface ProfilerCommandService { - Class getCommandClazz(); + short getCommandServiceCode(); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java index 75dc61628f27..a221a8103fc3 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocator.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,24 +16,20 @@ package com.navercorp.pinpoint.profiler.receiver; -import org.apache.thrift.TBase; - import java.util.Set; /** * @author koo.taejin */ -public interface ProfilerCommandServiceLocator { - - ProfilerCommandService getService(TBase tBase); +public interface ProfilerCommandServiceLocator { - ProfilerSimpleCommandService getSimpleService(TBase tBase); + ProfilerCommandService getService(short commandCode); - ProfilerRequestCommandService getRequestService(TBase tBase); + ProfilerSimpleCommandService getSimpleService(short commandCode); - ProfilerStreamCommandService getStreamService(TBase tBase); + ProfilerRequestCommandService getRequestService(short commandCode); - Set> getCommandServiceClasses(); + ProfilerStreamCommandService getStreamService(short commandCode); Set getCommandServiceCodes(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java index a8a3ed035ca1..a72201ccb357 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerRequestCommandService.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,11 @@ package com.navercorp.pinpoint.profiler.receiver; -import org.apache.thrift.TBase; - /** * @author koo.taejin */ -public interface ProfilerRequestCommandService extends ProfilerCommandService { +public interface ProfilerRequestCommandService extends ProfilerCommandService { - TBase requestCommandService(TBase tBase); + RES requestCommandService(REQ request); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java index 3e2cbf38b16c..5ae1c1fbdc78 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerSimpleCommandService.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,11 @@ package com.navercorp.pinpoint.profiler.receiver; -import org.apache.thrift.TBase; - /** * @author koo.taejin */ -public interface ProfilerSimpleCommandService extends ProfilerCommandService { +public interface ProfilerSimpleCommandService extends ProfilerCommandService { - void simpleCommandService(TBase tbase); + void simpleCommandService(REQ request); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java index 8247adea843a..3c9b738cddc1 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/ProfilerStreamCommandService.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,12 +17,11 @@ package com.navercorp.pinpoint.profiler.receiver; import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; -import org.apache.thrift.TBase; import com.navercorp.pinpoint.rpc.stream.ServerStreamChannelContext; -public interface ProfilerStreamCommandService extends ProfilerCommandService { +public interface ProfilerStreamCommandService extends ProfilerCommandService { - StreamCode streamCommandService(TBase tBase, ServerStreamChannelContext streamChannelContext); + StreamCode streamCommandService(REQ request, ServerStreamChannelContext streamChannelContext); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java index af9d95622b95..1cd5a3e4d0d7 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadCountService.java @@ -1,11 +1,11 @@ /* - * Copyright 2017 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,8 +28,8 @@ import com.navercorp.pinpoint.rpc.stream.StreamChannelStateChangeEventHandler; import com.navercorp.pinpoint.rpc.stream.StreamChannelStateCode; import com.navercorp.pinpoint.rpc.util.TimerFactory; -import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCount; import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes; +import com.navercorp.pinpoint.thrift.io.TCommandType; import com.navercorp.pinpoint.thrift.util.SerializationUtils; import org.apache.thrift.TBase; import org.jboss.netty.util.HashedWheelTimer; @@ -46,7 +46,7 @@ /** * @author Taejin Koo */ -public class ActiveThreadCountService implements ProfilerRequestCommandService, ProfilerStreamCommandService { +public class ActiveThreadCountService implements ProfilerRequestCommandService, TBase>, ProfilerStreamCommandService> { private static final long DEFAULT_FLUSH_DELAY = 1000; @@ -76,12 +76,12 @@ public ActiveThreadCountService(ActiveTraceRepository activeTraceRepository, lon } @Override - public Class getCommandClazz() { - return TCmdActiveThreadCount.class; + public short getCommandServiceCode() { + return TCommandType.ACTIVE_THREAD_COUNT.getCode(); } @Override - public TBase requestCommandService(TBase activeThreadCountObject) { + public TBase requestCommandService(TBase activeThreadCountObject) { if (activeThreadCountObject == null) { throw new NullPointerException("activeThreadCountObject must not be null."); } @@ -90,7 +90,7 @@ public Class getCommandClazz() { } @Override - public StreamCode streamCommandService(TBase tBase, ServerStreamChannelContext streamChannelContext) { + public StreamCode streamCommandService(TBase tBase, ServerStreamChannelContext streamChannelContext) { logger.info("streamCommandService object:{}, streamChannelContext:{}", tBase, streamChannelContext); streamChannelContext.getStreamChannel().addStateChangeEventHandler(stateChangeEventHandler); return StreamCode.OK; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java index 51e1e6e09141..758413fb842c 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadDumpService.java @@ -24,6 +24,7 @@ import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDump; import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadDumpRes; import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; +import com.navercorp.pinpoint.thrift.io.TCommandType; import org.apache.thrift.TBase; import java.lang.management.ThreadInfo; @@ -34,7 +35,7 @@ /** * @author Taejin Koo */ -public class ActiveThreadDumpService implements ProfilerRequestCommandService { +public class ActiveThreadDumpService implements ProfilerRequestCommandService, TBase> { static final String JAVA = "JAVA"; @@ -100,8 +101,8 @@ private TActiveThreadDump createTActiveThreadDump(ThreadDump threadDump) { } @Override - public Class getCommandClazz() { - return TCmdActiveThreadDump.class; + public short getCommandServiceCode() { + return TCommandType.ACTIVE_THREAD_DUMP.getCode(); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java index 7d42ba41d79a..d184a3b0805b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ActiveThreadLightDumpService.java @@ -1,11 +1,11 @@ /* - * Copyright 2016 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDump; import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadLightDumpRes; import com.navercorp.pinpoint.thrift.dto.command.TThreadLightDump; +import com.navercorp.pinpoint.thrift.io.TCommandType; import org.apache.thrift.TBase; import java.lang.management.ThreadInfo; @@ -35,7 +36,7 @@ /** * @author Taejin Koo */ -public class ActiveThreadLightDumpService implements ProfilerRequestCommandService { +public class ActiveThreadLightDumpService implements ProfilerRequestCommandService, TBase> { private final ActiveThreadDumpCoreService activeThreadDump; @@ -111,8 +112,8 @@ private TActiveThreadLightDump createActiveThreadDump(ThreadDump threadDump) { } @Override - public Class getCommandClazz() { - return TCmdActiveThreadLightDump.class; + public short getCommandServiceCode() { + return TCommandType.ACTIVE_THREAD_LIGHT_DUMP.getCode(); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java index d94589977135..bea7317b5e9a 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/EchoService.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.receiver.service; +import com.navercorp.pinpoint.thrift.io.TCommandType; import org.apache.thrift.TBase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +27,7 @@ /** * @author koo.taejin */ -public class EchoService implements ProfilerRequestCommandService { +public class EchoService implements ProfilerRequestCommandService, TBase> { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Override @@ -38,8 +39,8 @@ public class EchoService implements ProfilerRequestCommandService { } @Override - public Class getCommandClazz() { - return TCommandEcho.class; + public short getCommandServiceCode() { + return TCommandType.ECHO.getCode(); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java index 84e7b577c56f..466da282a978 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/receiver/service/ThreadDumpService.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; import com.navercorp.pinpoint.thrift.dto.command.TThreadDumpType; import com.navercorp.pinpoint.thrift.dto.command.TThreadState; +import com.navercorp.pinpoint.thrift.io.TCommandType; import org.apache.thrift.TBase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +42,7 @@ /** * @author koo.taejin */ -public class ThreadDumpService implements ProfilerRequestCommandService { +public class ThreadDumpService implements ProfilerRequestCommandService, TBase> { private static final Set THREAD_STATES = EnumSet.allOf(TThreadState.class); @@ -180,8 +181,8 @@ private ThreadInfo[] getAllThreadInfo() { } @Override - public Class getCommandClazz() { - return TCommandThreadDump.class; + public short getCommandServiceCode() { + return TCommandType.THREAD_DUMP.getCode(); } } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java index 90abefcfaba2..84f0aaf13768 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/receiver/ProfilerCommandServiceLocatorTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2017 NAVER Corp. + * Copyright 2018 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +19,6 @@ import com.navercorp.pinpoint.profiler.receiver.service.EchoService; import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; import com.navercorp.pinpoint.rpc.stream.ServerStreamChannelContext; -import com.navercorp.pinpoint.thrift.dto.TResult; -import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; -import com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer; import com.navercorp.pinpoint.thrift.io.TCommandType; import org.apache.thrift.TBase; import org.junit.Assert; @@ -54,13 +51,13 @@ public void throwNullTest2() throws Exception { @Test(expected = NullPointerException.class) public void throwNullTest3() throws Exception { ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(null, null); + builder.addService((short) -1, null); } @Test(expected = NullPointerException.class) public void throwNullTest4() throws Exception { ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); - builder.addService(TResult.class, null); + builder.addService(TCommandType.RESULT.getCode(), null); } @Test @@ -68,10 +65,10 @@ public void returnNullTest() throws Exception { ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); ProfilerCommandServiceLocator commandServiceLocator = builder.build(); - Assert.assertNull(commandServiceLocator.getService(null)); - Assert.assertNull(commandServiceLocator.getSimpleService(null)); - Assert.assertNull(commandServiceLocator.getRequestService(null)); - Assert.assertNull(commandServiceLocator.getStreamService(null)); + Assert.assertNull(commandServiceLocator.getService((short) -1)); + Assert.assertNull(commandServiceLocator.getSimpleService((short) -1)); + Assert.assertNull(commandServiceLocator.getRequestService((short) -1)); + Assert.assertNull(commandServiceLocator.getStreamService((short) -1)); } @Test @@ -79,13 +76,13 @@ public void basicFunctionTest1() throws Exception { ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); builder.addService(new EchoService()); builder.addService(new EchoService()); - ProfilerCommandServiceLocator commandServiceLocator = builder.build(); + DefaultProfilerCommandServiceLocator commandServiceLocator = (DefaultProfilerCommandServiceLocator) builder.build(); - TCommandEcho commandEcho = new TCommandEcho(); + short commandEcho = TCommandType.ECHO.getCode(); - Assert.assertEquals(1, commandServiceLocator.getCommandServiceClasses().size()); + Assert.assertEquals(1, commandServiceLocator.getCommandServiceSize()); Assert.assertEquals(1, commandServiceLocator.getCommandServiceCodes().size()); - Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(TCommandType.getType(commandEcho.getClass()).getCode())); + Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(commandEcho)); Assert.assertNotNull(commandServiceLocator.getService(commandEcho)); Assert.assertNotNull(commandServiceLocator.getRequestService(commandEcho)); @@ -98,15 +95,16 @@ public void basicFunctionTest1() throws Exception { public void basicFunctionTest2() throws Exception { ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder(); builder.addService(new MockCommandServiceGroup()); - ProfilerCommandServiceLocator commandServiceLocator = builder.build(); + DefaultProfilerCommandServiceLocator commandServiceLocator = (DefaultProfilerCommandServiceLocator) builder.build(); + + short commandResult = TCommandType.RESULT.getCode(); - TResult commandResult = new TResult(); - TCommandTransfer commandTransfer = new TCommandTransfer(); + short commandTransfer = TCommandType.TRANSFER.getCode(); - Assert.assertEquals(2, commandServiceLocator.getCommandServiceClasses().size()); + Assert.assertEquals(2, commandServiceLocator.getCommandServiceSize()); Assert.assertEquals(2, commandServiceLocator.getCommandServiceCodes().size()); - Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(TCommandType.getType(commandResult.getClass()).getCode())); - Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(TCommandType.getType(commandTransfer.getClass()).getCode())); + Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(commandResult)); + Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(commandTransfer)); Assert.assertNotNull(commandServiceLocator.getService(commandResult)); Assert.assertNotNull(commandServiceLocator.getSimpleService(commandResult)); @@ -119,7 +117,7 @@ public void basicFunctionTest2() throws Exception { Assert.assertNull(commandServiceLocator.getRequestService(commandTransfer)); } - private static class MockSimpleCommandService implements ProfilerSimpleCommandService { + private static class MockSimpleCommandService implements ProfilerSimpleCommandService> { @Override public void simpleCommandService(TBase tbase) { @@ -127,22 +125,22 @@ public void simpleCommandService(TBase tbase) { } @Override - public Class getCommandClazz() { - return TResult.class; + public short getCommandServiceCode() { + return TCommandType.RESULT.getCode(); } } - private static class MockStreamCommandService implements ProfilerStreamCommandService { + private static class MockStreamCommandService implements ProfilerStreamCommandService> { @Override - public StreamCode streamCommandService(TBase tBase, ServerStreamChannelContext streamChannelContext) { + public StreamCode streamCommandService(TBase tBase, ServerStreamChannelContext streamChannelContext) { return StreamCode.OK; } @Override - public Class getCommandClazz() { - return TCommandTransfer.class; + public short getCommandServiceCode() { + return TCommandType.TRANSFER.getCode(); } } diff --git a/thrift/src/main/java/com/navercorp/pinpoint/io/header/HeaderEntity.java b/thrift/src/main/java/com/navercorp/pinpoint/io/header/HeaderEntity.java index 96de2b429a6a..c109fea01aef 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/io/header/HeaderEntity.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/io/header/HeaderEntity.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.io.header; import java.util.Collections; -import java.util.HashMap; import java.util.Map; /** @@ -24,7 +23,7 @@ */ public class HeaderEntity { - public static final HeaderEntity EMPTY_HEADER_ENTITY = new HeaderEntity(new HashMap(0)); + public static final HeaderEntity EMPTY_HEADER_ENTITY = new HeaderEntity(Collections.emptyMap()); private final Map entity; @@ -43,4 +42,11 @@ public String getEntity(String key) { public Map getEntityAll() { return entity; } + + @Override + public String toString() { + return "HeaderEntity{" + + "entity=" + entity + + '}'; + } } diff --git a/thrift/src/main/java/com/navercorp/pinpoint/io/request/DefaultMessage.java b/thrift/src/main/java/com/navercorp/pinpoint/io/request/DefaultMessage.java index 9bb052f95003..81e5a58c392b 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/io/request/DefaultMessage.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/io/request/DefaultMessage.java @@ -54,4 +54,13 @@ public HeaderEntity getHeaderEntity() { public T getData() { return data; } + + @Override + public String toString() { + return "DefaultMessage{" + + "header=" + header + + ", headerEntity=" + headerEntity + + ", data=" + data + + '}'; + } } diff --git a/thrift/src/main/java/com/navercorp/pinpoint/io/request/EmptyMessage.java b/thrift/src/main/java/com/navercorp/pinpoint/io/request/EmptyMessage.java index be9b07f04fb7..f28d7cb5d71d 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/io/request/EmptyMessage.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/io/request/EmptyMessage.java @@ -18,20 +18,24 @@ import com.navercorp.pinpoint.io.header.Header; import com.navercorp.pinpoint.io.header.HeaderEntity; +import com.navercorp.pinpoint.io.header.v1.HeaderV1; /** * @author Woonduk Kang(emeroad) */ public class EmptyMessage implements Message { public static final Message INSTANCE = new EmptyMessage(); + + private static final Header EMPTY_HEADER = new HeaderV1((short) -1); + @Override public Header getHeader() { - return null; + return EMPTY_HEADER; } @Override public HeaderEntity getHeaderEntity() { - return null; + return HeaderEntity.EMPTY_HEADER_ENTITY; } @Override diff --git a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandType.java b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandType.java index 0e6e76bbeb12..82c425710166 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandType.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandType.java @@ -16,8 +16,6 @@ package com.navercorp.pinpoint.thrift.io; -import com.navercorp.pinpoint.io.header.Header; -import com.navercorp.pinpoint.io.header.v1.HeaderV1; import com.navercorp.pinpoint.io.util.BodyFactory; import com.navercorp.pinpoint.thrift.dto.command.*; import org.apache.thrift.TBase; @@ -41,6 +39,7 @@ public enum TCommandType { return new TResult(); } }), + TRANSFER((short) 700, new BodyFactory>() { @Override public TBase getObject() { @@ -53,12 +52,14 @@ public enum TCommandType { return new TCommandTransferResponse(); } }), + ECHO((short) 710, new BodyFactory>() { @Override public TBase getObject() { return new TCommandEcho(); } }), + THREAD_DUMP((short) 720, new BodyFactory>() { @Override public TBase getObject() { @@ -71,6 +72,7 @@ public enum TCommandType { return new TCommandThreadDumpResponse(); } }), + ACTIVE_THREAD_COUNT((short) 730, new BodyFactory>() { @Override public TBase getObject() { @@ -83,6 +85,7 @@ public enum TCommandType { return new TCmdActiveThreadCountRes(); } }), + ACTIVE_THREAD_DUMP((short) 740, new BodyFactory>() { @Override public TBase getObject() { @@ -95,6 +98,7 @@ public enum TCommandType { return new TCmdActiveThreadDumpRes(); } }), + ACTIVE_THREAD_LIGHT_DUMP((short) 750, new BodyFactory>() { @Override public TBase getObject() { @@ -129,14 +133,12 @@ public Class getClazz() { return clazz; } - protected boolean isInstanceOf(Object value) { - return this.clazz.isInstance(value); - } public BodyFactory> getBodyFactory() { return bodyFactory; } + @Deprecated public static TCommandType getType(Class clazz) { for (TCommandType commandType : TCOMMAND_TYPES) { if (commandType.getClazz() == clazz) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/DefaultPinpointRouteResponse.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/DefaultPinpointRouteResponse.java index c4e9953403b3..c05c771c9943 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/DefaultPinpointRouteResponse.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/DefaultPinpointRouteResponse.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.web.cluster; -import com.navercorp.pinpoint.io.request.EmptyMessage; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse; import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; @@ -49,7 +48,7 @@ public void parse(DeserializerFactory commandDeserializ return; } - TBase object = deserialize(commandDeserializerFactory, payload, EmptyMessage.emptyMessage()); + TBase object = deserialize(commandDeserializerFactory, payload, null); if (object == null) { routeResult = TRouteResult.NOT_SUPPORTED_RESPONSE; @@ -62,7 +61,7 @@ public void parse(DeserializerFactory commandDeserializ this.routeResult = routeResult; } - response = deserialize(commandDeserializerFactory, commandResponse.getPayload(), EmptyMessage.emptyMessage()); + response = deserialize(commandDeserializerFactory, commandResponse.getPayload(), null); } else { routeResult = TRouteResult.UNKNOWN; response = object; @@ -112,8 +111,11 @@ private void assertParsed() { } private TBase deserialize(DeserializerFactory commandDeserializerFactory, byte[] objectData, Message> defaultValue) { - Message> deserialize = SerializationUtils.deserialize(objectData, commandDeserializerFactory, defaultValue); - return deserialize.getData(); + final Message> message = SerializationUtils.deserialize(objectData, commandDeserializerFactory, defaultValue); + if (message == null) { + return null; + } + return message.getData(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java index 0893edb88eb3..a074b835f706 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java @@ -354,14 +354,20 @@ public byte[] serializeRequest(TBase tBase, byte[] defaultValue) { @Override public TBase deserializeResponse(byte[] objectData) throws TException { - Message> deserialize = SerializationUtils.deserialize(objectData, commandDeserializerFactory); - return deserialize.getData(); + Message> message = SerializationUtils.deserialize(objectData, commandDeserializerFactory); + if (message == null) { + return null; + } + return message.getData(); } @Override public TBase deserializeResponse(byte[] objectData, Message> defaultValue) { - Message> deserialize = SerializationUtils.deserialize(objectData, commandDeserializerFactory, defaultValue); - return deserialize.getData(); + Message> message = SerializationUtils.deserialize(objectData, commandDeserializerFactory, defaultValue); + if (message == null) { + return null; + } + return message.getData(); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java b/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java index bbcbab1346d6..19a260866986 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.web.websocket; -import com.navercorp.pinpoint.io.request.EmptyMessage; import com.navercorp.pinpoint.rpc.packet.stream.StreamClosePacket; import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; import com.navercorp.pinpoint.rpc.packet.stream.StreamCreateFailPacket; @@ -213,7 +212,7 @@ private class MessageListener implements ClientStreamChannelMessageListener { public void handleStreamData(ClientStreamChannelContext streamChannelContext, StreamResponsePacket packet) { LOGGING.handleStreamData(streamChannelContext, packet); - TBase response = agentService.deserializeResponse(packet.getPayload(), EmptyMessage.emptyMessage()); + TBase response = agentService.deserializeResponse(packet.getPayload(), null); AgentActiveThreadCount activeThreadCount = getAgentActiveThreadCount(response); responseAggregator.response(activeThreadCount); } @@ -227,7 +226,7 @@ public void handleStreamClose(ClientStreamChannelContext streamChannelContext, S private AgentActiveThreadCount getAgentActiveThreadCount(TBase routeResponse) { if (routeResponse instanceof TCommandTransferResponse) { byte[] payload = ((TCommandTransferResponse) routeResponse).getPayload(); - TBase activeThreadCountResponse = agentService.deserializeResponse(payload, EmptyMessage.emptyMessage()); + TBase activeThreadCountResponse = agentService.deserializeResponse(payload, null); AgentActiveThreadCountFactory factory = new AgentActiveThreadCountFactory(); factory.setAgentId(agentId);