Snailclimb / guide-rpc-framework

A custom RPC framework implemented by Netty+Kyro+Zookeeper.(一款基于 Netty+Kyro+Zookeeper 实现的自定义 RPC 框架-附详细实现过程和相关教程。)
https://gitee.com/SnailClimb/guide-rpc-framework
Other
3.97k stars 2.06k forks source link

github.javaguide.provider.impl.ZkServiceProviderImpl类中为什么有serviceMap,还需要registeredService这个set去保存接口名? #46

Closed winterliu1020 closed 3 years ago

winterliu1020 commented 3 years ago

请问github.javaguide.provider.impl.ZkServiceProviderImpl类中为什么有serviceMap,还需要registeredService这个set去保存接口名?

/**
     * key: rpc service name(interface name + version + group)
     * value: service object
     */
    private final Map<String, Object> serviceMap;
    private final Set<String> registeredService;

    // 在get方法中:
    String rpcServiceName = rpcServiceConfig.getRpcServiceName();
    if (registeredService.contains(rpcServiceName)) {
        return;
    }
    registeredService.add(rpcServiceName);
    serviceMap.put(rpcServiceName, rpcServiceConfig.getService());

直接用serviceMap.containsKey(rpcServiceName)不行吗?对此有些疑惑 :-)

Snailclimb commented 3 years ago

请问github.javaguide.provider.impl.ZkServiceProviderImpl类中为什么有serviceMap,还需要registeredService这个set去保存接口名?

/**
     * key: rpc service name(interface name + version + group)
     * value: service object
     */
    private final Map<String, Object> serviceMap;
    private final Set<String> registeredService;

    // 在get方法中:
    String rpcServiceName = rpcServiceConfig.getRpcServiceName();
    if (registeredService.contains(rpcServiceName)) {
        return;
    }
    registeredService.add(rpcServiceName);
    serviceMap.put(rpcServiceName, rpcServiceConfig.getService());

直接用serviceMap.containsKey(rpcServiceName)不行吗?对此有些疑惑 :-)

我也有点忘啦,好像是因为 concurrenthashmap 没有你说的这个方法。