Search in sources :

Example 6 with InitialMembershipEvent

use of com.hazelcast.cluster.InitialMembershipEvent in project hazelcast by hazelcast.

the class MembershipListenerTest method initialMemberEvents_whenAddedAfterClientStartedAsync.

@Test
public void initialMemberEvents_whenAddedAfterClientStartedAsync() throws InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().setAsyncStart(true);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final InitialMemberShipEventLogger listener = new InitialMemberShipEventLogger();
    client.getCluster().addMembershipListener(listener);
    EventObject eventObject = listener.events.poll(ASSERT_TRUE_EVENTUALLY_TIMEOUT, TimeUnit.SECONDS);
    assertInstanceOf(InitialMembershipEvent.class, eventObject);
    InitialMembershipEvent event = (InitialMembershipEvent) eventObject;
    assertEquals(2, event.getMembers().size());
    assertEquals(0, listener.events.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) EventObject(java.util.EventObject) InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with InitialMembershipEvent

use of com.hazelcast.cluster.InitialMembershipEvent 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)7 ClientConfig (com.hazelcast.client.config.ClientConfig)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 InitialMembershipListener (com.hazelcast.cluster.InitialMembershipListener)3 EventObject (java.util.EventObject)3 Member (com.hazelcast.cluster.Member)2 ListenerConfig (com.hazelcast.config.ListenerConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)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 AssertTask (com.hazelcast.test.AssertTask)1 UUID (java.util.UUID)1