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());
}
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());
}
}
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;
}
Aggregations