Skip to content

Commit

Permalink
injvm协议不连接注册中心
Browse files Browse the repository at this point in the history
  • Loading branch information
songxinjianqwe committed Jul 26, 2018
1 parent 33333e9 commit 9176b86
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public class RegistryConfig {
private ServiceRegistry registryInstance;

public void init() {
registryInstance.init();
if(registryInstance != null) {
registryInstance.init();
}
}


public void close() {
registryInstance.close();
if(registryInstance != null) {
registryInstance.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
* @author sinjinsong
* @date 2018/7/7
Expand All @@ -18,8 +19,8 @@
public abstract class AbstractProtocol implements Protocol {
private Map<String, Exporter<?>> exporters = new ConcurrentHashMap<>();
private GlobalConfig globalConfig;


public void init(GlobalConfig globalConfig) {
this.globalConfig = globalConfig;
}
Expand All @@ -42,6 +43,6 @@ public <T> ServiceConfig<T> referLocalService(String interfaceMame) throws RPCEx

@Override
public void close() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @date 2018/7/18
*/
public class InJvmInvoker<T> extends AbstractInvoker<T> {

@Override
public RPCResponse invoke(InvokeParam invokeParam) throws RPCException {
Object serviceBean = getGlobalConfig().getProtocol().referLocalService(invokeParam.getInterfaceName()).getRef();
Expand All @@ -33,5 +33,5 @@ public RPCResponse invoke(InvokeParam invokeParam) throws RPCException {
}
return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ public <T> Exporter<T> export(Invoker<T> invoker, ServiceConfig<T> serviceConfig
exporter.setServiceConfig(serviceConfig);
putExporter(invoker.getInterface(), exporter);
// export
// // injvm 不需要注册到注册中心
// try {
// //TODO refactor this
// serviceConfig.getRegistryConfig().getRegistryInstance().register(InetAddress.getLocalHost().getHostAddress() + ":" + getGlobalConfig().getPort(), serviceConfig.getInterfaceName());
// } catch (UnknownHostException e) {
// throw new RPCException(e,ErrorEnum.READ_LOCALHOST_ERROR,"读取本地Host失败");
// }
return exporter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
import com.sinjinsong.toy.registry.zookeeper.ZkServiceRegistry;
import com.sinjinsong.toy.serialize.api.Serializer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -34,13 +31,11 @@
@EnableConfigurationProperties(RPCProperties.class)
@Configuration
@Slf4j
public class RPCAutoConfiguration implements InitializingBean, ApplicationContextAware {
public class RPCAutoConfiguration implements InitializingBean {
@Autowired
private RPCProperties properties;
private ApplicationContext ctx;
private ExtensionLoader extensionLoader;


@Bean(initMethod = "init", destroyMethod = "close")
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = properties.getRegistry();
Expand All @@ -49,12 +44,14 @@ public RegistryConfig registryConfig() {
}
//TODO 根据type创建ServiceRegistry
//TODO injvm协议不需要连接ZK
ZkServiceRegistry serviceRegistry = new ZkServiceRegistry(registryConfig);
registryConfig.setRegistryInstance(serviceRegistry);
if (ProtocolType.INJVM != ProtocolType.valueOf(properties.getProtocol().getType().toUpperCase())) {
ZkServiceRegistry serviceRegistry = new ZkServiceRegistry(registryConfig);
registryConfig.setRegistryInstance(serviceRegistry);
}
log.info("{}", registryConfig);
return registryConfig;
}

@Bean
public ApplicationConfig applicationConfig() {
ApplicationConfig application = properties.getApplication();
Expand Down Expand Up @@ -151,10 +148,6 @@ public RPCProviderBeanPostProcessor rpcProviderBeanPostProcessor(ApplicationConf
return processor;
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.ctx = applicationContext;
}

@Override
public void afterPropertiesSet() throws Exception {
Expand Down

0 comments on commit 9176b86

Please sign in to comment.