mirror of https://github.com/apache/lucene.git
SOLR-1198 moved PluginInfo out of solrconfig
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@807120 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b9071efb3
commit
7b708bb413
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* 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.solr.core;
|
||||
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.DOMUtil;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An Object which represents a Plugin of any type
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PluginInfo {
|
||||
public final String startup, name, className, type;
|
||||
public final boolean isDefault;
|
||||
public final NamedList initArgs;
|
||||
public final Map<String, String> attributes;
|
||||
|
||||
public PluginInfo(String type, String startup, String name, String className,
|
||||
boolean isdefault, NamedList initArgs, Map<String, String> otherAttrs) {
|
||||
this.type = type;
|
||||
this.startup = startup;
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.isDefault = isdefault;
|
||||
this.initArgs = initArgs;
|
||||
attributes = otherAttrs == null ? Collections.<String, String>emptyMap() : otherAttrs;
|
||||
}
|
||||
|
||||
|
||||
public PluginInfo(Node node, String err, boolean requireName) {
|
||||
type = node.getNodeName();
|
||||
name = DOMUtil.getAttr(node, "name", requireName ? err : null);
|
||||
className = DOMUtil.getAttr(node, "class", err);
|
||||
isDefault = Boolean.parseBoolean(DOMUtil.getAttr(node, "default", null));
|
||||
startup = DOMUtil.getAttr(node, "startup", null);
|
||||
initArgs = DOMUtil.childNodesToNamedList(node);
|
||||
Map<String, String> m = new HashMap<String, String>();
|
||||
NamedNodeMap nnm = node.getAttributes();
|
||||
for (int i = 0; i < nnm.getLength(); i++) {
|
||||
String name = nnm.item(i).getNodeName();
|
||||
m.put(name, nnm.item(i).getNodeValue());
|
||||
}
|
||||
attributes = Collections.unmodifiableMap(m);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
if (name != null) sb.append("name = " + name + ",");
|
||||
if (className != null) sb.append("class = " + className + ",");
|
||||
if (isDefault) sb.append("default = " + isDefault + ",");
|
||||
if (startup != null) sb.append("startup = " + startup + ",");
|
||||
if (initArgs.size() > 0) sb.append("args = " + initArgs);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -135,8 +135,8 @@ final class RequestHandlers {
|
|||
*/
|
||||
|
||||
void initHandlersFromConfig(SolrConfig config ){
|
||||
Map<SolrConfig.PluginInfo,SolrRequestHandler> handlers = new HashMap<SolrConfig.PluginInfo,SolrRequestHandler>();
|
||||
for (SolrConfig.PluginInfo info : config.getReqHandlerInfo()) {
|
||||
Map<PluginInfo,SolrRequestHandler> handlers = new HashMap<PluginInfo,SolrRequestHandler>();
|
||||
for (PluginInfo info : config.getReqHandlerInfo()) {
|
||||
try {
|
||||
SolrRequestHandler requestHandler;
|
||||
if( info.startup != null ) {
|
||||
|
@ -166,7 +166,7 @@ final class RequestHandlers {
|
|||
SolrException.logOnce(log,null,e);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<SolrConfig.PluginInfo,SolrRequestHandler> entry : handlers.entrySet()) {
|
||||
for (Map.Entry<PluginInfo,SolrRequestHandler> entry : handlers.entrySet()) {
|
||||
entry.getValue().init(entry.getKey().initArgs);
|
||||
}
|
||||
|
||||
|
|
|
@ -460,61 +460,6 @@ public class SolrConfig extends Config {
|
|||
}
|
||||
}
|
||||
|
||||
public static class PluginInfo {
|
||||
public final String startup, name, className;
|
||||
public final boolean isDefault;
|
||||
public final NamedList initArgs;
|
||||
public final Map<String ,String> otherAttributes;
|
||||
|
||||
public PluginInfo(String startup, String name, String className,
|
||||
boolean isdefault, NamedList initArgs, Map<String ,String> otherAttrs) {
|
||||
this.startup = startup;
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.isDefault = isdefault;
|
||||
this.initArgs = initArgs;
|
||||
otherAttributes = otherAttrs == null ? Collections.<String ,String >emptyMap(): otherAttrs;
|
||||
}
|
||||
|
||||
|
||||
public PluginInfo(Node node, String err, boolean requireName) {
|
||||
name = DOMUtil.getAttr(node, "name", requireName ? err : null);
|
||||
className = DOMUtil.getAttr(node, "class", err );
|
||||
isDefault = Boolean.parseBoolean(DOMUtil.getAttr(node, "default", null));
|
||||
startup = DOMUtil.getAttr(node, "startup",null);
|
||||
initArgs = DOMUtil.childNodesToNamedList(node);
|
||||
Map<String ,String> m = new HashMap<String, String>();
|
||||
NamedNodeMap nnm = node.getAttributes();
|
||||
for (int i = 0; i < nnm.getLength(); i++) {
|
||||
String name= nnm.item(i).getNodeName();
|
||||
if(knownAttrs.contains(name)) continue;
|
||||
m.put(name, nnm.item(i).getNodeValue());
|
||||
}
|
||||
otherAttributes = m.isEmpty() ?
|
||||
Collections.<String ,String >emptyMap():
|
||||
Collections.unmodifiableMap(m);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
if(name != null) sb.append("name = "+name +",");
|
||||
if(className != null) sb.append("class = "+className +",");
|
||||
if(isDefault) sb.append("default = "+isDefault +",");
|
||||
if(startup != null) sb.append("startup = "+startup +",");
|
||||
if(initArgs.size() >0) sb.append("args = "+initArgs);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
private static final Set<String> knownAttrs = new HashSet<String>();
|
||||
static {
|
||||
knownAttrs.add("name");
|
||||
knownAttrs.add("class");
|
||||
knownAttrs.add("startup");
|
||||
knownAttrs.add("default");
|
||||
}
|
||||
}
|
||||
|
||||
public List<PluginInfo> getReqHandlerInfo() { return reqHandlerInfo; }
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
}
|
||||
|
||||
private void initDeletionPolicy() {
|
||||
SolrConfig.PluginInfo info = solrConfig.getDeletionPolicyInfo();
|
||||
PluginInfo info = solrConfig.getDeletionPolicyInfo();
|
||||
IndexDeletionPolicy delPolicy = null;
|
||||
if(info != null){
|
||||
delPolicy = createInstance(info.className,IndexDeletionPolicy.class,"Deletion Policy for SOLR");
|
||||
|
@ -261,9 +261,9 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
solrDelPolicy = new IndexDeletionPolicyWrapper(delPolicy);
|
||||
}
|
||||
|
||||
private List<SolrEventListener> parseListener(List<SolrConfig.PluginInfo> path) {
|
||||
private List<SolrEventListener> parseListener(List<PluginInfo> path) {
|
||||
List<SolrEventListener> lst = new ArrayList<SolrEventListener>();
|
||||
for (SolrConfig.PluginInfo info : path) {
|
||||
for (PluginInfo info : path) {
|
||||
SolrEventListener listener = createEventListener(info.className);
|
||||
listener.init(info.initArgs);
|
||||
lst.add(listener);
|
||||
|
@ -328,7 +328,7 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
|
||||
private void initDirectoryFactory() {
|
||||
DirectoryFactory dirFactory;
|
||||
SolrConfig.PluginInfo info = solrConfig.getDirectoryfactoryInfo();
|
||||
PluginInfo info = solrConfig.getDirectoryfactoryInfo();
|
||||
if (info != null) {
|
||||
dirFactory = (DirectoryFactory) getResourceLoader().newInstance(info.className);
|
||||
dirFactory.init(info.initArgs);
|
||||
|
@ -341,7 +341,7 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
|
||||
private void initIndexReaderFactory() {
|
||||
IndexReaderFactory indexReaderFactory;
|
||||
SolrConfig.PluginInfo info = solrConfig.getIndexReaderFactoryInfo();
|
||||
PluginInfo info = solrConfig.getIndexReaderFactoryInfo();
|
||||
if (info != null) {
|
||||
indexReaderFactory = (IndexReaderFactory) resourceLoader.newInstance(info.className);
|
||||
indexReaderFactory.init(info.initArgs);
|
||||
|
@ -590,19 +590,19 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
private Map<String,UpdateRequestProcessorChain> loadUpdateProcessorChains() {
|
||||
final Map<String, UpdateRequestProcessorChain> map = new HashMap<String, UpdateRequestProcessorChain>();
|
||||
UpdateRequestProcessorChain def = null;
|
||||
Map<String, List<SolrConfig.PluginInfo>> infos = solrConfig.getUpdateProcessorChainInfo();
|
||||
Map<String, List<PluginInfo>> infos = solrConfig.getUpdateProcessorChainInfo();
|
||||
if (!infos.isEmpty()) {
|
||||
boolean defaultProcessed = false;
|
||||
List<SolrConfig.PluginInfo> defProcessorChainInfo = infos.get(null);// this is the default one
|
||||
for (Map.Entry<String, List<SolrConfig.PluginInfo>> e : solrConfig.getUpdateProcessorChainInfo().entrySet()) {
|
||||
List<SolrConfig.PluginInfo> processorsInfo = e.getValue();
|
||||
List<PluginInfo> defProcessorChainInfo = infos.get(null);// this is the default one
|
||||
for (Map.Entry<String, List<PluginInfo>> e : solrConfig.getUpdateProcessorChainInfo().entrySet()) {
|
||||
List<PluginInfo> processorsInfo = e.getValue();
|
||||
if (processorsInfo == defProcessorChainInfo && defaultProcessed) {
|
||||
map.put(e.getKey(), def);
|
||||
continue;
|
||||
}
|
||||
UpdateRequestProcessorFactory[] chain = new UpdateRequestProcessorFactory[processorsInfo.size()];
|
||||
for (int i = 0; i < processorsInfo.size(); i++) {
|
||||
SolrConfig.PluginInfo info = processorsInfo.get(i);
|
||||
PluginInfo info = processorsInfo.get(i);
|
||||
chain[i] = createInstance(info.className, UpdateRequestProcessorFactory.class, null);
|
||||
chain[i].init(info.initArgs);
|
||||
}
|
||||
|
@ -1465,9 +1465,9 @@ public final class SolrCore implements SolrInfoMBean {
|
|||
}
|
||||
}
|
||||
|
||||
public <T> T initPlugins(List<SolrConfig.PluginInfo> pluginInfos , Map<String ,T> registry, Class<T> type){
|
||||
public <T> T initPlugins(List<PluginInfo> pluginInfos , Map<String ,T> registry, Class<T> type){
|
||||
T def = null;
|
||||
for (SolrConfig.PluginInfo info : pluginInfos) {
|
||||
for (PluginInfo info : pluginInfos) {
|
||||
T o = createInstance(info.className,type, type.getSimpleName());
|
||||
if (o instanceof NamedListInitializedPlugin) {
|
||||
((NamedListInitializedPlugin) o).init(info.initArgs);
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.solr.common.params.SolrParams;
|
|||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.PluginInfo;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.schema.SchemaField;
|
||||
|
@ -63,7 +64,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter
|
|||
// Load the fragmenters
|
||||
ResourceLoader loader= config.getResourceLoader();
|
||||
SolrFragmenter frag = null;
|
||||
for (SolrConfig.PluginInfo info : config.getHighlightingFragmenterInfo()) {
|
||||
for (PluginInfo info : config.getHighlightingFragmenterInfo()) {
|
||||
SolrFragmenter fragmenter = (SolrFragmenter) loader.newInstance(info.className);
|
||||
fragmenter.init(info.initArgs);
|
||||
if(info.isDefault) frag = fragmenter;
|
||||
|
@ -77,7 +78,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter
|
|||
fragmenters.put( null, frag );
|
||||
// Load the formatters
|
||||
SolrFormatter fmt = null;
|
||||
for (SolrConfig.PluginInfo info : config.getHighlightingFormatterInfo()) {
|
||||
for (PluginInfo info : config.getHighlightingFormatterInfo()) {
|
||||
SolrFormatter formatter = (SolrFormatter) loader.newInstance(info.className);
|
||||
formatter.init(info.initArgs);
|
||||
formatters.put(info.name, formatter);
|
||||
|
|
Loading…
Reference in New Issue