Search in sources :

Example 1 with MembershipAwareService

use of com.hazelcast.spi.MembershipAwareService in project hazelcast by hazelcast.

the class QuorumTest method testQuorumIgnoresMemberAttributeEvents.

@Test
public void testQuorumIgnoresMemberAttributeEvents() {
    final RecordingQuorumFunction function = new RecordingQuorumFunction();
    QuorumConfig quorumConfig = new QuorumConfig().setName(randomString()).setEnabled(true).setQuorumFunctionImplementation(function);
    Config config = new Config().addQuorumConfig(quorumConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hazelcastInstance);
    MembershipAwareService service = nodeEngine.getService(QuorumServiceImpl.SERVICE_NAME);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(function.wasCalled);
        }
    });
    function.wasCalled = false;
    MemberAttributeServiceEvent event = mock(MemberAttributeServiceEvent.class);
    service.memberAttributeChanged(event);
    assertFalse(function.wasCalled);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) MembershipAwareService(com.hazelcast.spi.MembershipAwareService) AssertTask(com.hazelcast.test.AssertTask) MemberAttributeServiceEvent(com.hazelcast.spi.MemberAttributeServiceEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with MembershipAwareService

use of com.hazelcast.spi.MembershipAwareService 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());
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) MemberAttributeEvent(com.hazelcast.core.MemberAttributeEvent) MembershipAwareService(com.hazelcast.spi.MembershipAwareService) MemberAttributeServiceEvent(com.hazelcast.spi.MemberAttributeServiceEvent) EventService(com.hazelcast.spi.EventService)

Example 3 with MembershipAwareService

use of com.hazelcast.spi.MembershipAwareService in project hazelcast by hazelcast.

the class ClusterServiceImpl method sendMembershipEventNotifications.

private void sendMembershipEventNotifications(MemberImpl member, Set<Member> members, final boolean added) {
    int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED;
    MembershipEvent membershipEvent = new MembershipEvent(this, member, eventType, members);
    Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class);
    if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
        final MembershipServiceEvent event = new MembershipServiceEvent(membershipEvent);
        for (final MembershipAwareService service : membershipAwareServices) {
            nodeEngine.getExecutionService().execute(MEMBERSHIP_EVENT_EXECUTOR_NAME, new Runnable() {

                public void run() {
                    if (added) {
                        service.memberAdded(event);
                    } else {
                        service.memberRemoved(event);
                    }
                }
            });
        }
    }
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
    for (EventRegistration reg : registrations) {
        eventService.publishEvent(SERVICE_NAME, reg, membershipEvent, reg.getId().hashCode());
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) MembershipServiceEvent(com.hazelcast.spi.MembershipServiceEvent) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) MembershipAwareService(com.hazelcast.spi.MembershipAwareService) EventService(com.hazelcast.spi.EventService)

Aggregations

MembershipAwareService (com.hazelcast.spi.MembershipAwareService)3 EventRegistration (com.hazelcast.spi.EventRegistration)2 EventService (com.hazelcast.spi.EventService)2 MemberAttributeServiceEvent (com.hazelcast.spi.MemberAttributeServiceEvent)2 Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 QuorumConfig (com.hazelcast.config.QuorumConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)1 MemberAttributeEvent (com.hazelcast.core.MemberAttributeEvent)1 MembershipEvent (com.hazelcast.core.MembershipEvent)1 MembershipServiceEvent (com.hazelcast.spi.MembershipServiceEvent)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 AssertTask (com.hazelcast.test.AssertTask)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1