Search in sources :

Example 41 with EventRegistration

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

the class CacheProxy method addPartitionLostListener.

@Override
public String addPartitionLostListener(CachePartitionLostListener listener) {
    checkNotNull(listener, "CachePartitionLostListener can't be null");
    EventFilter filter = new CachePartitionLostEventFilter();
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    injectDependencies(listener);
    EventRegistration registration = getService().getNodeEngine().getEventService().registerListener(AbstractCacheService.SERVICE_NAME, name, filter, listenerAdapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)

Example 42 with EventRegistration

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

the class AbstractCacheRecordStore method closeListeners.

protected void closeListeners() {
    InternalEventService eventService = (InternalEventService) cacheService.getNodeEngine().getEventService();
    Collection<EventRegistration> candidates = eventService.getRegistrations(ICacheService.SERVICE_NAME, name);
    for (EventRegistration eventRegistration : candidates) {
        eventService.close(eventRegistration);
    }
}
Also used : InternalEventService(com.hazelcast.spi.impl.eventservice.InternalEventService) EventRegistration(com.hazelcast.spi.EventRegistration)

Example 43 with EventRegistration

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

the class AbstractCacheService method deregisterAllListener.

@Override
public void deregisterAllListener(String name) {
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
    if (registrations != null) {
        for (EventRegistration registration : registrations) {
            Closeable listener = closeableListeners.remove(registration.getId());
            if (listener != null) {
                IOUtil.closeResource(listener);
            }
        }
    }
    eventService.deregisterAllListeners(AbstractCacheService.SERVICE_NAME, name);
    CacheContext cacheContext = cacheContexts.get(name);
    if (cacheContext != null) {
        cacheContext.resetCacheEntryListenerCount();
        cacheContext.resetInvalidationListenerCount();
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Closeable(java.io.Closeable) EventService(com.hazelcast.spi.EventService)

Example 44 with EventRegistration

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

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

Aggregations

EventRegistration (com.hazelcast.spi.EventRegistration)55 EventService (com.hazelcast.spi.EventService)37 Data (com.hazelcast.nio.serialization.Data)7 EventFilter (com.hazelcast.spi.EventFilter)7 Address (com.hazelcast.nio.Address)5 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)5 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)4 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)3 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 Registration (com.hazelcast.spi.impl.eventservice.impl.Registration)3 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 ItemListener (com.hazelcast.core.ItemListener)2 Member (com.hazelcast.core.Member)2 MigrationEvent (com.hazelcast.core.MigrationEvent)2 MemberImpl (com.hazelcast.instance.MemberImpl)2