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());
}
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();
}
Aggregations