Search in sources :

Example 1 with InitialMembershipListener

use of com.hazelcast.core.InitialMembershipListener 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)

Example 2 with InitialMembershipListener

use of com.hazelcast.core.InitialMembershipListener in project hazelcast by hazelcast.

the class ClientClusterServiceImpl method initMembershipListener.

private void initMembershipListener(MembershipListener listener) {
    if (listener instanceof InitialMembershipListener) {
        Cluster cluster = client.getCluster();
        Collection<Member> memberCollection = members.get().values();
        LinkedHashSet<Member> members = new LinkedHashSet<Member>(memberCollection);
        InitialMembershipEvent event = new InitialMembershipEvent(cluster, members);
        ((InitialMembershipListener) listener).init(event);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent)

Aggregations

InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 InitialMembershipListener (com.hazelcast.core.InitialMembershipListener)2 Cluster (com.hazelcast.core.Cluster)1 Member (com.hazelcast.core.Member)1 EventRegistration (com.hazelcast.spi.EventRegistration)1 EventService (com.hazelcast.spi.EventService)1 LinkedHashSet (java.util.LinkedHashSet)1