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();
}
}
}
Aggregations