Search in sources :

Example 1 with EventRegistration

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

the class MapServiceContextImpl method addListenerAdapter.

@Override
public String addListenerAdapter(String cacheName, ListenerAdapter listenerAdaptor) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration registration = eventService.registerListener(MapService.SERVICE_NAME, cacheName, TrueEventFilter.INSTANCE, listenerAdaptor);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 2 with EventRegistration

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

the class NodeQueryCacheEventService method publishLocalEvent.

// TODO needs refactoring.
private void publishLocalEvent(String mapName, String cacheName, Object eventData) {
    String listenerName = generateListenerName(mapName, cacheName);
    Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
    if (eventRegistrations.isEmpty()) {
        return;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (!(listener instanceof QueryCacheListenerAdapter)) {
            continue;
        }
        Object eventDataToPublish = eventData;
        int orderKey = -1;
        if (eventDataToPublish instanceof LocalCacheWideEventData) {
            orderKey = listenerName.hashCode();
        } else if (eventDataToPublish instanceof LocalEntryEventData) {
            LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventDataToPublish;
            if (localEntryEventData.getEventType() != EventLostEvent.EVENT_TYPE) {
                EventFilter filter = registration.getFilter();
                if (!canPassFilter(localEntryEventData, filter)) {
                    continue;
                } else {
                    boolean includeValue = isIncludeValue(filter);
                    eventDataToPublish = includeValue ? localEntryEventData : localEntryEventData.cloneWithoutValue();
                    Data keyData = localEntryEventData.getKeyData();
                    orderKey = keyData == null ? -1 : keyData.hashCode();
                }
            }
        }
        publishEventInternal(registration, eventDataToPublish, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) EventFilter(com.hazelcast.spi.EventFilter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Example 3 with EventRegistration

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

the class ClientEngineImpl method sendClientEvent.

private void sendClientEvent(ClientEvent event) {
    final EventService eventService = nodeEngine.getEventService();
    final Collection<EventRegistration> regs = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
    String uuid = event.getUuid();
    eventService.publishEvent(SERVICE_NAME, regs, event, uuid.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 4 with EventRegistration

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

the class CacheAddPartitionLostListenerMessageTask method call.

@Override
protected Object call() {
    final ClientEndpoint endpoint = getEndpoint();
    CachePartitionLostListener listener = new CachePartitionLostListener() {

        @Override
        public void partitionLost(CachePartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = CacheAddPartitionLostListenerCodec.encodeCachePartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    EventFilter filter = new CachePartitionLostEventFilter();
    CacheService service = getService(CacheService.SERVICE_NAME);
    EventService eventService = service.getNodeEngine().getEventService();
    EventRegistration registration;
    if (parameters.localOnly) {
        registration = eventService.registerLocalListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    } else {
        registration = eventService.registerListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    }
    String registrationId = registration.getId();
    endpoint.addListenerDestroyAction(CacheService.SERVICE_NAME, parameters.name, registrationId);
    return registrationId;
}
Also used : CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) EventRegistration(com.hazelcast.spi.EventRegistration) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) EventService(com.hazelcast.spi.EventService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 5 with EventRegistration

use of com.hazelcast.spi.EventRegistration 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)

Aggregations

EventRegistration (com.hazelcast.spi.EventRegistration)16 EventService (com.hazelcast.spi.EventService)14 ClientEndpoint (com.hazelcast.client.ClientEndpoint)3 Data (com.hazelcast.nio.serialization.Data)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)2 ItemListener (com.hazelcast.core.ItemListener)2 MigrationEvent (com.hazelcast.core.MigrationEvent)2 MemberImpl (com.hazelcast.instance.MemberImpl)2 EventFilter (com.hazelcast.spi.EventFilter)2 MembershipAwareService (com.hazelcast.spi.MembershipAwareService)2 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)1 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)1 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ITopic (com.hazelcast.core.ITopic)1 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)1 Member (com.hazelcast.core.Member)1