ibessonov commented on a change in pull request #336: URL: https://github.com/apache/ignite-3/pull/336#discussion_r715441925
########## File path: modules/configuration/src/main/java/org/apache/ignite/internal/configuration/DynamicConfiguration.java ########## @@ -133,4 +140,9 @@ public DynamicConfiguration( public Map<String, ConfigurationProperty<?>> touchMembers() { return members(); } + + /** + * @return Configuration interface, for example {@code RootConfiguration}. Review comment: What should it return for named lists? I'd like that to be documented here ########## File path: modules/configuration-api/src/main/java/org/apache/ignite/configuration/NamedConfigurationTree.java ########## @@ -43,4 +43,14 @@ * @param listener Listener. */ void listenElements(ConfigurationNamedListListener<VIEW> listener); + + /** + * Get a placeholder that allows you to add listeners for changing configuration value Review comment: Usually method descriptions formulated like "Returns blah-blah" rather than "Do this and that", can you please run through your javadocs and correct that? ########## File path: modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationNotificationsUtil.java ########## @@ -30,66 +32,115 @@ import org.apache.ignite.configuration.notifications.ConfigurationListener; import org.apache.ignite.configuration.notifications.ConfigurationNamedListListener; import org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent; -import org.apache.ignite.internal.configuration.ConfigurationNode; import org.apache.ignite.internal.configuration.DynamicConfiguration; import org.apache.ignite.internal.configuration.DynamicProperty; import org.apache.ignite.internal.configuration.NamedListConfiguration; import org.apache.ignite.internal.configuration.tree.ConfigurationVisitor; import org.apache.ignite.internal.configuration.tree.InnerNode; import org.apache.ignite.internal.configuration.tree.NamedListNode; +import org.jetbrains.annotations.Nullable; import static org.apache.ignite.internal.configuration.util.ConfigurationUtil.innerNodeVisitor; import static org.apache.ignite.internal.configuration.util.ConfigurationUtil.leafNodeVisitor; import static org.apache.ignite.internal.configuration.util.ConfigurationUtil.namedListNodeVisitor; +import static org.apache.ignite.internal.util.CollectionUtils.viewReadOnly; /** */ public class ConfigurationNotificationsUtil { /** * Recursively notifies all public configuration listeners, accumulating resulting futures in {@code futures} list. + * * @param oldInnerNode Old configuration values root. * @param newInnerNode New configuration values root. * @param cfgNode Public configuration tree node corresponding to the current inner nodes. * @param storageRevision Storage revision. * @param futures Write-only list of futures to accumulate results. */ public static void notifyListeners( - InnerNode oldInnerNode, + @Nullable InnerNode oldInnerNode, InnerNode newInnerNode, DynamicConfiguration<InnerNode, ?> cfgNode, long storageRevision, List<CompletableFuture<?>> futures + ) { + notifyListeners(oldInnerNode, newInnerNode, cfgNode, storageRevision, futures, List.of(), new HashMap<>()); + } + + /** + * Recursively notifies all public configuration listeners, accumulating resulting futures in {@code futures} list. + * + * @param oldInnerNode Old configuration values root. + * @param newInnerNode New configuration values root. + * @param cfgNode Public configuration tree node corresponding to the current inner nodes. + * @param storageRevision Storage revision. + * @param futures Write-only list of futures to accumulate results. + * @param anyConfigs Current {@link NamedListConfiguration#any "any"} configurations. + * @param eventConfigs Configuration containers for {@link ConfigurationNotificationEvent}. + */ + private static void notifyListeners( Review comment: you know, this method became way too big, can you extract some parts so that it's easier to navigate the code? ########## File path: modules/configuration-api/src/main/java/org/apache/ignite/configuration/ConfigurationListenOnlyException.java ########## @@ -0,0 +1,32 @@ +/* + * 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.configuration; + +/** + * This exception is used if an attempt was made to get/update a configuration value in listen-only mode. + */ +public class ConfigurationListenOnlyException extends RuntimeException { Review comment: I think it is appropriate to have RuntimeException here. Maybe we should use IgniteException as a base class, I'm not sure yet ########## File path: modules/configuration-api/src/main/java/org/apache/ignite/configuration/NamedConfigurationTree.java ########## @@ -43,4 +43,14 @@ * @param listener Listener. */ void listenElements(ConfigurationNamedListListener<VIEW> listener); Review comment: I see no "stop" method here. Is this what's intended? ########## File path: modules/configuration-api/src/main/java/org/apache/ignite/configuration/notifications/ConfigurationNotificationEvent.java ########## @@ -50,4 +50,28 @@ * @return Counter value. */ long storageRevision(); + + /** + * Get the parent (any from the root) or current configuration. + * <p> + * For example, if we changed the child configuration, then we can get both the parent + * and the current child configuration. + * + * @param configClass Configuration interface, for example {@code RootConfiguration}. + * @param <T> Configuration type. + * @return Configuration instance. + */ + @Nullable <T extends ConfigurationProperty> T config(Class<T> configClass); + + /** + * Get the key of a named list item for the parent (any from the root) or current configuration. + * <p> + * For example, if a column of a table has changed, then we can get the name of the table and columns + * for which the changes have occurred. + * + * @param configClass Configuration interface, for example {@code TableConfiguration}. + * @param <T> Configuration type. + * @return Configuration instance. + */ + @Nullable <T extends ConfigurationProperty> String keyNamedConfig(Class<T> configClass); Review comment: Type T is excessive here, you should use "Class<? extends ConfigurationProperty>" ########## File path: modules/configuration-api/src/main/java/org/apache/ignite/configuration/notifications/ConfigurationNotificationEvent.java ########## @@ -50,4 +50,28 @@ * @return Counter value. */ long storageRevision(); + + /** + * Get the parent (any from the root) or current configuration. + * <p> + * For example, if we changed the child configuration, then we can get both the parent + * and the current child configuration. + * + * @param configClass Configuration interface, for example {@code RootConfiguration}. + * @param <T> Configuration type. + * @return Configuration instance. + */ + @Nullable <T extends ConfigurationProperty> T config(Class<T> configClass); + + /** + * Get the key of a named list item for the parent (any from the root) or current configuration. + * <p> + * For example, if a column of a table has changed, then we can get the name of the table and columns + * for which the changes have occurred. + * + * @param configClass Configuration interface, for example {@code TableConfiguration}. + * @param <T> Configuration type. + * @return Configuration instance. + */ + @Nullable <T extends ConfigurationProperty> String keyNamedConfig(Class<T> configClass); Review comment: Name implies that you return config, but instead you return name. I think you should rename this method ########## File path: modules/configuration/src/main/java/org/apache/ignite/internal/configuration/ConfigurationNode.java ########## @@ -17,24 +17,27 @@ package org.apache.ignite.internal.configuration; -import java.util.Collections; +import java.util.Collection; import java.util.List; import java.util.NoSuchElementException; import java.util.Objects; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.ignite.configuration.ConfigurationListenOnlyException; import org.apache.ignite.configuration.ConfigurationProperty; import org.apache.ignite.configuration.RootKey; import org.apache.ignite.configuration.notifications.ConfigurationListener; import org.apache.ignite.internal.configuration.tree.TraversableTreeNode; import org.apache.ignite.internal.configuration.util.ConfigurationUtil; import org.apache.ignite.internal.configuration.util.KeyNotFoundException; +import static java.util.Collections.unmodifiableCollection; + /** * Super class for dynamic configuration tree nodes. Has all common data and value retrieving algorithm in it. */ public abstract class ConfigurationNode<VIEW> implements ConfigurationProperty<VIEW> { /** Listeners of property update. */ - private final List<ConfigurationListener<VIEW>> updateListeners = new CopyOnWriteArrayList<>(); + private final Collection<ConfigurationListener<VIEW>> updateListeners = ConcurrentHashMap.newKeySet(); Review comment: This one does not preserve order of the elements, right? I think that guys who implement tables flow might be upset, we should find better collection -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org