Search in sources :

Example 46 with EventService

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

the class MultiMapEventsPublisher method publishMultiMapEvent.

public void publishMultiMapEvent(String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, mapName);
    if (registrations.isEmpty()) {
        return;
    }
    Address caller = nodeEngine.getThisAddress();
    String source = caller.toString();
    MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
    eventService.publishEvent(MultiMapService.SERVICE_NAME, registrations, mapEventData, mapName.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Address(com.hazelcast.cluster.Address) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

Example 47 with EventService

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

the class ProxyRegistry method publish.

private void publish(DistributedObjectEventPacket event) {
    EventService eventService = proxyService.nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(ProxyServiceImpl.SERVICE_NAME, ProxyServiceImpl.SERVICE_NAME);
    eventService.publishRemoteEvent(ProxyServiceImpl.SERVICE_NAME, registrations, event, event.getName().hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 48 with EventService

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

the class ProxyRegistry method destroyProxy.

/**
 * Destroys a proxy.
 *
 * @param name         The name of the proxy to destroy.
 * @param source       The UUID of the client or member which initialized destroyProxy.
 * @param publishEvent true if this destroy should be published.
 */
void destroyProxy(String name, UUID source, boolean publishEvent) {
    final DistributedObjectFuture proxyFuture = proxies.remove(name);
    if (proxyFuture == null) {
        return;
    }
    DistributedObject proxy;
    try {
        proxy = proxyFuture.getNow();
    } catch (Throwable t) {
        proxyService.logger.warning("Cannot destroy proxy [" + serviceName + ":" + name + "], since its creation is failed with " + t.getClass().getName() + ": " + t.getMessage());
        return;
    }
    if (proxy == null) {
        // complete exceptionally the proxy future
        try {
            proxyFuture.setError(new DistributedObjectDestroyedException("Proxy [" + serviceName + ":" + name + "] " + "was destroyed while being created. This may result in incomplete cleanup of resources."));
        } catch (IllegalStateException e) {
            // proxy was set and initialized in the meanwhile
            proxy = proxyFuture.get();
        }
    }
    if (proxy != null) {
        EventService eventService = proxyService.nodeEngine.getEventService();
        ProxyEventProcessor callback = new ProxyEventProcessor(proxyService.listeners.values(), DESTROYED, serviceName, name, proxy, source);
        eventService.executeEventCallback(callback);
    }
    if (publishEvent) {
        publish(new DistributedObjectEventPacket(DESTROYED, serviceName, name, source));
    }
}
Also used : AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) DistributedObject(com.hazelcast.core.DistributedObject) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 49 with EventService

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

the class PublishOperation method run.

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

Example 50 with EventService

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

the class ClientMigrationListenerTest method assertRegistrationsSizeEventually.

private void assertRegistrationsSizeEventually(HazelcastInstance instance, int size) {
    assertTrueEventually(() -> {
        EventService eventService = getNode(instance).getNodeEngine().getEventService();
        Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, MIGRATION_EVENT_TOPIC);
        assertEquals(size, registrations.size());
    });
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

EventService (com.hazelcast.spi.impl.eventservice.EventService)67 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)45 UUID (java.util.UUID)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Address (com.hazelcast.cluster.Address)4 Config (com.hazelcast.config.Config)4 Data (com.hazelcast.internal.serialization.Data)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 AssertTask (com.hazelcast.test.AssertTask)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 ItemListener (com.hazelcast.collection.ItemListener)2 DistributedObject (com.hazelcast.core.DistributedObject)2 Nonnull (javax.annotation.Nonnull)2 CacheEventType (com.hazelcast.cache.CacheEventType)1