Search in sources :

Example 6 with InitialMembershipEvent

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();
}
Also used : InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) AbstractMember(com.hazelcast.instance.AbstractMember) Member(com.hazelcast.core.Member) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent)

Example 7 with InitialMembershipEvent

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();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) EventService(com.hazelcast.spi.EventService) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent)

Aggregations

InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)7 ClientConfig (com.hazelcast.client.config.ClientConfig)3 Member (com.hazelcast.core.Member)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 ListenerConfig (com.hazelcast.config.ListenerConfig)2 InitialMembershipListener (com.hazelcast.core.InitialMembershipListener)2 EventObject (java.util.EventObject)2 Cluster (com.hazelcast.core.Cluster)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 MembershipEvent (com.hazelcast.core.MembershipEvent)1 AbstractMember (com.hazelcast.instance.AbstractMember)1 EventRegistration (com.hazelcast.spi.EventRegistration)1 EventService (com.hazelcast.spi.EventService)1 AssertTask (com.hazelcast.test.AssertTask)1 LinkedHashSet (java.util.LinkedHashSet)1