use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class MembershipListenerTest method whenMemberRemoved_thenMemberRemovedEvent.
@Test
public void whenMemberRemoved_thenMemberRemovedEvent() throws Exception {
final HazelcastInstance server1 = hazelcastFactory.newHazelcastInstance();
final MemberShipEventLogger listener = new MemberShipEventLogger();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
//start a second server and verify that hazelcastFactory listener receives it.
final HazelcastInstance server2 = hazelcastFactory.newHazelcastInstance();
client.getCluster().addMembershipListener(listener);
final Member server2Member = server2.getCluster().getLocalMember();
server2.shutdown();
//verify that the correct member removed event was received.
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotEquals("Expecting one or more events", 0, listener.events.size());
MembershipEvent event = (MembershipEvent) listener.events.getLast();
assertEquals("Last event should be member removed", MembershipEvent.MEMBER_REMOVED, event.getEventType());
assertEquals(server2Member, event.getMember());
assertEquals(getMembers(server1), event.getMembers());
}
});
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class DefaultPublisherContext method handleSubscriberAddRemove.
private void handleSubscriberAddRemove() {
ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
clusterService.addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
Member member = membershipEvent.getMember();
String uuid = member.getUuid();
handleDisconnectedSubscriber(uuid);
}
@Override
public void memberAdded(MembershipEvent membershipEvent) {
Member member = membershipEvent.getMember();
String uuid = member.getUuid();
handleConnectedSubscriber(uuid);
}
});
}
Aggregations