Search in sources :

Example 16 with EventRegistration

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

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

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

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

the class ClientServiceProxy method addClientListener.

@Nonnull
@Override
public UUID addClientListener(@Nonnull ClientListener clientListener) {
    checkNotNull(clientListener, "clientListener should not be null");
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration = eventService.registerLocalListener(ClientEngineImpl.SERVICE_NAME, ClientEngineImpl.SERVICE_NAME, clientListener);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) Nonnull(javax.annotation.Nonnull)

Example 20 with EventRegistration

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

the class SetAddListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    Data partitionKey = serializationService.toData(parameters.name);
    ItemListener listener = createItemListener(endpoint, partitionKey);
    EventService eventService = clientEngine.getEventService();
    CollectionEventFilter filter = new CollectionEventFilter(parameters.includeValue);
    if (parameters.localOnly) {
        return newCompletedFuture(eventService.registerLocalListener(getServiceName(), parameters.name, filter, listener).getId());
    }
    return eventService.registerListenerAsync(getServiceName(), parameters.name, filter, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : CollectionEventFilter(com.hazelcast.collection.impl.collection.CollectionEventFilter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Data(com.hazelcast.internal.serialization.Data) ItemListener(com.hazelcast.collection.ItemListener) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)67 EventService (com.hazelcast.spi.impl.eventservice.EventService)45 Data (com.hazelcast.internal.serialization.Data)8 EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)7 UUID (java.util.UUID)7 Address (com.hazelcast.cluster.Address)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)4 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)4 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)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 ItemListener (com.hazelcast.collection.ItemListener)2 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)2 AssertTask (com.hazelcast.test.AssertTask)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2