tkalkirill commented on a change in pull request #589:
URL: https://github.com/apache/ignite-3/pull/589#discussion_r793496160



##########
File path: 
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/ConfigurationListenerHolder.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.configuration;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Holder (thread safe) for configuration change listeners.
+ */
+class ConfigurationListenerHolder<L> {
+    private final Collection<Container<L>> containers = new 
CopyOnWriteArrayList<>();
+
+    /**
+     * Adds a listener.
+     *
+     * @param listener Configuration change listener.
+     * @param notificationNumber Configuration notification listener number 
after which the listener will be called.
+     * @see ConfigurationListenerHolder#listeners
+     */
+    void addListener(L listener, long notificationNumber) {
+        containers.add(new Container<>(listener, notificationNumber));
+    }
+
+    /**
+     * Removes the listener.
+     *
+     * @param listener Configuration change listener.
+     */
+    void removeListener(L listener) {
+        containers.remove(new Container<>(listener, -1) {
+            /** {@inheritDoc} */
+            @Override
+            public boolean equals(Object obj) {
+                return listener == ((Container<L>) obj).listener;
+            }
+        });
+    }
+
+    /**
+     * Returns an iterator of the listeners for the {@code notificationNumber} 
(were added for and before it).
+     *
+     * <p>NOTE: {@link Iterator#remove} - not supported.
+     *
+     * @param notificationNumber Configuration notification listener number.
+     * @see ConfigurationListenerHolder#addListener
+     */
+    Iterator<L> listeners(long notificationNumber) {

Review comment:
       We discussed personally that at the moment it is difficult to rewrite 
the code for streams because of **any()**, since streams are one-time, we need 
to figure out how to rewrite the code for **any()**.




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