Search in sources :

Example 16 with EventRegistration

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

the class SetAddListenerMessageTask method call.

@Override
protected Object call() {
    ClientEndpoint endpoint = getEndpoint();
    Data partitionKey = serializationService.toData(parameters.name);
    ItemListener listener = createItemListener(endpoint, partitionKey);
    EventService eventService = clientEngine.getEventService();
    CollectionEventFilter filter = new CollectionEventFilter(parameters.includeValue);
    EventRegistration registration;
    if (parameters.localOnly) {
        registration = eventService.registerLocalListener(getServiceName(), parameters.name, filter, listener);
    } else {
        registration = eventService.registerListener(getServiceName(), parameters.name, filter, listener);
    }
    String registrationId = registration.getId();
    endpoint.addListenerDestroyAction(getServiceName(), parameters.name, registrationId);
    return registrationId;
}
Also used : CollectionEventFilter(com.hazelcast.collection.impl.collection.CollectionEventFilter) EventRegistration(com.hazelcast.spi.EventRegistration) Data(com.hazelcast.nio.serialization.Data) ItemListener(com.hazelcast.core.ItemListener) EventService(com.hazelcast.spi.EventService) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 17 with EventRegistration

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

the class AbstractCollectionProxyImpl method addItemListener.

public String addItemListener(ItemListener<E> listener, boolean includeValue) {
    final EventService eventService = getNodeEngine().getEventService();
    final CollectionEventFilter filter = new CollectionEventFilter(includeValue);
    final EventRegistration registration = eventService.registerListener(getServiceName(), name, filter, listener);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 18 with EventRegistration

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

the class QueueService method addItemListener.

public String addItemListener(String name, ItemListener listener, boolean includeValue, boolean isLocal) {
    EventService eventService = nodeEngine.getEventService();
    QueueEventFilter filter = new QueueEventFilter(includeValue);
    EventRegistration registration;
    if (isLocal) {
        registration = eventService.registerLocalListener(QueueService.SERVICE_NAME, name, filter, listener);
    } else {
        registration = eventService.registerListener(QueueService.SERVICE_NAME, name, filter, listener);
    }
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 19 with EventRegistration

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

the class AbstractCacheService method registerListenerInternal.

protected String registerListenerInternal(String name, CacheEventListener listener, EventFilter eventFilter, boolean isLocal) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration reg;
    if (isLocal) {
        if (eventFilter == null) {
            reg = eventService.registerLocalListener(AbstractCacheService.SERVICE_NAME, name, listener);
        } else {
            reg = eventService.registerLocalListener(AbstractCacheService.SERVICE_NAME, name, eventFilter, listener);
        }
    } else {
        if (eventFilter == null) {
            reg = eventService.registerListener(AbstractCacheService.SERVICE_NAME, name, listener);
        } else {
            reg = eventService.registerListener(AbstractCacheService.SERVICE_NAME, name, eventFilter, listener);
        }
    }
    String id = reg.getId();
    if (listener instanceof Closeable) {
        closeableListeners.put(id, (Closeable) listener);
    } else if (listener instanceof CacheEntryListenerProvider) {
        CacheEntryListener cacheEntryListener = ((CacheEntryListenerProvider) listener).getCacheEntryListener();
        if (cacheEntryListener instanceof Closeable) {
            closeableListeners.put(id, (Closeable) cacheEntryListener);
        }
    }
    return id;
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) CacheEntryListener(javax.cache.event.CacheEntryListener) Closeable(java.io.Closeable) EventService(com.hazelcast.spi.EventService)

Example 20 with EventRegistration

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

the class AbstractCacheService method addInvalidationListener.

/**
     * Registers and {@link com.hazelcast.cache.impl.CacheEventListener} for specified <code>cacheName</code>.
     *
     * @param name      the name of the cache that {@link com.hazelcast.cache.impl.CacheEventListener} will be registered for
     * @param listener  the {@link com.hazelcast.cache.impl.CacheEventListener} to be registered for specified <code>cache</code>
     * @param localOnly true if only events originated from this member wants be listened, false if all invalidation events in the
     *                  cluster wants to be listened
     * @return the id which is unique for current registration
     */
@Override
public String addInvalidationListener(String name, CacheEventListener listener, boolean localOnly) {
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration;
    if (localOnly) {
        registration = eventService.registerLocalListener(SERVICE_NAME, name, listener);
    } else {
        registration = eventService.registerListener(SERVICE_NAME, name, listener);
    }
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) 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