Şu satırı dahil ederiz
import com.hazelcast.cluster.Member;
Cluster nesnesi ile elde edilir.
getAddressMap metodu
Örnek
Şöyle yaparız
HazelcastInstance hazelcastInstance = ...Set<Member> members = hazelcastInstance.getCluster().getMembers(); for (Member member : members) { System.out.println(member.getAddressMap()); }
Örnek
Şöyle yaparız. Burada java.util.UUID karşılaştırması yapılarak en eski Member bulunuyor
HazelcastInstance instance = ..; @Scheduled(fixedDelay = 10_000, initialDelay = 60_000) void startJob() { String leaderAddress = getOldestMember().getSocketAddress().toString(); String currentAddress = instance.getCluster().getLocalMember().getSocketAddress() .toString(); // Run the task only on leader node if (currentAddress.equals(leaderAddress)) { System.out.println("I am leader, use me to poll database, distribute task etc"); ... } } private Member getOldestMember() { Cluster cluster = instance.getCluster(); Member oldestMember = null; for (Member member : cluster.getMembers()) { if (oldestMember == null || member.getUuid().compareTo(oldestMember.getUuid()) < 0) { oldestMember = member; } } return oldestMember; }
Hiç yorum yok:
Yorum Gönder