use of com.hazelcast.cluster.InitialMembershipListener in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method applyInitialState.
private void applyInitialState(int version, Collection<MemberInfo> memberInfos) {
MemberListSnapshot snapshot = createSnapshot(version, memberInfos);
translateToPublicAddress.refresh(client.getClusterDiscoveryService().current().getAddressProvider(), memberInfos);
memberListSnapshot.set(snapshot);
logger.info(membersString(snapshot));
Set<Member> members = toUnmodifiableHasSet(snapshot.members.values());
InitialMembershipEvent event = new InitialMembershipEvent(client.getCluster(), members);
for (MembershipListener listener : listeners.values()) {
if (listener instanceof InitialMembershipListener) {
((InitialMembershipListener) listener).init(event);
}
}
}
use of com.hazelcast.cluster.InitialMembershipListener in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method addMembershipListener.
@Nonnull
@Override
public UUID addMembershipListener(@Nonnull MembershipListener listener) {
checkNotNull(listener, "Listener can't be null");
synchronized (clusterViewLock) {
UUID id = addMembershipListenerWithoutInit(listener);
if (listener instanceof InitialMembershipListener) {
Cluster cluster = client.getCluster();
Collection<Member> members = memberListSnapshot.get().members.values();
// it will be redirected to listeners when it arrives see #handleInitialMembershipEvent
if (!members.isEmpty()) {
InitialMembershipEvent event = new InitialMembershipEvent(cluster, toUnmodifiableHasSet(members));
((InitialMembershipListener) listener).init(event);
}
}
return id;
}
}
use of com.hazelcast.cluster.InitialMembershipListener in project hazelcast by hazelcast.
the class ClusterServiceImpl method addMembershipListener.
@Nonnull
public UUID addMembershipListener(@Nonnull 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