use of com.alibaba.nacos.common.utils.ConcurrentHashSet in project nacos by alibaba.
the class ServerMemberManager method memberChange.
synchronized boolean memberChange(Collection<Member> members) {
if (members == null || members.isEmpty()) {
return false;
}
boolean isContainSelfIp = members.stream().anyMatch(ipPortTmp -> Objects.equals(localAddress, ipPortTmp.getAddress()));
if (isContainSelfIp) {
isInIpList = true;
} else {
isInIpList = false;
members.add(this.self);
Loggers.CLUSTER.warn("[serverlist] self ip {} not in serverlist {}", self, members);
}
// If the number of old and new clusters is different, the cluster information
// must have changed; if the number of clusters is the same, then compare whether
// there is a difference; if there is a difference, then the cluster node changes
// are involved and all recipients need to be notified of the node change event
boolean hasChange = members.size() != serverList.size();
ConcurrentSkipListMap<String, Member> tmpMap = new ConcurrentSkipListMap<>();
Set<String> tmpAddressInfo = new ConcurrentHashSet<>();
for (Member member : members) {
final String address = member.getAddress();
Member existMember = serverList.get(address);
if (existMember == null) {
hasChange = true;
tmpMap.put(address, member);
} else {
// to keep extendInfo and abilities that report dynamically.
tmpMap.put(address, existMember);
}
if (NodeState.UP.equals(member.getState())) {
tmpAddressInfo.add(address);
}
}
serverList = tmpMap;
memberAddressInfos = tmpAddressInfo;
Collection<Member> finalMembers = allMembers();
// that the event publication is sequential
if (hasChange) {
Loggers.CLUSTER.warn("[serverlist] updated to : {}", finalMembers);
MemberUtil.syncToFile(finalMembers);
Event event = MembersChangeEvent.builder().members(finalMembers).build();
NotifyCenter.publishEvent(event);
} else {
if (Loggers.CLUSTER.isDebugEnabled()) {
Loggers.CLUSTER.debug("[serverlist] not updated, is still : {}", finalMembers);
}
}
return hasChange;
}
use of com.alibaba.nacos.common.utils.ConcurrentHashSet in project nacos by alibaba.
the class RaftController method getAllListeners.
/**
* Get all listeners.
*
* @param request http request
* @param response http response
* @return all listener information
*/
@GetMapping("/listeners")
public JsonNode getAllListeners(HttpServletRequest request, HttpServletResponse response) {
if (versionJudgement.allMemberIsNewVersion()) {
throw new IllegalStateException("old raft protocol already stop");
}
ObjectNode result = JacksonUtils.createEmptyJsonNode();
Map<String, ConcurrentHashSet<RecordListener>> listeners = raftCore.getListeners();
ArrayNode listenerArray = JacksonUtils.createEmptyArrayNode();
for (String key : listeners.keySet()) {
listenerArray.add(key);
}
result.replace("listeners", listenerArray);
return result;
}
use of com.alibaba.nacos.common.utils.ConcurrentHashSet in project nacos by alibaba.
the class WatchFileCenter_ITCase method test_multi_file_modify.
@Test
public void test_multi_file_modify() throws Exception {
CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
AtomicInteger count = new AtomicInteger(0);
Set<String> set = new ConcurrentHashSet<>();
final String fileName = "test2_file_change_" + i;
final File file = Paths.get(path, fileName).toFile();
executor.execute(() -> {
try {
func(fileName, file, content -> {
set.add(content);
count.incrementAndGet();
});
} catch (Throwable ex) {
ex.printStackTrace();
} finally {
latch.countDown();
}
});
}
latch.await(10_000L, TimeUnit.MILLISECONDS);
ThreadUtils.sleep(5_000L);
}
use of com.alibaba.nacos.common.utils.ConcurrentHashSet in project nacos by alibaba.
the class WatchFileCenter_ITCase method test_high_concurrency_modify.
// The last file change must be notified
@Test
public void test_high_concurrency_modify() throws Exception {
AtomicInteger count = new AtomicInteger(0);
Set<String> set = new ConcurrentHashSet<>();
final String fileName = "test2_file_change";
final File file = Paths.get(path, fileName).toFile();
func(fileName, file, content -> {
set.add(content);
count.incrementAndGet();
});
ThreadUtils.sleep(5_000L);
}
Aggregations