You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2020/10/07 05:05:02 UTC

[lucene-solr] branch master updated: SOLR-14151: refactor to avoid code duplicate

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

noble pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a8136b  SOLR-14151: refactor to avoid code duplicate
2a8136b is described below

commit 2a8136b3fd597cec2f8f54d29b2834b7853ffbae
Author: noblepaul <no...@gmail.com>
AuthorDate: Wed Oct 7 16:04:35 2020 +1100

    SOLR-14151: refactor to avoid code duplicate
---
 .../org/apache/solr/core/SolrResourceLoader.java    | 21 ++++++++++++++-------
 .../org/apache/solr/schema/ManagedIndexSchema.java  | 11 +++++------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
index 69eabc5..609da78 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -694,18 +694,25 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
       }
 
       for (ResourceLoaderAware aware : arr) {
-        CURRENT_AWARE.set(aware);
-        try{
-          aware.inform(loader);
-        } finally {
-          CURRENT_AWARE.remove();
-        }
+        informAware(loader, aware);
 
       }
     }
   }
 
   /**
+   * Set the current {@link ResourceLoaderAware} object in thread local so that appropriate classloader can be used for package loaded classes
+   */
+  public static void informAware(ResourceLoader loader, ResourceLoaderAware aware) throws IOException {
+    CURRENT_AWARE.set(aware);
+    try{
+      aware.inform(loader);
+    } finally {
+      CURRENT_AWARE.remove();
+    }
+  }
+
+  /**
    * Register any {@link SolrInfoBean}s
    *
    * @param infoRegistry The Info Registry
@@ -883,6 +890,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
   }
 
   //This is to verify if this requires to use the schema classloader for classes loaded from packages
-  public static final ThreadLocal<ResourceLoaderAware> CURRENT_AWARE = new ThreadLocal<>();
+  private static final ThreadLocal<ResourceLoaderAware> CURRENT_AWARE = new ThreadLocal<>();
 
 }
diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
index c1815e0..e7a748c 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
@@ -79,6 +79,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.InputSource;
 
+import static org.apache.solr.core.SolrResourceLoader.informAware;
+
 /** Solr-managed schema - non-user-editable, but can be mutable via internal and external REST API requests. */
 public final class ManagedIndexSchema extends IndexSchema {
 
@@ -1324,7 +1326,7 @@ public final class ManagedIndexSchema extends IndexSchema {
     for (CharFilterFactory next : charFilters) {
       if (next instanceof ResourceLoaderAware) {
         try {
-          ((ResourceLoaderAware) next).inform(loader);
+          informAware(loader, (ResourceLoaderAware) next);
         } catch (IOException e) {
           throw new SolrException(ErrorCode.SERVER_ERROR, e);
         }
@@ -1334,7 +1336,7 @@ public final class ManagedIndexSchema extends IndexSchema {
     TokenizerFactory tokenizerFactory = chain.getTokenizerFactory();
     if (tokenizerFactory instanceof ResourceLoaderAware) {
       try {
-        ((ResourceLoaderAware) tokenizerFactory).inform(loader);
+        informAware(loader, (ResourceLoaderAware) tokenizerFactory);
       } catch (IOException e) {
         throw new SolrException(ErrorCode.SERVER_ERROR, e);
       }
@@ -1343,13 +1345,10 @@ public final class ManagedIndexSchema extends IndexSchema {
     TokenFilterFactory[] filters = chain.getTokenFilterFactories();
     for (TokenFilterFactory next : filters) {
       if (next instanceof ResourceLoaderAware) {
-        SolrResourceLoader.CURRENT_AWARE.set((ResourceLoaderAware) next);
         try {
-          ((ResourceLoaderAware) next).inform(loader);
+          informAware(loader, (ResourceLoaderAware) next);
         } catch (IOException e) {
           throw new SolrException(ErrorCode.SERVER_ERROR, e);
-        } finally {
-          SolrResourceLoader.CURRENT_AWARE.remove();
         }
       }
     }