use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class MapServiceContextImpl method addListenerAdapter.
@Override
public String addListenerAdapter(String cacheName, ListenerAdapter listenerAdaptor) {
EventService eventService = getNodeEngine().getEventService();
EventRegistration registration = eventService.registerListener(MapService.SERVICE_NAME, cacheName, TrueEventFilter.INSTANCE, 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 ClientEngineImpl method sendClientEvent.
private void sendClientEvent(ClientEvent event) {
final EventService eventService = nodeEngine.getEventService();
final Collection<EventRegistration> regs = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
String uuid = event.getUuid();
eventService.publishEvent(SERVICE_NAME, regs, event, uuid.hashCode());
}
use of com.hazelcast.spi.EventRegistration 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.EventRegistration in project hazelcast by hazelcast.
the class ListAddListenerMessageTask method call.
@Override
protected Object call() {
ClientEndpoint endpoint = getEndpoint();
Data partitionKey = serializationService.toData(parameters.name);
ItemListener listener = createItemListener(endpoint, partitionKey);
EventService eventService = clientEngine.getEventService();
CollectionEventFilter filter = new CollectionEventFilter(parameters.includeValue);
EventRegistration registration;
if (parameters.localOnly) {
registration = eventService.registerLocalListener(getServiceName(), parameters.name, filter, listener);
} else {
registration = eventService.registerListener(getServiceName(), parameters.name, filter, listener);
}
String registrationId = registration.getId();
endpoint.addListenerDestroyAction(getServiceName(), parameters.name, registrationId);
return registrationId;
}
Aggregations