use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class EventServiceImpl method registerListener0.
/**
* /**
* Registers the listener for events matching the service name, topic and filter on local member.
*
* @param serviceName the service name for which we are registering
* @param topic the event topic for which we are registering
* @param filter the filter for the listened events
* @param listener the event listener
* @return the event registration
* @throws IllegalArgumentException if the listener or filter is null
*/
private EventRegistration registerListener0(@Nonnull String serviceName, @Nonnull String topic, @Nonnull EventFilter filter, @Nonnull Object listener, boolean isLocal) {
checkNotNull(listener, "Null listener is not allowed!");
checkNotNull(filter, "Null filter is not allowed!");
EventServiceSegment segment = getSegment(serviceName, true);
UUID id = UuidUtil.newUnsecureUUID();
final Registration reg = new Registration(id, serviceName, topic, filter, nodeEngine.getThisAddress(), listener, isLocal);
if (!segment.addRegistration(topic, reg)) {
return null;
}
return reg;
}
use of com.hazelcast.spi.impl.eventservice.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) {
ignore(e);
}
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class PublishAllOperation method run.
@Override
public void run() throws Exception {
TopicService service = getService();
EventService eventService = getNodeEngine().getEventService();
Collection<EventRegistration> registrations = eventService.getRegistrations(TopicService.SERVICE_NAME, name);
Lock lock = service.getOrderLock(name);
lock.lock();
try {
for (Data item : messages) {
TopicEvent topicEvent = new TopicEvent(name, item, getCallerAddress());
eventService.publishEvent(TopicService.SERVICE_NAME, registrations, topicEvent, name.hashCode());
service.incrementPublishes(name);
}
} finally {
lock.unlock();
}
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration 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<>();
}
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.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class MapServiceContextImpl method addPartitionLostListenerAsync.
@Override
public CompletableFuture<UUID> addPartitionLostListenerAsync(MapPartitionLostListener listener, String mapName) {
ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
EventFilter filter = new MapPartitionLostEventFilter();
return eventService.registerListenerAsync(SERVICE_NAME, mapName, filter, listenerAdapter).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Aggregations