Search in sources :

Example 11 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class InternalEntryListenerAdapter method onEvent.

@Override
public void onEvent(IMapEvent event) {
    final EntryEventType eventType = event.getEventType();
    final ListenerAdapter listenerAdapter = listenerAdapters[eventType.ordinal()];
    if (listenerAdapter == null) {
        return;
    }
    listenerAdapter.onEvent(event);
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType)

Example 12 with EntryEventType

use of com.hazelcast.core.EntryEventType 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)

Example 13 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class MapListenerAdapterTest method ensure_map_listener_adapter_implements_listeners_for_all_entry_event_types_except_invalidation.

@Test
public void ensure_map_listener_adapter_implements_listeners_for_all_entry_event_types_except_invalidation() {
    MapListenerAdapter mapListenerAdapterInstance = new MapListenerAdapter();
    Map<EntryEventType, ConstructorFunction<MapListener, ListenerAdapter>> constructors = getConstructors();
    for (Map.Entry<EntryEventType, ConstructorFunction<MapListener, ListenerAdapter>> entry : constructors.entrySet()) {
        EntryEventType entryEventType = entry.getKey();
        if (entryEventType == EntryEventType.INVALIDATION) {
            // this event is used to listen near-cache invalidations.
            continue;
        }
        assertNotNull("MapListenerAdapter misses an interface " + "to implement for entry-event-type=" + entryEventType, entry.getValue().createNew(mapListenerAdapterInstance));
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) Map(java.util.Map) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class EventPublishOrderWithEvictionTest method assertEmittedEventsOrder.

private void assertEmittedEventsOrder(EventOrderAwareEntryListener entryListener) {
    Map<Integer, List<EntryEventType>> eventsPerKey = new HashMap<Integer, List<EntryEventType>>();
    List<EntryEvent> events = entryListener.getOrderedEvents();
    for (EntryEvent event : events) {
        Integer key = (Integer) event.getKey();
        List<EntryEventType> eventTypes = eventsPerKey.get(key);
        if (eventTypes == null) {
            eventTypes = new ArrayList<EntryEventType>();
            eventsPerKey.put(key, eventTypes);
        }
        EntryEventType eventType = event.getEventType();
        eventTypes.add(eventType);
    }
    Set<Map.Entry<Integer, List<EntryEventType>>> entries = eventsPerKey.entrySet();
    for (Map.Entry<Integer, List<EntryEventType>> entry : entries) {
        List<EntryEventType> eventTypes = entry.getValue();
        EntryEventType prev = null;
        for (int i = 0; i < eventTypes.size(); i++) {
            final EntryEventType eventType = eventTypes.get(i);
            if (i == 0) {
                assertEquals(EntryEventType.ADDED, eventType);
                prev = eventType;
                continue;
            }
            if (prev.equals(EntryEventType.ADDED)) {
                assertEquals(EntryEventType.EVICTED, eventType);
            } else if (prev.equals(EntryEventType.EVICTED)) {
                assertEquals(EntryEventType.ADDED, eventType);
            }
            prev = eventType;
        }
    }
}
Also used : HashMap(java.util.HashMap) EntryEventType(com.hazelcast.core.EntryEventType) EntryEvent(com.hazelcast.core.EntryEvent) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class MapListenerAdaptors method createListenerAdapters.

/**
 * Creates a {@link com.hazelcast.map.impl.ListenerAdapter} array
 * for all event types of {@link com.hazelcast.core.EntryEventType}.
 *
 * @param mapListener a {@link com.hazelcast.map.listener.MapListener} instance.
 * @return an array of {@link com.hazelcast.map.impl.ListenerAdapter}
 */
public static ListenerAdapter[] createListenerAdapters(MapListener mapListener) {
    EntryEventType[] values = EntryEventType.values();
    ListenerAdapter[] listenerAdapters = new ListenerAdapter[values.length];
    for (EntryEventType eventType : values) {
        listenerAdapters[eventType.ordinal()] = createListenerAdapter(eventType, mapListener);
    }
    return listenerAdapters;
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType)

Aggregations

EntryEventType (com.hazelcast.core.EntryEventType)24 Data (com.hazelcast.internal.serialization.Data)3 EntryEvent (com.hazelcast.core.EntryEvent)2 ToHeapDataConverter.toHeapData (com.hazelcast.internal.util.ToHeapDataConverter.toHeapData)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)2 Record (com.hazelcast.map.impl.record.Record)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 CacheEventData (com.hazelcast.cache.impl.CacheEventData)1 CacheEventSet (com.hazelcast.cache.impl.CacheEventSet)1 Member (com.hazelcast.cluster.Member)1 CollectionEvent (com.hazelcast.collection.impl.collection.CollectionEvent)1 QueueEvent (com.hazelcast.collection.impl.queue.QueueEvent)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EntryListener (com.hazelcast.core.EntryListener)1 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 EventLostEvent (com.hazelcast.map.EventLostEvent)1 MapEvent (com.hazelcast.map.MapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1