This commit is contained in:
crusader 2018-04-25 21:56:59 +09:00
parent 55c6a58f37
commit 952de14105
3 changed files with 19 additions and 6 deletions

View File

@ -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";

View File

@ -42,6 +42,9 @@ public class ContainerConfiguration {
@Qualifier(Container.PIPELINE_CHANNEL_HANDLERS)
private List<ChannelHandler> 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);

View File

@ -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<String, Object> services;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@Bean(Container.SERVICES)
public Map<String, Object> services() {
return this.applicationContext.getBeansWithAnnotation(RPCService.class);
}
@Override
public void afterPropertiesSet() throws Exception {
Map<String, Object> 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);
});
}