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:10:15 UTC
[lucene-solr] branch branch_8x 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 branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 00f914a SOLR-14151: refactor to avoid code duplicate
00f914a is described below
commit 00f914a0a5a0f2fbd02d43395a271d59a7f904da
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 52706c7..5de8818 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -719,18 +719,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
*/
@@ -912,6 +919,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 f4ae860..3a06534 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 {
@@ -1319,7 +1321,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);
}
@@ -1329,7 +1331,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);
}
@@ -1338,13 +1340,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();
}
}
}