From 952de1410575ea5bee3450954ec88c965db4e426 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 25 Apr 2018 21:56:59 +0900 Subject: [PATCH] ing --- .../loafle/overflow/container/Container.java | 1 + .../configuration/ContainerConfiguration.java | 5 ++++- .../overflow/container/service/Service.java | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/loafle/overflow/container/Container.java b/src/main/java/com/loafle/overflow/container/Container.java index a7cebc2..023bf19 100644 --- a/src/main/java/com/loafle/overflow/container/Container.java +++ b/src/main/java/com/loafle/overflow/container/Container.java @@ -6,6 +6,7 @@ package com.loafle.overflow.container; public class Container { public static final String PIDFILE_PATH = "CONTAINER_PIDFILE_PATH"; public static final String CRAWLERS = "CONTAINER_CRAWLERS"; + public static final String SERVICES = "CONTAINER_SERVICES"; 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"; 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 cf1ec10..12920c4 100644 --- a/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java +++ b/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java @@ -42,6 +42,9 @@ public class ContainerConfiguration { @Qualifier(Container.PIPELINE_CHANNEL_HANDLERS) private List pipelineChannelHandlers; + @Autowired() + private RPCServerHandler rpcServerHandler; + @Autowired(required = false) private Gson gson; @@ -81,7 +84,7 @@ public class ContainerConfiguration { public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline cp = ch.pipeline(); cp.addLast(new SocketServerProtocolHandler(true)); - cp.addLast(new RPCServerHandler()); + cp.addLast(rpcServerHandler); if (null != pipelineChannelHandlers) { for (ChannelHandler channelHandler : pipelineChannelHandlers) { cp.addLast(channelHandler); 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 d41679c..f7ed6d4 100644 --- a/src/main/java/com/loafle/overflow/container/service/Service.java +++ b/src/main/java/com/loafle/overflow/container/service/Service.java @@ -18,13 +18,14 @@ 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.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.stereotype.Component; /** * Service */ -@Component +@Configuration public class Service implements InitializingBean, ApplicationContextAware { private static final Logger logger = LoggerFactory.getLogger(Service.class); @@ -34,20 +35,28 @@ public class Service implements InitializingBean, ApplicationContextAware { @Qualifier(Container.RPC_REGISTRY) private RPCRegistry rpcRegistry; + @Autowired + @Qualifier(Container.SERVICES) + private Map services; + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } + @Bean(Container.SERVICES) + public Map services() { + return this.applicationContext.getBeansWithAnnotation(RPCService.class); + } + @Override public void afterPropertiesSet() throws Exception { - Map services = this.applicationContext.getBeansWithAnnotation(RPCService.class); - if (null == services || 0 == services.size()) { + if (null == this.services || 0 == this.services.size()) { logger.debug("there is not service"); return; } - services.forEach((name, bean) -> { + this.services.forEach((name, bean) -> { this.registerRPCService(bean, name); }); }