This commit is contained in:
crusader 2018-04-25 22:08:31 +09:00
parent 952de14105
commit 5c82049f48

View File

@ -18,45 +18,42 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; 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.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
/** /**
* Service * Service
*/ */
@Configuration @Component
public class Service implements InitializingBean, ApplicationContextAware { public class Service implements InitializingBean, ApplicationContextAware {
private static final Logger logger = LoggerFactory.getLogger(Service.class); private static final Logger logger = LoggerFactory.getLogger(Service.class);
public static final Class<?>[] OrderedServices = {
ContainerProbeService.class,
ContainerSensorConfigService.class,
ContainerCrawlerService.class,
};
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired @Autowired
@Qualifier(Container.RPC_REGISTRY) @Qualifier(Container.RPC_REGISTRY)
private RPCRegistry rpcRegistry; private RPCRegistry rpcRegistry;
@Autowired
@Qualifier(Container.SERVICES)
private Map<String, Object> services;
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
@Bean(Container.SERVICES)
public Map<String, Object> services() {
return this.applicationContext.getBeansWithAnnotation(RPCService.class);
}
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
if (null == this.services || 0 == this.services.size()) { Map<String, Object> services = this.applicationContext.getBeansWithAnnotation(RPCService.class);
if (null == services || 0 == services.size()) {
logger.debug("there is not service"); logger.debug("there is not service");
return; return;
} }
this.services.forEach((name, bean) -> { services.forEach((name, bean) -> {
this.registerRPCService(bean, name); this.registerRPCService(bean, name);
}); });
} }