Commit b7eea6f2 by huangfusuper

Rpc插件 客户端源码解析

parent 4a24f8ee
...@@ -23,4 +23,6 @@ spring: ...@@ -23,4 +23,6 @@ spring:
host: 10.0.120.218 host: 10.0.120.218
port: 6379 port: 6379
password: password:
authentication:
user:
pub-key: "huangfu"
...@@ -63,7 +63,7 @@ public class RegistryClient { ...@@ -63,7 +63,7 @@ public class RegistryClient {
registryThread.setDaemon(true); registryThread.setDaemon(true);
registryThread.start(); registryThread.start();
// discovery thread // 发现线程 这一步猜测 应该是为了不间断的查询数据库 并且发现线程
discoveryThread = new Thread(new Runnable() { discoveryThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -230,7 +230,7 @@ public class RegistryClient { ...@@ -230,7 +230,7 @@ public class RegistryClient {
// discovery mult // discovery mult
Map<String, TreeSet<String>> updatedData = new HashMap<>(); Map<String, TreeSet<String>> updatedData = new HashMap<>();
//这一步似乎查询了什么
Map<String, TreeSet<String>> keyValueListData = registryBaseClient.discovery(keys); Map<String, TreeSet<String>> keyValueListData = registryBaseClient.discovery(keys);
if (keyValueListData!=null) { if (keyValueListData!=null) {
for (String keyItem: keyValueListData.keySet()) { for (String keyItem: keyValueListData.keySet()) {
......
...@@ -47,7 +47,7 @@ public abstract class ServiceRegistry { ...@@ -47,7 +47,7 @@ public abstract class ServiceRegistry {
public abstract boolean remove(Set<String> keys, String value); public abstract boolean remove(Set<String> keys, String value);
/** /**
* discovery services, for mult *多种发现服务
* *
* @param keys * @param keys
* @return * @return
......
...@@ -51,6 +51,7 @@ public class RpcSpringInvokerFactory extends InstantiationAwareBeanPostProcessor ...@@ -51,6 +51,7 @@ public class RpcSpringInvokerFactory extends InstantiationAwareBeanPostProcessor
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
// start invoker factory // start invoker factory
rpcInvokerFactory = new RpcInvokerFactory(serviceRegistryClass, serviceRegistryParam); rpcInvokerFactory = new RpcInvokerFactory(serviceRegistryClass, serviceRegistryParam);
//这一步实际上是将数据库对象实例化了出来
rpcInvokerFactory.start(); rpcInvokerFactory.start();
} }
...@@ -87,7 +88,7 @@ public class RpcSpringInvokerFactory extends InstantiationAwareBeanPostProcessor ...@@ -87,7 +88,7 @@ public class RpcSpringInvokerFactory extends InstantiationAwareBeanPostProcessor
null, null,
rpcInvokerFactory rpcInvokerFactory
); );
//获取一个代理对象 //获取一个代理对象 这个代理对象传入了 rpcInvokerFactory
Object serviceProxy = referenceBean.getObject(); Object serviceProxy = referenceBean.getObject();
// set bean // set bean
......
...@@ -124,6 +124,7 @@ public class RpcReferenceBean { ...@@ -124,6 +124,7 @@ public class RpcReferenceBean {
private void initClient() { private void initClient() {
try { try {
client = netType.clientClass.newInstance(); client = netType.clientClass.newInstance();
//他将自己当做对象传递 自己的对象包好rpcInvokerFactory对象 这里又存在发送信息的方法 钩子方法
client.init(this); client.init(this);
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
throw new RpcException(e); throw new RpcException(e);
......
...@@ -192,7 +192,7 @@ public class RpcProviderFactory { ...@@ -192,7 +192,7 @@ public class RpcProviderFactory {
} }
/** /**
* make service key * 制作服务密钥
* *
* @param iface * @param iface
* @param version * @param version
......
...@@ -26,6 +26,13 @@ public class DataSourceServiceRegistry extends PluginServiceRegistry { ...@@ -26,6 +26,13 @@ public class DataSourceServiceRegistry extends PluginServiceRegistry {
registryClient = new RegistryClient(registryUrl,null,biz,env); registryClient = new RegistryClient(registryUrl,null,biz,env);
} }
public static void main(String[] args) {
RegistryClient registryClient = new RegistryClient("http://localhost:8080/myth-register",
null,"byit-myth-job","plugin_test");
TreeSet<String> discovery = registryClient.discovery("01Test");
System.out.println(discovery);
}
@Override @Override
public void stop() { public void stop() {
if (registryClient != null) { if (registryClient != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment