Search in sources :

Example 6 with EventRegistration

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

the class EventServiceImpl method registerListener0.

/**
 *     /**
 * Registers the listener for events matching the service name, topic and filter on local member.
 *
 * @param serviceName the service name for which we are registering
 * @param topic       the event topic for which we are registering
 * @param filter      the filter for the listened events
 * @param listener    the event listener
 * @return the event registration
 * @throws IllegalArgumentException if the listener or filter is null
 */
private EventRegistration registerListener0(@Nonnull String serviceName, @Nonnull String topic, @Nonnull EventFilter filter, @Nonnull Object listener, boolean isLocal) {
    checkNotNull(listener, "Null listener is not allowed!");
    checkNotNull(filter, "Null filter is not allowed!");
    EventServiceSegment segment = getSegment(serviceName, true);
    UUID id = UuidUtil.newUnsecureUUID();
    final Registration reg = new Registration(id, serviceName, topic, filter, nodeEngine.getThisAddress(), listener, isLocal);
    if (!segment.addRegistration(topic, reg)) {
        return null;
    }
    return reg;
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) UUID(java.util.UUID)

Example 7 with EventRegistration

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

the class EventServiceImpl method close.

@Override
public void close(EventRegistration eventRegistration) {
    Registration registration = (Registration) eventRegistration;
    Object listener = registration.getListener();
    if (!(listener instanceof Closeable)) {
        return;
    }
    try {
        ((Closeable) listener).close();
    } catch (IOException e) {
        ignore(e);
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Closeable(java.io.Closeable) IOException(java.io.IOException)

Example 8 with EventRegistration

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

the class PublishAllOperation method run.

@Override
public void run() throws Exception {
    TopicService service = getService();
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(TopicService.SERVICE_NAME, name);
    Lock lock = service.getOrderLock(name);
    lock.lock();
    try {
        for (Data item : messages) {
            TopicEvent topicEvent = new TopicEvent(name, item, getCallerAddress());
            eventService.publishEvent(TopicService.SERVICE_NAME, registrations, topicEvent, name.hashCode());
            service.incrementPublishes(name);
        }
    } finally {
        lock.unlock();
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) Data(com.hazelcast.internal.serialization.Data) Lock(java.util.concurrent.locks.Lock)

Example 9 with EventRegistration

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

the class MapEventPublisherImpl method publishMapEvent.

@Override
public void publishMapEvent(Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    Collection<EventRegistration> mapsListenerRegistrations = getRegistrations(mapName);
    if (isEmpty(mapsListenerRegistrations)) {
        return;
    }
    Collection<EventRegistration> registrations = null;
    for (EventRegistration registration : mapsListenerRegistrations) {
        EventFilter filter = registration.getFilter();
        if (filter instanceof EventListenerFilter) {
            if (!filter.eval(eventType.getType())) {
                continue;
            }
        }
        if (!(filter instanceof MapPartitionLostEventFilter)) {
            if (registrations == null) {
                registrations = new ArrayList<>();
            }
            registrations.add(registration);
        }
    }
    if (isEmpty(registrations)) {
        return;
    }
    String source = getThisNodesAddress();
    MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
    publishEventInternal(registrations, mapEventData, mapName.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter)

Example 10 with EventRegistration

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

the class MapServiceContextImpl method addPartitionLostListenerAsync.

@Override
public CompletableFuture<UUID> addPartitionLostListenerAsync(MapPartitionLostListener listener, String mapName) {
    ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
    EventFilter filter = new MapPartitionLostEventFilter();
    return eventService.registerListenerAsync(SERVICE_NAME, mapName, filter, listenerAdapter).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

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