Search in sources :

Example 1 with CollectionEventFilter

use of com.hazelcast.collection.impl.collection.CollectionEventFilter in project hazelcast by hazelcast.

the class ListAddListenerMessageTask 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 2 with CollectionEventFilter

use of com.hazelcast.collection.impl.collection.CollectionEventFilter 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 3 with CollectionEventFilter

use of com.hazelcast.collection.impl.collection.CollectionEventFilter in project hazelcast by hazelcast.

the class CollectionOperation method publishEvent.

protected void publishEvent(ItemEventType eventType, Data data) {
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(getServiceName(), name);
    final Address address = getNodeEngine().getThisAddress();
    for (EventRegistration registration : registrations) {
        CollectionEventFilter filter = (CollectionEventFilter) registration.getFilter();
        final boolean includeValue = filter.isIncludeValue();
        CollectionEvent event = new CollectionEvent(name, includeValue ? data : null, eventType, address);
        eventService.publishEvent(getServiceName(), registration, event, name.hashCode());
    }
}
Also used : CollectionEventFilter(com.hazelcast.collection.impl.collection.CollectionEventFilter) EventRegistration(com.hazelcast.spi.EventRegistration) Address(com.hazelcast.nio.Address) CollectionEvent(com.hazelcast.collection.impl.collection.CollectionEvent) EventService(com.hazelcast.spi.EventService)

Aggregations

CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 EventRegistration (com.hazelcast.spi.EventRegistration)3 EventService (com.hazelcast.spi.EventService)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 ItemListener (com.hazelcast.core.ItemListener)2 Data (com.hazelcast.nio.serialization.Data)2 CollectionEvent (com.hazelcast.collection.impl.collection.CollectionEvent)1 Address (com.hazelcast.nio.Address)1