use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class ClientMembershipListener method handle.
@Override
public void handle(Collection<Member> initialMembers) {
Map<String, Member> prevMembers = Collections.emptyMap();
if (!members.isEmpty()) {
prevMembers = new HashMap<String, Member>(members.size());
for (Member member : members) {
prevMembers.put(member.getUuid(), member);
}
members.clear();
}
for (Member initialMember : initialMembers) {
members.add(initialMember);
}
if (prevMembers.isEmpty()) {
//this means this is the first time client connected to server
logger.info(membersString());
clusterService.handleInitialMembershipEvent(new InitialMembershipEvent(client.getCluster(), unmodifiableSet(members)));
initialListFetchedLatch.countDown();
return;
}
List<MembershipEvent> events = detectMembershipEvents(prevMembers);
logger.info(membersString());
fireMembershipEvent(events);
initialListFetchedLatch.countDown();
}
use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class ClusterServiceImpl method addMembershipListener.
public String addMembershipListener(MembershipListener listener) {
checkNotNull(listener, "listener cannot be null");
EventService eventService = nodeEngine.getEventService();
EventRegistration registration;
if (listener instanceof InitialMembershipListener) {
lock.lock();
try {
((InitialMembershipListener) listener).init(new InitialMembershipEvent(this, getMembers()));
registration = eventService.registerLocalListener(SERVICE_NAME, SERVICE_NAME, listener);
} finally {
lock.unlock();
}
} else {
registration = eventService.registerLocalListener(SERVICE_NAME, SERVICE_NAME, listener);
}
return registration.getId();
}
Aggregations