From 55c6a58f37cc1a8e96eb029b9d2993bbeaf29f95 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 25 Apr 2018 21:30:44 +0900 Subject: [PATCH] ing --- .../com/loafle/overflow/container/Container.java | 3 +++ .../configuration/ContainerConfiguration.java | 4 ++-- .../container/server/handler/RPCServerHandler.java | 13 ++++++++++--- .../loafle/overflow/container/service/Service.java | 3 +++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/loafle/overflow/container/Container.java b/src/main/java/com/loafle/overflow/container/Container.java index 506bc32..a7cebc2 100644 --- a/src/main/java/com/loafle/overflow/container/Container.java +++ b/src/main/java/com/loafle/overflow/container/Container.java @@ -7,5 +7,8 @@ public class Container { public static final String PIDFILE_PATH = "CONTAINER_PIDFILE_PATH"; public static final String CRAWLERS = "CONTAINER_CRAWLERS"; public static final String PIPELINE_CHANNEL_HANDLERS = "CONTAINER_PIPELINE_CHANNEL_HANDLERS"; + public static final String RPC_SERVER_CODEC = "CONTAINER_RPC_SERVER_CODEC"; + public static final String RPC_REGISTRY = "CONTAINER_RPC_REGISTRY"; + public static final String RPC_INVOKER = "CONTAINER_RPC_INVOKER"; } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java b/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java index 0a60188..cf1ec10 100644 --- a/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java +++ b/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java @@ -60,7 +60,7 @@ public class ContainerConfiguration { return new LoggingHandler(LogLevel.INFO); } - @Bean + @Bean(Container.RPC_SERVER_CODEC) public RPCServerCodec rpcServerCodec() { if (null != gson) { return new JSONRPCServerCodec(gson); @@ -69,7 +69,7 @@ public class ContainerConfiguration { } } - @Bean + @Bean({Container.RPC_INVOKER, Container.RPC_REGISTRY}) public RPCRegistry rpcRegistry() { return new RPCRegistry(); } diff --git a/src/main/java/com/loafle/overflow/container/server/handler/RPCServerHandler.java b/src/main/java/com/loafle/overflow/container/server/handler/RPCServerHandler.java index a2155d0..d73d80b 100644 --- a/src/main/java/com/loafle/overflow/container/server/handler/RPCServerHandler.java +++ b/src/main/java/com/loafle/overflow/container/server/handler/RPCServerHandler.java @@ -6,12 +6,15 @@ import com.loafle.commons.rpc.protocol.RPCServerRequestCodec; import com.loafle.commons.rpc.registry.RPCInvoker; import com.loafle.commons.server.socket.handler.codec.SocketFrame; import com.loafle.commons.server.socket.handler.codec.TextSocketFrame; +import com.loafle.overflow.container.Container; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; +import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -23,8 +26,10 @@ public class RPCServerHandler extends SimpleChannelInboundHandler { private static final Logger logger = LoggerFactory.getLogger(RPCServerHandler.class); @Autowired + @Qualifier(Container.RPC_SERVER_CODEC) private RPCServerCodec serverCodec; - @Autowired + @Autowired() + @Qualifier(Container.RPC_INVOKER) private RPCInvoker rpcInvoker; public RPCServerHandler() { @@ -33,13 +38,15 @@ public class RPCServerHandler extends SimpleChannelInboundHandler { @Override protected void channelRead0(ChannelHandlerContext ctx, SocketFrame frame) throws Exception { if (frame instanceof TextSocketFrame) { + ByteBuf buff = null; byte[] requestBytes = null; RPCServerRequestCodec requestCodec = null; Object reply = null; RPCException error = null; try { - requestBytes = new byte[frame.content().readableBytes()]; - frame.content().readBytes(requestBytes); + buff = frame.content(); + requestBytes = new byte[buff.readableBytes()]; + buff.getBytes(buff.readerIndex(), requestBytes); requestCodec = this.serverCodec.request(requestBytes); reply = this.rpcInvoker.invoke(requestCodec); diff --git a/src/main/java/com/loafle/overflow/container/service/Service.java b/src/main/java/com/loafle/overflow/container/service/Service.java index af96a6b..d41679c 100644 --- a/src/main/java/com/loafle/overflow/container/service/Service.java +++ b/src/main/java/com/loafle/overflow/container/service/Service.java @@ -6,6 +6,7 @@ import java.util.Map; import com.loafle.commons.rpc.RPCException; import com.loafle.commons.rpc.registry.RPCRegistry; +import com.loafle.overflow.container.Container; import com.loafle.overflow.core.annotation.ProbeAPI; import com.loafle.overflow.core.annotation.RPCService; @@ -14,6 +15,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.annotation.AnnotationUtils; @@ -29,6 +31,7 @@ public class Service implements InitializingBean, ApplicationContextAware { private ApplicationContext applicationContext; @Autowired + @Qualifier(Container.RPC_REGISTRY) private RPCRegistry rpcRegistry; @Override