use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class TopicDestroyTest method assertRegistrationSize.
void assertRegistrationSize(int size) {
EventService eventService = getNode(instance).getNodeEngine().getEventService();
Collection<EventRegistration> regs = eventService.getRegistrations(TopicService.SERVICE_NAME, topicName);
assertEquals(size, regs.size());
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method addListener.
@Override
public String addListener(String mapName, String cacheName, MapListener listener, EventFilter filter) {
checkHasText(mapName, "mapName");
checkHasText(cacheName, "cacheName");
checkNotNull(listener, "listener cannot be null");
ListenerAdapter queryCacheListenerAdaptor = createQueryCacheListenerAdaptor(listener);
ListenerAdapter listenerAdaptor = new SimpleQueryCacheListenerAdapter(queryCacheListenerAdaptor);
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
EventService eventService = nodeEngine.getEventService();
String listenerName = generateListenerName(mapName, cacheName);
EventRegistration registration;
if (filter == null) {
registration = eventService.registerLocalListener(MapService.SERVICE_NAME, listenerName, listenerAdaptor);
} else {
registration = eventService.registerLocalListener(MapService.SERVICE_NAME, listenerName, filter, listenerAdaptor);
}
return registration.getId();
}
use of com.hazelcast.spi.EventRegistration 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.spi.EventRegistration in project hazelcast by hazelcast.
the class ReplicatedMapEventPublishingService method fireEntryListenerEvent.
public void fireEntryListenerEvent(Data key, Data oldValue, Data value, EntryEventType eventType, String name, Address caller) {
Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
if (registrations.isEmpty()) {
return;
}
EntryEventData eventData = new EntryEventData(name, name, caller, key, value, oldValue, eventType.getType());
for (EventRegistration registration : registrations) {
if (!shouldPublish(key, oldValue, value, eventType, registration.getFilter())) {
continue;
}
eventService.publishEvent(SERVICE_NAME, registration, eventData, key.hashCode());
}
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class EventServiceImpl method close.
@Override
public void close(EventRegistration eventRegistration) {
Registration registration = (Registration) eventRegistration;
Object listener = registration.getListener();
if (!(listener instanceof Closeable)) {
return;
}
try {
((Closeable) listener).close();
} catch (IOException e) {
EmptyStatement.ignore(e);
}
}
Aggregations