You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/11/03 14:04:01 UTC

[GitHub] [lucene-solr] noblepaul commented on a change in pull request #1962: SOLR-14749 Provide a clean API for cluster-level event processing

noblepaul commented on a change in pull request #1962:
URL: https://github.com/apache/lucene-solr/pull/1962#discussion_r515762968



##########
File path: solr/core/src/java/org/apache/solr/core/ClusterEventProducerFactory.java
##########
@@ -0,0 +1,178 @@
+package org.apache.solr.core;
+
+import org.apache.solr.api.CustomContainerPlugins;
+import org.apache.solr.cluster.events.ClusterEvent;
+import org.apache.solr.cluster.events.ClusterEventListener;
+import org.apache.solr.cluster.events.ClusterEventProducer;
+import org.apache.solr.cluster.events.impl.DefaultClusterEventProducer;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This class helps in handling the initial registration of plugin-based listeners,
+ * when both the final {@link ClusterEventProducer} implementation and listeners
+ * are configured using plugins.
+ */
+public class ClusterEventProducerFactory implements ClusterEventProducer {
+  private Map<ClusterEvent.EventType, Set<ClusterEventListener>> initialListeners = new HashMap<>();
+  private CustomContainerPlugins.PluginRegistryListener initialPluginListener;
+  private final CoreContainer cc;
+  private boolean created = false;
+
+  public ClusterEventProducerFactory(CoreContainer cc) {
+    this.cc = cc;
+    initialPluginListener = new CustomContainerPlugins.PluginRegistryListener() {
+      @Override
+      public void added(CustomContainerPlugins.ApiInfo plugin) {
+        if (plugin == null || plugin.getInstance() == null) {
+          return;
+        }
+        Object instance = plugin.getInstance();
+        if (instance instanceof ClusterEventListener) {
+          registerListener((ClusterEventListener) instance);
+        }
+      }
+
+      @Override
+      public void deleted(CustomContainerPlugins.ApiInfo plugin) {
+        if (plugin == null || plugin.getInstance() == null) {
+          return;
+        }
+        Object instance = plugin.getInstance();
+        if (instance instanceof ClusterEventListener) {
+          unregisterListener((ClusterEventListener) instance);
+        }
+      }
+
+      @Override
+      public void modified(CustomContainerPlugins.ApiInfo old, CustomContainerPlugins.ApiInfo replacement) {
+        added(replacement);
+        deleted(old);
+      }
+    };
+  }
+
+  /**
+   * This method returns an initial plugin registry listener that helps to capture the
+   * freshly loaded listener plugins before the final cluster event producer is created.
+   * @return initial listener
+   */
+  public CustomContainerPlugins.PluginRegistryListener getPluginRegistryListener() {
+    return initialPluginListener;
+  }
+
+  /**
+   * Create a {@link ClusterEventProducer} based on the current plugin configurations.
+   * <p>NOTE: this method can only be called once because it has side-effects, such as
+   * transferring the initially collected listeners to the resulting producer's instance, and
+   * installing a {@link org.apache.solr.api.CustomContainerPlugins.PluginRegistryListener}.
+   * Calling this method more than once will result in an exception.</p>
+   * @param plugins current plugin configurations
+   * @return configured instance of cluster event producer (with side-effects, see above)
+   */
+  public ClusterEventProducer create(CustomContainerPlugins plugins) {
+    if (created) {
+      throw new RuntimeException("this factory can be called only once!");
+    }
+    final ClusterEventProducer clusterEventProducer;
+    CustomContainerPlugins.ApiInfo clusterEventProducerInfo = plugins.getPlugin(ClusterEventProducer.PLUGIN_NAME);
+    if (clusterEventProducerInfo != null) {
+      // the listener in ClusterSingletons already registered it
+      clusterEventProducer = (ClusterEventProducer) clusterEventProducerInfo.getInstance();
+    } else {
+      // create the default impl
+      clusterEventProducer = new DefaultClusterEventProducer(cc);

Review comment:
       NO , please. 
   
   I am -1 on enabling this by default

##########
File path: solr/core/src/java/org/apache/solr/core/ClusterEventProducerFactory.java
##########
@@ -0,0 +1,178 @@
+package org.apache.solr.core;
+
+import org.apache.solr.api.CustomContainerPlugins;
+import org.apache.solr.cluster.events.ClusterEvent;
+import org.apache.solr.cluster.events.ClusterEventListener;
+import org.apache.solr.cluster.events.ClusterEventProducer;
+import org.apache.solr.cluster.events.impl.DefaultClusterEventProducer;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This class helps in handling the initial registration of plugin-based listeners,
+ * when both the final {@link ClusterEventProducer} implementation and listeners
+ * are configured using plugins.
+ */
+public class ClusterEventProducerFactory implements ClusterEventProducer {
+  private Map<ClusterEvent.EventType, Set<ClusterEventListener>> initialListeners = new HashMap<>();
+  private CustomContainerPlugins.PluginRegistryListener initialPluginListener;
+  private final CoreContainer cc;
+  private boolean created = false;
+
+  public ClusterEventProducerFactory(CoreContainer cc) {
+    this.cc = cc;
+    initialPluginListener = new CustomContainerPlugins.PluginRegistryListener() {
+      @Override
+      public void added(CustomContainerPlugins.ApiInfo plugin) {
+        if (plugin == null || plugin.getInstance() == null) {
+          return;
+        }
+        Object instance = plugin.getInstance();
+        if (instance instanceof ClusterEventListener) {
+          registerListener((ClusterEventListener) instance);
+        }
+      }
+
+      @Override
+      public void deleted(CustomContainerPlugins.ApiInfo plugin) {
+        if (plugin == null || plugin.getInstance() == null) {
+          return;
+        }
+        Object instance = plugin.getInstance();
+        if (instance instanceof ClusterEventListener) {
+          unregisterListener((ClusterEventListener) instance);
+        }
+      }
+
+      @Override
+      public void modified(CustomContainerPlugins.ApiInfo old, CustomContainerPlugins.ApiInfo replacement) {
+        added(replacement);
+        deleted(old);
+      }
+    };
+  }
+
+  /**
+   * This method returns an initial plugin registry listener that helps to capture the
+   * freshly loaded listener plugins before the final cluster event producer is created.
+   * @return initial listener
+   */
+  public CustomContainerPlugins.PluginRegistryListener getPluginRegistryListener() {
+    return initialPluginListener;
+  }
+
+  /**
+   * Create a {@link ClusterEventProducer} based on the current plugin configurations.
+   * <p>NOTE: this method can only be called once because it has side-effects, such as
+   * transferring the initially collected listeners to the resulting producer's instance, and
+   * installing a {@link org.apache.solr.api.CustomContainerPlugins.PluginRegistryListener}.
+   * Calling this method more than once will result in an exception.</p>
+   * @param plugins current plugin configurations
+   * @return configured instance of cluster event producer (with side-effects, see above)
+   */
+  public ClusterEventProducer create(CustomContainerPlugins plugins) {
+    if (created) {
+      throw new RuntimeException("this factory can be called only once!");
+    }
+    final ClusterEventProducer clusterEventProducer;
+    CustomContainerPlugins.ApiInfo clusterEventProducerInfo = plugins.getPlugin(ClusterEventProducer.PLUGIN_NAME);
+    if (clusterEventProducerInfo != null) {
+      // the listener in ClusterSingletons already registered it
+      clusterEventProducer = (ClusterEventProducer) clusterEventProducerInfo.getInstance();
+    } else {
+      // create the default impl
+      clusterEventProducer = new DefaultClusterEventProducer(cc);

Review comment:
       NO , please. 
   
   I am -1 on enabling this by default. We are trying to repeat the same mistake we did with the previous version. TBH, nobody should be bothered with any event producer and the user should not pay a price for that

##########
File path: solr/core/src/java/org/apache/solr/core/ClusterEventProducerFactory.java
##########
@@ -0,0 +1,178 @@
+package org.apache.solr.core;
+
+import org.apache.solr.api.CustomContainerPlugins;
+import org.apache.solr.cluster.events.ClusterEvent;
+import org.apache.solr.cluster.events.ClusterEventListener;
+import org.apache.solr.cluster.events.ClusterEventProducer;
+import org.apache.solr.cluster.events.impl.DefaultClusterEventProducer;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This class helps in handling the initial registration of plugin-based listeners,
+ * when both the final {@link ClusterEventProducer} implementation and listeners
+ * are configured using plugins.
+ */
+public class ClusterEventProducerFactory implements ClusterEventProducer {
+  private Map<ClusterEvent.EventType, Set<ClusterEventListener>> initialListeners = new HashMap<>();
+  private CustomContainerPlugins.PluginRegistryListener initialPluginListener;
+  private final CoreContainer cc;
+  private boolean created = false;
+
+  public ClusterEventProducerFactory(CoreContainer cc) {
+    this.cc = cc;
+    initialPluginListener = new CustomContainerPlugins.PluginRegistryListener() {
+      @Override
+      public void added(CustomContainerPlugins.ApiInfo plugin) {
+        if (plugin == null || plugin.getInstance() == null) {
+          return;
+        }
+        Object instance = plugin.getInstance();
+        if (instance instanceof ClusterEventListener) {
+          registerListener((ClusterEventListener) instance);
+        }
+      }
+
+      @Override
+      public void deleted(CustomContainerPlugins.ApiInfo plugin) {
+        if (plugin == null || plugin.getInstance() == null) {
+          return;
+        }
+        Object instance = plugin.getInstance();
+        if (instance instanceof ClusterEventListener) {
+          unregisterListener((ClusterEventListener) instance);
+        }
+      }
+
+      @Override
+      public void modified(CustomContainerPlugins.ApiInfo old, CustomContainerPlugins.ApiInfo replacement) {
+        added(replacement);
+        deleted(old);
+      }
+    };
+  }
+
+  /**
+   * This method returns an initial plugin registry listener that helps to capture the
+   * freshly loaded listener plugins before the final cluster event producer is created.
+   * @return initial listener
+   */
+  public CustomContainerPlugins.PluginRegistryListener getPluginRegistryListener() {
+    return initialPluginListener;
+  }
+
+  /**
+   * Create a {@link ClusterEventProducer} based on the current plugin configurations.
+   * <p>NOTE: this method can only be called once because it has side-effects, such as
+   * transferring the initially collected listeners to the resulting producer's instance, and
+   * installing a {@link org.apache.solr.api.CustomContainerPlugins.PluginRegistryListener}.
+   * Calling this method more than once will result in an exception.</p>
+   * @param plugins current plugin configurations
+   * @return configured instance of cluster event producer (with side-effects, see above)
+   */
+  public ClusterEventProducer create(CustomContainerPlugins plugins) {
+    if (created) {
+      throw new RuntimeException("this factory can be called only once!");
+    }
+    final ClusterEventProducer clusterEventProducer;
+    CustomContainerPlugins.ApiInfo clusterEventProducerInfo = plugins.getPlugin(ClusterEventProducer.PLUGIN_NAME);
+    if (clusterEventProducerInfo != null) {
+      // the listener in ClusterSingletons already registered it
+      clusterEventProducer = (ClusterEventProducer) clusterEventProducerInfo.getInstance();
+    } else {
+      // create the default impl
+      clusterEventProducer = new DefaultClusterEventProducer(cc);

Review comment:
       NO , please. 
   
   I am -1 on enabling this by default. We are trying to repeat the same mistake we did with the previous version. TBH, nobody should be bothered with any event producer and the user should not pay a price for that unless it is explicitly configured




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org