Search in sources :

Example 1 with CollectionEvent

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

the class EventQueuePluginTest method testSampleRunnable.

@Test
public void testSampleRunnable() {
    Address caller = new Address();
    Data data = mock(Data.class);
    EntryEventData mapEventAdded = new EntryEventData("source", "mapName", caller, data, data, data, ADDED.getType());
    EntryEventData mapEventUpdated = new EntryEventData("source", "mapName", caller, data, data, data, UPDATED.getType());
    EntryEventData mapEventRemoved = new EntryEventData("source", "mapName", caller, data, data, data, REMOVED.getType());
    assertSampleRunnable("IMap 'mapName' ADDED", mapEventAdded, MapService.SERVICE_NAME);
    assertSampleRunnable("IMap 'mapName' UPDATED", mapEventUpdated, MapService.SERVICE_NAME);
    assertSampleRunnable("IMap 'mapName' REMOVED", mapEventRemoved, MapService.SERVICE_NAME);
    CacheEventData cacheEventCreated = new CacheEventDataImpl("cacheName", CacheEventType.CREATED, data, data, data, true);
    CacheEventData cacheEventUpdated = new CacheEventDataImpl("cacheName", CacheEventType.UPDATED, data, data, data, true);
    CacheEventData cacheEventRemoved = new CacheEventDataImpl("cacheName", CacheEventType.REMOVED, data, data, data, true);
    CacheEventSet CacheEventSetCreated = new CacheEventSet(CacheEventType.CREATED, singleton(cacheEventCreated), 1);
    CacheEventSet CacheEventSetUpdated = new CacheEventSet(CacheEventType.UPDATED, singleton(cacheEventUpdated), 1);
    CacheEventSet cacheEventSetRemoved = new CacheEventSet(CacheEventType.REMOVED, singleton(cacheEventRemoved), 1);
    assertSampleRunnable("ICache 'cacheName' CREATED", CacheEventSetCreated, CacheService.SERVICE_NAME);
    assertSampleRunnable("ICache 'cacheName' UPDATED", CacheEventSetUpdated, CacheService.SERVICE_NAME);
    assertSampleRunnable("ICache 'cacheName' REMOVED", cacheEventSetRemoved, CacheService.SERVICE_NAME);
    List<CacheEventData> cacheEventData = asList(cacheEventCreated, cacheEventUpdated, cacheEventRemoved);
    Set<CacheEventData> cacheEvents = new HashSet<CacheEventData>(cacheEventData);
    CacheEventSet cacheEventSetAll = new CacheEventSet(CacheEventType.EXPIRED, cacheEvents, 1);
    assertCacheEventSet(cacheEventSetAll, "ICache 'cacheName' CREATED", "ICache 'cacheName' UPDATED", "ICache 'cacheName' REMOVED");
    QueueEvent queueEventAdded = new QueueEvent("queueName", data, ItemEventType.ADDED, caller);
    QueueEvent queueEventRemoved = new QueueEvent("queueName", data, ItemEventType.REMOVED, caller);
    assertSampleRunnable("IQueue 'queueName' ADDED", queueEventAdded, QueueService.SERVICE_NAME);
    assertSampleRunnable("IQueue 'queueName' REMOVED", queueEventRemoved, QueueService.SERVICE_NAME);
    CollectionEvent setEventAdded = new CollectionEvent("setName", data, ItemEventType.ADDED, caller);
    CollectionEvent setEventRemoved = new CollectionEvent("setName", data, ItemEventType.REMOVED, caller);
    assertSampleRunnable("ISet 'setName' ADDED", setEventAdded, SetService.SERVICE_NAME);
    assertSampleRunnable("ISet 'setName' REMOVED", setEventRemoved, SetService.SERVICE_NAME);
    CollectionEvent listEventAdded = new CollectionEvent("listName", data, ItemEventType.ADDED, caller);
    CollectionEvent listEventRemoved = new CollectionEvent("listName", data, ItemEventType.REMOVED, caller);
    assertSampleRunnable("IList 'listName' ADDED", listEventAdded, ListService.SERVICE_NAME);
    assertSampleRunnable("IList 'listName' REMOVED", listEventRemoved, ListService.SERVICE_NAME);
    assertSampleRunnable("Object", new Object(), LongRegisterService.SERVICE_NAME);
    assertSampleRunnable(new TestEvent(), TestEvent.class.getName());
}
Also used : Address(com.hazelcast.cluster.Address) CacheEventSet(com.hazelcast.cache.impl.CacheEventSet) CollectionEvent(com.hazelcast.collection.impl.collection.CollectionEvent) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) CacheEventData(com.hazelcast.cache.impl.CacheEventData) Data(com.hazelcast.internal.serialization.Data) CacheEventDataImpl(com.hazelcast.cache.impl.CacheEventDataImpl) CacheEventData(com.hazelcast.cache.impl.CacheEventData) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) QueueEvent(com.hazelcast.collection.impl.queue.QueueEvent) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with CollectionEvent

use of com.hazelcast.collection.impl.collection.CollectionEvent 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.impl.eventservice.EventRegistration) Address(com.hazelcast.cluster.Address) CollectionEvent(com.hazelcast.collection.impl.collection.CollectionEvent) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 3 with CollectionEvent

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

the class EventQueuePlugin method sampleLocalDispatcherEvent.

private int sampleLocalDispatcherEvent(LocalEventDispatcher eventDispatcher) {
    Object dispatcherEvent = eventDispatcher.getEvent();
    if (dispatcherEvent instanceof EntryEventData) {
        // IMap event
        EntryEventData event = (EntryEventData) dispatcherEvent;
        EntryEventType type = EntryEventType.getByType(event.getEventType());
        String mapName = event.getMapName();
        occurrenceMap.add(format("IMap '%s' %s", mapName, type), 1);
        return 1;
    } else if (dispatcherEvent instanceof CacheEventSet) {
        // ICache event
        CacheEventSet eventSet = (CacheEventSet) dispatcherEvent;
        Set<CacheEventData> events = eventSet.getEvents();
        for (CacheEventData event : events) {
            occurrenceMap.add(format("ICache '%s' %s", event.getName(), event.getCacheEventType()), 1);
        }
        return events.size();
    } else if (dispatcherEvent instanceof QueueEvent) {
        // IQueue event
        QueueEvent event = (QueueEvent) dispatcherEvent;
        occurrenceMap.add(format("IQueue '%s' %s", event.getName(), event.getEventType()), 1);
        return 1;
    } else if (dispatcherEvent instanceof CollectionEvent) {
        // ISet or IList event
        CollectionEvent event = (CollectionEvent) dispatcherEvent;
        String serviceName = eventDispatcher.getServiceName();
        if (SetService.SERVICE_NAME.equals(serviceName)) {
            serviceName = "ISet";
        } else if (ListService.SERVICE_NAME.equals(serviceName)) {
            serviceName = "IList";
        }
        occurrenceMap.add(format("%s '%s' %s", serviceName, event.getName(), event.getEventType()), 1);
        return 1;
    }
    occurrenceMap.add(dispatcherEvent.getClass().getSimpleName(), 1);
    return 1;
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) CacheEventData(com.hazelcast.cache.impl.CacheEventData) CacheEventSet(com.hazelcast.cache.impl.CacheEventSet) Set(java.util.Set) CacheEventSet(com.hazelcast.cache.impl.CacheEventSet) CollectionEvent(com.hazelcast.collection.impl.collection.CollectionEvent) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) QueueEvent(com.hazelcast.collection.impl.queue.QueueEvent)

Aggregations

CollectionEvent (com.hazelcast.collection.impl.collection.CollectionEvent)3 CacheEventData (com.hazelcast.cache.impl.CacheEventData)2 CacheEventSet (com.hazelcast.cache.impl.CacheEventSet)2 Address (com.hazelcast.cluster.Address)2 QueueEvent (com.hazelcast.collection.impl.queue.QueueEvent)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)2 CacheEventDataImpl (com.hazelcast.cache.impl.CacheEventDataImpl)1 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)1 EntryEventType (com.hazelcast.core.EntryEventType)1 Data (com.hazelcast.internal.serialization.Data)1 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)1 EventService (com.hazelcast.spi.impl.eventservice.EventService)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.junit.Test)1