Search in sources :

Example 1 with InitialMembershipListener

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);
        }
    }
}
Also used : InitialMembershipListener(com.hazelcast.cluster.InitialMembershipListener) InitialMembershipListener(com.hazelcast.cluster.InitialMembershipListener) MembershipListener(com.hazelcast.cluster.MembershipListener) Member(com.hazelcast.cluster.Member) InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent)

Example 2 with InitialMembershipListener

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;
    }
}
Also used : InitialMembershipListener(com.hazelcast.cluster.InitialMembershipListener) Cluster(com.hazelcast.cluster.Cluster) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent) Nonnull(javax.annotation.Nonnull)

Example 3 with InitialMembershipListener

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();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) InitialMembershipListener(com.hazelcast.cluster.InitialMembershipListener) EventService(com.hazelcast.spi.impl.eventservice.EventService) InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent) Nonnull(javax.annotation.Nonnull)

Aggregations

InitialMembershipEvent (com.hazelcast.cluster.InitialMembershipEvent)3 InitialMembershipListener (com.hazelcast.cluster.InitialMembershipListener)3 Member (com.hazelcast.cluster.Member)2 Nonnull (javax.annotation.Nonnull)2 Cluster (com.hazelcast.cluster.Cluster)1 MembershipListener (com.hazelcast.cluster.MembershipListener)1 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)1 EventService (com.hazelcast.spi.impl.eventservice.EventService)1 UUID (java.util.UUID)1