use of com.hazelcast.core.MemberAttributeEvent in project hazelcast by hazelcast.
the class ClusterServiceImpl method dispatchEvent.
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
@Override
public void dispatchEvent(MembershipEvent event, MembershipListener listener) {
switch(event.getEventType()) {
case MembershipEvent.MEMBER_ADDED:
listener.memberAdded(event);
break;
case MembershipEvent.MEMBER_REMOVED:
listener.memberRemoved(event);
break;
case MembershipEvent.MEMBER_ATTRIBUTE_CHANGED:
MemberAttributeEvent memberAttributeEvent = (MemberAttributeEvent) event;
listener.memberAttributeChanged(memberAttributeEvent);
break;
default:
throw new IllegalArgumentException("Unhandled event: " + event);
}
}
use of com.hazelcast.core.MemberAttributeEvent in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testMergeAfterSplitBrain.
private void testMergeAfterSplitBrain(boolean multicast) throws InterruptedException {
String groupName = generateRandomString(10);
Config config = new Config();
config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "5");
config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "3");
config.getGroupConfig().setName(groupName);
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getMulticastConfig().setEnabled(multicast);
join.getTcpIpConfig().setEnabled(!multicast);
join.getTcpIpConfig().addMember("127.0.0.1");
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
HazelcastInstance h3 = Hazelcast.newHazelcastInstance(config);
final CountDownLatch splitLatch = new CountDownLatch(2);
h3.getCluster().addMembershipListener(new MembershipListener() {
@Override
public void memberAdded(MembershipEvent membershipEvent) {
}
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
splitLatch.countDown();
}
@Override
public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
}
});
final CountDownLatch mergeLatch = new CountDownLatch(1);
h3.getLifecycleService().addLifecycleListener(new MergedEventLifeCycleListener(mergeLatch));
closeConnectionBetween(h1, h3);
closeConnectionBetween(h2, h3);
assertTrue(splitLatch.await(10, TimeUnit.SECONDS));
assertEquals(2, h1.getCluster().getMembers().size());
assertEquals(2, h2.getCluster().getMembers().size());
assertEquals(1, h3.getCluster().getMembers().size());
assertTrue(mergeLatch.await(30, TimeUnit.SECONDS));
assertEquals(3, h1.getCluster().getMembers().size());
assertEquals(3, h2.getCluster().getMembers().size());
assertEquals(3, h3.getCluster().getMembers().size());
assertEquals(ACTIVE, h1.getCluster().getClusterState());
assertEquals(ACTIVE, h2.getCluster().getClusterState());
assertEquals(ACTIVE, h3.getCluster().getClusterState());
}
use of com.hazelcast.core.MemberAttributeEvent in project hazelcast by hazelcast.
the class QueueAdvancedTest method testDeadTaker.
/**
* Test for issue 730 (Google).
*/
@Test
public void testDeadTaker() throws Exception {
Config config = new Config();
final CountDownLatch shutdownLatch = new CountDownLatch(1);
config.addListenerConfig(new ListenerConfig().setImplementation(new MembershipListener() {
@Override
public void memberAdded(MembershipEvent membershipEvent) {
}
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
shutdownLatch.countDown();
}
@Override
public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
}
}));
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = factory.newInstances(config);
final HazelcastInstance h1 = instances[0];
final HazelcastInstance h2 = instances[1];
warmUpPartitions(h1, h2);
final IQueue<String> q1 = h1.getQueue("default");
final IQueue<String> q2 = h2.getQueue("default");
final CountDownLatch startLatch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
try {
assertTrue("Expected startLatch.await() to succeed within 10 seconds", startLatch.await(10, SECONDS));
Thread.sleep(5000);
h2.getLifecycleService().terminate();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
startLatch.countDown();
String value = q2.take();
fail("Should not be able to take value from queue, but got: " + value);
} catch (HazelcastInstanceNotActiveException e) {
EmptyStatement.ignore(e);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
assertTrue("Expected shutdownLatch.await() to succeed within 1 minute", shutdownLatch.await(1, MINUTES));
q1.offer("item");
assertEquals(1, q1.size());
assertEquals("item", q1.poll());
}
use of com.hazelcast.core.MemberAttributeEvent in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method testListenersTerminateRandomNode.
private void testListenersTerminateRandomNode() {
setupListener();
terminateRandomNode();
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final CountDownLatch memberAddedLatch = new CountDownLatch(1);
clientInstanceImpl.getClientClusterService().addMembershipListener(new MembershipListener() {
@Override
public void memberAdded(MembershipEvent membershipEvent) {
memberAddedLatch.countDown();
}
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
}
@Override
public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
}
});
factory.newHazelcastInstance();
assertOpenEventually(memberAddedLatch);
validateRegistrationsAndListenerFunctionality();
}
use of com.hazelcast.core.MemberAttributeEvent in project hazelcast by hazelcast.
the class ClusterServiceImpl method sendMemberAttributeEvent.
private void sendMemberAttributeEvent(MemberImpl member, MemberAttributeOperationType operationType, String key, Object value) {
final MemberAttributeServiceEvent event = new MemberAttributeServiceEvent(this, member, operationType, key, value);
MemberAttributeEvent attributeEvent = new MemberAttributeEvent(this, member, operationType, key, value);
Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class);
if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
for (final MembershipAwareService service : membershipAwareServices) {
// service events should not block each other
nodeEngine.getExecutionService().execute(ExecutionService.SYSTEM_EXECUTOR, new Runnable() {
public void run() {
service.memberAttributeChanged(event);
}
});
}
}
EventService eventService = nodeEngine.getEventService();
Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
for (EventRegistration reg : registrations) {
eventService.publishEvent(SERVICE_NAME, reg, attributeEvent, reg.getId().hashCode());
}
}
Aggregations