use of com.hazelcast.spi.EventFilter in project hazelcast by hazelcast.
the class CacheAddPartitionLostListenerMessageTask method call.
@Override
protected Object call() {
final ClientEndpoint endpoint = getEndpoint();
CachePartitionLostListener listener = new CachePartitionLostListener() {
@Override
public void partitionLost(CachePartitionLostEvent event) {
if (endpoint.isAlive()) {
ClientMessage eventMessage = CacheAddPartitionLostListenerCodec.encodeCachePartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
sendClientMessage(null, eventMessage);
}
}
};
InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
EventFilter filter = new CachePartitionLostEventFilter();
CacheService service = getService(CacheService.SERVICE_NAME);
EventService eventService = service.getNodeEngine().getEventService();
EventRegistration registration;
if (parameters.localOnly) {
registration = eventService.registerLocalListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
} else {
registration = eventService.registerListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
}
String registrationId = registration.getId();
endpoint.addListenerDestroyAction(CacheService.SERVICE_NAME, parameters.name, registrationId);
return registrationId;
}
use of com.hazelcast.spi.EventFilter in project hazelcast by hazelcast.
the class AbstractMapAddEntryListenerMessageTask method call.
@Override
protected Object call() {
final ClientEndpoint endpoint = getEndpoint();
final MapService mapService = getService(MapService.SERVICE_NAME);
Object listener = newMapListener();
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
String name = getDistributedObjectName();
EventFilter eventFilter = getEventFilter();
String registrationId;
if (isLocalOnly()) {
registrationId = mapServiceContext.addLocalEventListener(listener, eventFilter, name);
} else {
registrationId = mapServiceContext.addEventListener(listener, eventFilter, name);
}
endpoint.addListenerDestroyAction(MapService.SERVICE_NAME, name, registrationId);
return registrationId;
}
use of com.hazelcast.spi.EventFilter in project hazelcast by hazelcast.
the class QueryCacheEventPublisher method convertQueryCacheEventDataOrNull.
private QueryCacheEventData convertQueryCacheEventDataOrNull(PartitionAccumulatorRegistry registry, Data dataKey, Data dataNewValue, Data dataOldValue, int eventTypeId, int partitionId) {
EventFilter eventFilter = registry.getEventFilter();
EntryEventType eventType = EntryEventType.getByType(eventTypeId);
// filtering strategy
if (filteringStrategy instanceof DefaultEntryEventFilteringStrategy) {
eventType = getCQCEventTypeOrNull(eventType, eventFilter, dataKey, dataNewValue, dataOldValue);
} else {
int producedEventTypeId = filteringStrategy.doFilter(eventFilter, dataKey, dataOldValue, dataNewValue, eventType, null);
if (producedEventTypeId == FilteringStrategy.FILTER_DOES_NOT_MATCH) {
eventType = null;
} else {
eventType = EntryEventType.getByType(producedEventTypeId);
}
}
if (eventType == null) {
return null;
}
boolean includeValue = isIncludeValue(eventFilter);
return newQueryCacheEventDataBuilder(includeValue).withPartitionId(partitionId).withDataKey(dataKey).withDataNewValue(dataNewValue).withEventType(eventType.getType()).withDataOldValue(dataOldValue).withSerializationService((serializationService)).build();
}
use of com.hazelcast.spi.EventFilter in project hazelcast by hazelcast.
the class MapEventPublisherImpl method publishMapEvent.
@Override
public void publishMapEvent(Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
Collection<EventRegistration> mapsListenerRegistrations = getRegistrations(mapName);
if (isEmpty(mapsListenerRegistrations)) {
return;
}
Collection<EventRegistration> registrations = null;
for (EventRegistration registration : mapsListenerRegistrations) {
EventFilter filter = registration.getFilter();
if (filter instanceof EventListenerFilter) {
if (!filter.eval(eventType.getType())) {
continue;
}
}
if (!(filter instanceof MapPartitionLostEventFilter)) {
if (registrations == null) {
registrations = new ArrayList<EventRegistration>();
}
registrations.add(registration);
}
}
if (isEmpty(registrations)) {
return;
}
String source = getThisNodesAddress();
MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
publishEventInternal(registrations, mapEventData, mapName.hashCode());
}
use of com.hazelcast.spi.EventFilter 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);
}
}
Aggregations