use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method publishLocalEvent.
// TODO needs refactoring.
private void publishLocalEvent(String mapName, String cacheName, Object eventData) {
String listenerName = generateListenerName(mapName, cacheName);
Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
if (eventRegistrations.isEmpty()) {
return;
}
for (EventRegistration eventRegistration : eventRegistrations) {
Registration registration = (Registration) eventRegistration;
Object listener = registration.getListener();
if (!(listener instanceof QueryCacheListenerAdapter)) {
continue;
}
Object eventDataToPublish = eventData;
int orderKey = -1;
if (eventDataToPublish instanceof LocalCacheWideEventData) {
orderKey = listenerName.hashCode();
} else if (eventDataToPublish instanceof LocalEntryEventData) {
LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventDataToPublish;
if (localEntryEventData.getEventType() != EventLostEvent.EVENT_TYPE) {
EventFilter filter = registration.getFilter();
if (!canPassFilter(localEntryEventData, filter)) {
continue;
} else {
boolean includeValue = isIncludeValue(filter);
eventDataToPublish = includeValue ? localEntryEventData : localEntryEventData.cloneWithoutValue();
Data keyData = localEntryEventData.getKeyData();
orderKey = keyData == null ? -1 : keyData.hashCode();
}
}
}
publishEventInternal(registration, eventDataToPublish, orderKey);
}
}
use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.
the class EventPublisherHelper method publishEntryEvent.
/**
* Publishes event upon a change on a key in {@code QueryCache}.
*
* @param mapName the name of underlying map.
* @param cacheName the name of {@code QueryCache}
* @param dataKey the key in {@code Data} format.
* @param dataNewValue the value in {@code Data} format.
* @param oldRecord the relevant {@code QueryCacheEntry}
* @param context the {@code QueryCacheContext}
*/
static void publishEntryEvent(QueryCacheContext context, String mapName, String cacheName, Data dataKey, Data dataNewValue, QueryCacheRecord oldRecord, EntryEventType eventType) {
QueryCacheEventService eventService = getQueryCacheEventService(context);
if (!eventService.hasListener(mapName, cacheName)) {
return;
}
Object oldValue = getOldValue(oldRecord);
LocalEntryEventData eventData = createLocalEntryEventData(cacheName, dataKey, dataNewValue, oldValue, eventType.getType(), -1, context);
eventService.publish(mapName, cacheName, eventData, dataKey.hashCode());
}
use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.
the class EventPublisherHelper method publishEntryEvent.
/**
* Publishes event upon a change on a key in {@code QueryCache}.
*
* @param mapName the name of underlying map.
* @param cacheId the name of {@code QueryCache}
* @param queryCacheKey the key in {@code Data} format.
* @param dataNewValue the value in {@code Data} format.
* @param oldRecord the relevant {@code QueryCacheEntry}
* @param context the {@code QueryCacheContext}
*/
static void publishEntryEvent(QueryCacheContext context, String mapName, String cacheId, Object queryCacheKey, Data dataNewValue, QueryCacheRecord oldRecord, EntryEventType eventType, Extractors extractors) {
if (!hasListener(context, mapName, cacheId)) {
return;
}
Data dataKey = context.getSerializationService().toData(queryCacheKey);
QueryCacheEventService eventService = getQueryCacheEventService(context);
Object oldValue = getOldValue(oldRecord);
LocalEntryEventData eventData = createLocalEntryEventData(cacheId, dataKey, dataNewValue, oldValue, eventType.getType(), -1, context);
eventService.publish(mapName, cacheId, eventData, dataKey.hashCode(), extractors);
}
use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.
the class EventPublisherHelper method createIMapEvent.
public static IMapEvent createIMapEvent(EventData eventData, EventFilter filter, Member member, SerializationService serializationService) {
String source = eventData.getSource();
int eventType = eventData.getEventType();
if (eventType == EventLostEvent.EVENT_TYPE) {
LocalEntryEventData localEventData = (LocalEntryEventData) eventData;
int partitionId = localEventData.getPartitionId();
return new EventLostEvent(source, null, partitionId);
}
if (eventType == EntryEventType.CLEAR_ALL.getType() || eventType == EntryEventType.EVICT_ALL.getType()) {
LocalCacheWideEventData localCacheWideEventData = (LocalCacheWideEventData) eventData;
int numberOfEntriesAffected = localCacheWideEventData.getNumberOfEntriesAffected();
return new MapEvent(source, null, eventType, numberOfEntriesAffected);
}
LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventData;
Data dataKey = localEntryEventData.getKeyData();
Data dataNewValue = localEntryEventData.getValueData();
Data dataOldValue = localEntryEventData.getOldValueData();
boolean includeValue = isIncludeValue(filter);
return new DataAwareEntryEvent(member, eventType, source, dataKey, (includeValue ? dataNewValue : null), (includeValue ? dataOldValue : null), null, serializationService);
}
use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method canPassFilter.
private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter) {
if (filter == null || filter instanceof TrueEventFilter) {
return true;
}
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
SerializationService serializationService = nodeEngine.getSerializationService();
Data keyData = localEntryEventData.getKeyData();
Object value = getValueOrOldValue(localEntryEventData);
QueryableEntry entry = new QueryEntry((InternalSerializationService) serializationService, keyData, value, Extractors.empty());
return filter.eval(entry);
}
Aggregations