You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/10 09:58:08 UTC

[lucene] 03/06: move out direct dependency on CLusterSingleton from CustomContainerPlugins

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch jira/solr-14749-cluster-singleton
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 56105d0beb0eaa8a54370494f7c6dab92818fe6f
Author: noblepaul <no...@gmail.com>
AuthorDate: Thu Oct 15 13:28:28 2020 +1100

    move out direct dependency on CLusterSingleton from CustomContainerPlugins
---
 .../apache/solr/api/CustomContainerPlugins.java    | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java b/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
index 119f651..616fb9d 100644
--- a/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
+++ b/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.lucene.util.ResourceLoaderAware;
@@ -59,6 +60,8 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
   private final ObjectMapper mapper = SolrJacksonAnnotationInspector.createObjectMapper();
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+  private final List<PluginRegistryListener> listeners = new CopyOnWriteArrayList<>();
+
   final CoreContainer coreContainer;
   final ApiBag containerApiBag;
 
@@ -70,6 +73,13 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
     return false;
   }
 
+  public void registerListener(PluginRegistryListener listener) {
+    listeners.add(listener);
+  }
+  public void unregisterListener(PluginRegistryListener listener) {
+    listeners.remove(listener);
+  }
+
   public CustomContainerPlugins(CoreContainer coreContainer, ApiBag apiBag) {
     this.coreContainer = coreContainer;
     this.containerApiBag = apiBag;
@@ -113,6 +123,7 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
       if (e.getValue() == Diff.REMOVED) {
         ApiInfo apiInfo = currentPlugins.remove(e.getKey());
         if (apiInfo == null) continue;
+        listeners.forEach(listener -> listener.deleted(apiInfo));
         handleClusterSingleton(null, apiInfo);
         for (ApiHolder holder : apiInfo.holders) {
           Api old = containerApiBag.unregister(holder.api.getEndPoint().method()[0],
@@ -143,6 +154,8 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
             containerApiBag.register(holder, getTemplateVars(apiInfo.info));
           }
           currentPlugins.put(e.getKey(), apiInfo);
+          final ApiInfo apiInfoFinal = apiInfo;
+          listeners.forEach(listener -> listener.added(apiInfoFinal));
           handleClusterSingleton(apiInfo, null);
         } else {
           //this plugin is being updated
@@ -151,6 +164,8 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
             //register all new paths
             containerApiBag.register(holder, getTemplateVars(apiInfo.info));
           }
+          final ApiInfo apiInfoFinal = apiInfo;
+          listeners.forEach(listener -> listener.modified(old, apiInfoFinal));
           handleClusterSingleton(apiInfo, old);
           if (old != null) {
             //this is an update of the plugin. But, it is possible that
@@ -240,6 +255,7 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
   @SuppressWarnings({"rawtypes"})
   public class ApiInfo implements ReflectMapWriter {
     List<ApiHolder> holders;
+
     @JsonProperty
     private final PluginMeta info;
 
@@ -265,6 +281,9 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
       return instance;
     }
 
+    public PluginMeta getInfo() {
+      return info.copy();
+    }
     @SuppressWarnings({"unchecked","rawtypes"})
     public ApiInfo(PluginMeta info, List<String> errs) {
       this.info = info;
@@ -401,4 +420,14 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
 
     return null;
   }
+
+  interface PluginRegistryListener {
+
+    void added(ApiInfo plugin);
+
+    void deleted(ApiInfo plugin);
+
+    void modified(ApiInfo old, ApiInfo replacement);
+
+  }
 }