Search in sources :

Example 31 with EventRegistration

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

the class EventServiceImpl method registerListenerInternal.

private EventRegistration registerListenerInternal(String serviceName, String topic, EventFilter filter, Object listener, boolean localOnly) {
    if (listener == null) {
        throw new IllegalArgumentException("Listener required!");
    }
    if (filter == null) {
        throw new IllegalArgumentException("EventFilter required!");
    }
    EventServiceSegment segment = getSegment(serviceName, true);
    String id = UuidUtil.newUnsecureUuidString();
    Registration reg = new Registration(id, serviceName, topic, filter, nodeEngine.getThisAddress(), listener, localOnly);
    if (!segment.addRegistration(topic, reg)) {
        return null;
    }
    if (!localOnly) {
        invokeRegistrationOnOtherNodes(serviceName, reg);
    }
    return reg;
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration)

Example 32 with EventRegistration

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

Example 33 with EventRegistration

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

the class EventServiceImpl method publishRemoteEvent.

@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.EventRegistration) EventRegistration(com.hazelcast.spi.EventRegistration) Data(com.hazelcast.nio.serialization.Data)

Example 34 with EventRegistration

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

the class ReplicatedMapEventPublishingService method fireMapClearedEvent.

public void fireMapClearedEvent(int deletedEntrySize, String name) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
    if (registrations.isEmpty()) {
        return;
    }
    MapEventData mapEventData = new MapEventData(name, name, nodeEngine.getThisAddress(), EntryEventType.CLEAR_ALL.getType(), deletedEntrySize);
    eventService.publishEvent(SERVICE_NAME, registrations, mapEventData, name.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

Example 35 with EventRegistration

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

the class QueueOperation method hasListener.

public boolean hasListener() {
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(getServiceName(), name);
    return registrations.size() > 0;
}
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