tkalkirill commented on code in PR #2592:
URL: https://github.com/apache/ignite-3/pull/2592#discussion_r1327109346


##########
modules/core/src/main/java/org/apache/ignite/internal/event/AbstractEventProducer.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.event;
+
+import static java.util.concurrent.CompletableFuture.allOf;
+import static java.util.concurrent.CompletableFuture.completedFuture;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Event producer.
+ *
+ * <p>Allows to {@link #listen add} and {@link #removeListener remove} event 
listeners for events, as well as
+ * {@link #fireEvent fire events}.</p>
+ */
+public abstract class AbstractEventProducer<T extends Event, P extends 
EventParameters> implements EventProducer<T, P> {
+    private final ConcurrentHashMap<T, List<EventListener<P>>> 
listenersByEvent = new ConcurrentHashMap<>();
+
+    @Override
+    public void listen(T evt, EventListener<? extends P> listener) {
+        listenersByEvent.computeIfAbsent(evt, evtKey -> new 
CopyOnWriteArrayList<>()).add((EventListener<P>) listener);

Review Comment:
   Did it



##########
modules/core/src/main/java/org/apache/ignite/internal/event/AbstractEventProducer.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.event;
+
+import static java.util.concurrent.CompletableFuture.allOf;
+import static java.util.concurrent.CompletableFuture.completedFuture;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Event producer.
+ *
+ * <p>Allows to {@link #listen add} and {@link #removeListener remove} event 
listeners for events, as well as
+ * {@link #fireEvent fire events}.</p>
+ */
+public abstract class AbstractEventProducer<T extends Event, P extends 
EventParameters> implements EventProducer<T, P> {
+    private final ConcurrentHashMap<T, List<EventListener<P>>> 
listenersByEvent = new ConcurrentHashMap<>();
+
+    @Override
+    public void listen(T evt, EventListener<? extends P> listener) {
+        listenersByEvent.computeIfAbsent(evt, evtKey -> new 
CopyOnWriteArrayList<>()).add((EventListener<P>) listener);
+    }
+
+    @Override
+    public void removeListener(T evt, EventListener<? extends P> listener) {
+        listenersByEvent.computeIfPresent(evt, (evt0, listeners) -> {
+            listeners.remove(listener);
+
+            return listeners.isEmpty() ? null : listeners;
+        });
+    }
+
+    /**
+     * Notifies every listener that subscribed before.
+     *
+     * @param evt Event.
+     * @param params Event parameters.
+     * @param err Exception when it was happened, or {@code null} otherwise.
+     * @return Completable future which is completed when event handling is 
complete.
+     */
+    protected CompletableFuture<Void> fireEvent(T evt, P params, @Nullable 
Throwable err) {
+        List<EventListener<P>> listeners = listenersByEvent.get(evt);
+
+        if (listeners == null) {
+            return completedFuture(null);
+        }
+
+        List<CompletableFuture<?>> futures = new ArrayList<>();
+
+        for (EventListener<P> listener : listeners) {

Review Comment:
   Fix it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to