valepakh commented on code in PR #3522:
URL: https://github.com/apache/ignite-3/pull/3522#discussion_r1546203581


##########
modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/impl/ConfigurationBasedChannelRegistry.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.eventlog.impl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.stream.Collectors;
+import org.apache.ignite.configuration.NamedListView;
+import org.apache.ignite.configuration.notifications.ConfigurationListener;
+import 
org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent;
+import org.apache.ignite.internal.eventlog.api.EventChannel;
+import org.apache.ignite.internal.eventlog.config.schema.ChannelView;
+import org.apache.ignite.internal.eventlog.config.schema.EventLogConfiguration;
+
+class ConfigurationBasedChannelRegistry implements ChannelRegistry {
+    private final ReadWriteLock guard;
+
+    private final Map<String, EventChannel> cache;
+
+    private final Map<String, Set<EventChannel>> typeCache;
+
+    private final SinkRegistry sinkRegistry;
+
+    ConfigurationBasedChannelRegistry(EventLogConfiguration cfg, SinkRegistry 
sinkRegistry) {
+        this.guard = new ReentrantReadWriteLock();
+        this.cache = new HashMap<>();
+        this.typeCache = new HashMap<>();
+        this.sinkRegistry = sinkRegistry;
+
+        cfg.channels().listen(new CacheUpdater());
+    }
+
+    @Override
+    public EventChannel getByName(String name) {
+        guard.readLock().lock();
+        try {
+            return cache.get(name);
+        } finally {
+            guard.readLock().unlock();
+        }
+    }
+
+    @Override
+    public Set<EventChannel> findAllChannelsByEventType(String 
igniteEventType) {
+        guard.readLock().lock();
+        try {
+            Set<EventChannel> result = typeCache.get(igniteEventType);
+            return result == null ? Set.of() : result;
+        } finally {
+            guard.readLock().unlock();
+        }
+    }
+
+    private class CacheUpdater implements 
ConfigurationListener<NamedListView<ChannelView>> {
+        @Override
+        public CompletableFuture<?> 
onUpdate(ConfigurationNotificationEvent<NamedListView<ChannelView>> ctx) {
+            NamedListView<ChannelView> newListValue = ctx.newValue();
+
+            guard.writeLock().lock();
+
+            try {
+                cache.clear();
+                typeCache.clear();
+
+                newListValue.forEach(view -> {
+                    if (view.enabled()) {
+                        cache.put(view.name(), createChannel(view));
+                        for (String eventType : view.events()) {
+                            typeCache.computeIfAbsent(
+                                    eventType.trim(),
+                                    t -> ConcurrentHashMap.newKeySet()
+                            ).add(cache.get(view.name()));
+                        }
+                    }
+                });
+
+                return CompletableFuture.completedFuture(null);

Review Comment:
   > Could you please use statically imported 
`CompletableFutures.nullCompletedFuture()` here?
   
   Doesn't look like this is resolved



-- 
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