Search in sources :

Example 41 with EventService

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

the class AbstractCacheService method deregisterListener.

@Override
public boolean deregisterListener(String name, String registrationId) {
    EventService eventService = getNodeEngine().getEventService();
    boolean result = eventService.deregisterListener(SERVICE_NAME, name, registrationId);
    Closeable listener = closeableListeners.remove(registrationId);
    if (listener != null) {
        IOUtil.closeResource(listener);
    }
    return result;
}
Also used : Closeable(java.io.Closeable) EventService(com.hazelcast.spi.EventService)

Example 42 with EventService

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

the class ClusterServiceImpl method removeMembershipListener.

public boolean removeMembershipListener(String registrationId) {
    checkNotNull(registrationId, "registrationId cannot be null");
    EventService eventService = nodeEngine.getEventService();
    return eventService.deregisterListener(SERVICE_NAME, SERVICE_NAME, registrationId);
}
Also used : EventService(com.hazelcast.spi.EventService)

Example 43 with EventService

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

the class ClusterServiceImpl method addMembershipListener.

public String addMembershipListener(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.EventRegistration) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) EventService(com.hazelcast.spi.EventService) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent)

Example 44 with EventService

use of com.hazelcast.spi.EventService 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 45 with EventService

use of com.hazelcast.spi.EventService 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

EventService (com.hazelcast.spi.EventService)49 EventRegistration (com.hazelcast.spi.EventRegistration)37 Address (com.hazelcast.nio.Address)5 NodeEngine (com.hazelcast.spi.NodeEngine)5 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Collection (java.util.Collection)4 Test (org.junit.Test)4 ClientEndpoint (com.hazelcast.client.ClientEndpoint)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 Config (com.hazelcast.config.Config)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 Data (com.hazelcast.nio.serialization.Data)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 ItemListener (com.hazelcast.core.ItemListener)2 Member (com.hazelcast.core.Member)2