Search in sources :

Example 16 with EventService

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

the class AbstractCacheService method registerListener.

@Override
public UUID registerListener(String cacheNameWithPrefix, CacheEventListener listener, EventFilter eventFilter) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration registration = eventService.registerListener(AbstractCacheService.SERVICE_NAME, cacheNameWithPrefix, eventFilter, listener);
    return updateRegisteredListeners(listener, registration);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 17 with EventService

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

the class AbstractCacheService method registerLocalListener.

@Override
public UUID registerLocalListener(String cacheNameWithPrefix, CacheEventListener listener) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration registration = eventService.registerLocalListener(AbstractCacheService.SERVICE_NAME, cacheNameWithPrefix, listener);
    if (registration == null) {
        return null;
    }
    return updateRegisteredListeners(listener, registration);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 18 with EventService

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

the class CacheEventHandler method publishEvent.

void publishEvent(CacheEventContext cacheEventContext) {
    final EventService eventService = nodeEngine.getEventService();
    final String cacheName = cacheEventContext.getCacheName();
    final Collection<EventRegistration> candidates = eventService.getRegistrations(SERVICE_NAME, cacheName);
    if (candidates.isEmpty()) {
        return;
    }
    final Object eventData;
    final CacheEventType eventType = cacheEventContext.getEventType();
    switch(eventType) {
        case CREATED:
        case UPDATED:
        case REMOVED:
        case EXPIRED:
            final CacheEventData cacheEventData = new CacheEventDataImpl(cacheName, eventType, cacheEventContext.getDataKey(), cacheEventContext.getDataValue(), cacheEventContext.getDataOldValue(), cacheEventContext.isOldValueAvailable());
            CacheEventSet eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId());
            eventSet.addEventData(cacheEventData);
            eventData = eventSet;
            break;
        case EVICTED:
        case INVALIDATED:
            eventData = new CacheEventDataImpl(cacheName, eventType, cacheEventContext.getDataKey(), null, null, false);
            break;
        case COMPLETED:
            CacheEventData completedEventData = new CacheEventDataImpl(cacheName, eventType, cacheEventContext.getDataKey(), cacheEventContext.getDataValue(), null, false);
            eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId());
            eventSet.addEventData(completedEventData);
            eventData = eventSet;
            break;
        default:
            throw new IllegalArgumentException("Event Type not defined to create an eventData during publish: " + eventType.name());
    }
    eventService.publishEvent(SERVICE_NAME, candidates, eventData, cacheEventContext.getOrderKey());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) CacheEventType(com.hazelcast.cache.CacheEventType)

Example 19 with EventService

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

the class CacheEventHandler method publishEvent.

void publishEvent(String cacheNameWithPrefix, CacheEventSet eventSet, int orderKey) {
    final EventService eventService = nodeEngine.getEventService();
    final Collection<EventRegistration> candidates = eventService.getRegistrations(SERVICE_NAME, cacheNameWithPrefix);
    if (candidates.isEmpty()) {
        return;
    }
    eventService.publishEvent(SERVICE_NAME, candidates, eventSet, orderKey);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 20 with EventService

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

the class ClientEndpointImpl method addListenerDestroyAction.

@Override
public void addListenerDestroyAction(final String service, final String topic, final UUID id) {
    final EventService eventService = clientEngine.getEventService();
    addDestroyAction(id, () -> eventService.deregisterListener(service, topic, id));
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

EventService (com.hazelcast.spi.impl.eventservice.EventService)67 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)45 UUID (java.util.UUID)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Address (com.hazelcast.cluster.Address)4 Config (com.hazelcast.config.Config)4 Data (com.hazelcast.internal.serialization.Data)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 AssertTask (com.hazelcast.test.AssertTask)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 ItemListener (com.hazelcast.collection.ItemListener)2 DistributedObject (com.hazelcast.core.DistributedObject)2 Nonnull (javax.annotation.Nonnull)2 CacheEventType (com.hazelcast.cache.CacheEventType)1