Search in sources :

Example 46 with EventRegistration

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

the class MultiMapService method addListenerAsync.

public CompletableFuture<UUID> addListenerAsync(String name, @Nonnull EventListener listener, Data key, boolean includeValue) {
    EventService eventService = nodeEngine.getEventService();
    MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
    return eventService.registerListenerAsync(SERVICE_NAME, name, filter, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 47 with EventRegistration

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

the class MultiMapEventsPublisher method publishEntryEvent.

public final void publishEntryEvent(String multiMapName, EntryEventType eventType, Data key, Object newValue, Object oldValue) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, multiMapName);
    for (EventRegistration registration : registrations) {
        MultiMapEventFilter filter = (MultiMapEventFilter) registration.getFilter();
        if (filter.getKey() == null || filter.getKey().equals(key)) {
            Data dataNewValue = filter.isIncludeValue() ? nodeEngine.toData(newValue) : null;
            Data dataOldValue = filter.isIncludeValue() ? nodeEngine.toData(oldValue) : null;
            Address caller = nodeEngine.getThisAddress();
            String source = caller.toString();
            EntryEventData event = new EntryEventData(source, multiMapName, caller, key, dataNewValue, dataOldValue, eventType.getType());
            eventService.publishEvent(MultiMapService.SERVICE_NAME, registration, event, multiMapName.hashCode());
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Address(com.hazelcast.cluster.Address) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Data(com.hazelcast.internal.serialization.Data)

Example 48 with EventRegistration

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

the class MultiMapEventsPublisher method publishMultiMapEvent.

public void publishMultiMapEvent(String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, mapName);
    if (registrations.isEmpty()) {
        return;
    }
    Address caller = nodeEngine.getThisAddress();
    String source = caller.toString();
    MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
    eventService.publishEvent(MultiMapService.SERVICE_NAME, registrations, mapEventData, mapName.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Address(com.hazelcast.cluster.Address) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

Example 49 with EventRegistration

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

the class EventServiceImpl method publishEvent.

@Override
public void publishEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey) {
    Data eventData = null;
    for (EventRegistration registration : registrations) {
        if (!(registration instanceof Registration)) {
            throw new IllegalArgumentException();
        }
        if (isLocal(registration)) {
            executeLocal(serviceName, event, registration, orderKey);
            continue;
        }
        if (eventData == null) {
            eventData = serializationService.toData(event);
        }
        EventEnvelope eventEnvelope = new EventEnvelope(registration.getId(), serviceName, eventData);
        sendEvent(registration.getSubscriber(), eventEnvelope, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Data(com.hazelcast.internal.serialization.Data)

Example 50 with EventRegistration

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

the class EventServiceImpl method publishRemoteEvent.

/**
 * {@inheritDoc}
 *
 * @param serviceName   service name
 * @param registrations multiple event registrations
 * @param event         event object
 * @param orderKey      order key
 * @throws IllegalArgumentException if any registration is not an instance of {@link Registration}
 */
@Override
public void publishRemoteEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey) {
    if (registrations.isEmpty()) {
        return;
    }
    Data eventData = serializationService.toData(event);
    for (EventRegistration registration : registrations) {
        if (!(registration instanceof Registration)) {
            throw new IllegalArgumentException();
        }
        if (isLocal(registration)) {
            continue;
        }
        EventEnvelope eventEnvelope = new EventEnvelope(registration.getId(), serviceName, eventData);
        sendEvent(registration.getSubscriber(), eventEnvelope, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Data(com.hazelcast.internal.serialization.Data)

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