Search in sources :

Example 1 with MemberUtil

use of com.alibaba.nacos.core.cluster.MemberUtil in project nacos by alibaba.

the class ClusterRpcClientProxy method refresh.

/**
 * init cluster rpc clients.
 *
 * @param members cluster server list member list.
 */
private void refresh(List<Member> members) throws NacosException {
    // ensure to create client of new members
    for (Member member : members) {
        if (MemberUtil.isSupportedLongCon(member)) {
            createRpcClientAndStart(member, ConnectionType.GRPC);
        }
    }
    // shutdown and remove old members.
    Set<Map.Entry<String, RpcClient>> allClientEntrys = RpcClientFactory.getAllClientEntries();
    Iterator<Map.Entry<String, RpcClient>> iterator = allClientEntrys.iterator();
    List<String> newMemberKeys = members.stream().filter(MemberUtil::isSupportedLongCon).map(this::memberClientKey).collect(Collectors.toList());
    while (iterator.hasNext()) {
        Map.Entry<String, RpcClient> next1 = iterator.next();
        if (next1.getKey().startsWith("Cluster-") && !newMemberKeys.contains(next1.getKey())) {
            Loggers.CLUSTER.info("member leave,destroy client of member - > : {}", next1.getKey());
            RpcClientFactory.getClient(next1.getKey()).shutdown();
            iterator.remove();
        }
    }
}
Also used : Member(com.alibaba.nacos.core.cluster.Member) MemberUtil(com.alibaba.nacos.core.cluster.MemberUtil) HashMap(java.util.HashMap) Map(java.util.Map) RpcClient(com.alibaba.nacos.common.remote.client.RpcClient)

Aggregations

RpcClient (com.alibaba.nacos.common.remote.client.RpcClient)1 Member (com.alibaba.nacos.core.cluster.Member)1 MemberUtil (com.alibaba.nacos.core.cluster.MemberUtil)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1