Apache Lucene open-source search software
SOLR-695 -- refactoring MultiCore to CoreContainer
Ryan McKinley425d8ac209c5
diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java b/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.javaindex 1528115075c..8a57e5f3e03 100644--- a/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java+++ b/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java@@ -34,7 +34,7 @@ import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;-import org.apache.solr.core.MultiCore;+import org.apache.solr.core.CoreContainer;import org.apache.solr.core.SolrCore;import org.apache.solr.request.BinaryResponseWriter;import org.apache.solr.request.QueryResponseWriter;@@ -55,9 +55,9 @@ import org.apache.solr.servlet.SolrRequestParsers;public class EmbeddedSolrServer extends SolrServer{- protected final MultiCore multicore; // either multicore+ protected final CoreContainer multicore; // either multicoreprotected final SolrCore core; // or single core- protected final String coreName; // use MultiCore registry+ protected final String coreName; // use CoreContainer registryprivate final SolrRequestParsers _parser;@@ -73,10 +73,10 @@ public class EmbeddedSolrServer extends SolrServer_parser = new SolrRequestParsers( null );}- public EmbeddedSolrServer( MultiCore multicore, String coreName )+ public EmbeddedSolrServer( CoreContainer multicore, String coreName ){if ( multicore == null ) {- throw new NullPointerException("MultiCore instance required");+ throw new NullPointerException("CoreContainer instance required");}this.core = null;this.multicore = multicore;diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java b/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.javaindex 004b8e1551a..85005ac47cd 100644--- a/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java+++ b/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java@@ -25,7 +25,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;import org.apache.solr.client.solrj.request.UpdateRequest.ACTION;import org.apache.solr.client.solrj.response.MultiCoreResponse;import org.apache.solr.common.SolrInputDocument;-import org.apache.solr.core.MultiCore;+import org.apache.solr.core.CoreContainer;/**@@ -34,7 +34,7 @@ import org.apache.solr.core.MultiCore;*/public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase{- protected static final MultiCore multicore = new MultiCore();+ protected static final CoreContainer multicore = new CoreContainer();@Override public String getSolrHome() { return "../../../example/multicore/"; }diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.javaindex 82a99d73cd2..17baea1805a 100644--- a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java+++ b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java@@ -76,6 +76,7 @@ public class JettyWebappTest extends TestCaseassertNotNull( html ); // real error will be an exceptionadminPath += "admin/";+ html = IOUtils.toString( new URL(adminPath).openStream() );assertNotNull( html ); // real error will be an exception// analysisdiff --git a/example/solr/conf/schema.xml b/example/solr/conf/schema.xmlindex ed27785ac60..6cdeebc9fc2 100755--- a/example/solr/conf/schema.xml+++ b/example/solr/conf/schema.xml@@ -204,6 +204,14 @@</analyzer></fieldType>+ <fieldType name="grams" class="solr.TextField" positionIncrementGap="100" >+ <analyzer>+ <tokenizer class="solr.StandardTokenizerFactory"/>+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>+ <filter class="solr.LengthFilterFactory" min="3" max="15" />+ <filter class="solr.WordGramFilterFactory" minLength="1" maxLength="3" sep=" " />+ </analyzer>+ </fieldType><!--Setup simple analysis for spell checkingdiff --git a/src/java/org/apache/solr/core/MultiCore.java b/src/java/org/apache/solr/core/CoreContainer.javasimilarity index 93%rename from src/java/org/apache/solr/core/MultiCore.javarename to src/java/org/apache/solr/core/CoreContainer.javaindex 9e250b75b98..3fd77dc7c29 100644--- a/src/java/org/apache/solr/core/MultiCore.java+++ b/src/java/org/apache/solr/core/CoreContainer.java@@ -36,7 +36,7 @@ import javax.xml.xpath.XPathConstants;import org.apache.solr.common.SolrException;import org.apache.solr.common.util.DOMUtil;import org.apache.solr.common.util.XML;-import org.apache.solr.handler.admin.MultiCoreHandler;+import org.apache.solr.handler.admin.CoreAdminHandler;import org.apache.solr.schema.IndexSchema;import org.w3c.dom.Node;import org.w3c.dom.NodeList;@@ -47,27 +47,27 @@ import org.xml.sax.SAXException;* @version $Id$* @since solr 1.3*/-public class MultiCore+public class CoreContainer{- protected static Logger log = Logger.getLogger(MultiCore.class.getName());+ protected static Logger log = Logger.getLogger(CoreContainer.class.getName());protected final Map<String, CoreDescriptor> cores = new LinkedHashMap<String, CoreDescriptor>();protected boolean enabled = false;protected boolean persistent = false;protected String adminPath = null;- protected MultiCoreHandler multiCoreHandler = null;+ protected CoreAdminHandler coreAdminHandler = null;protected File configFile = null;protected String libDir = null;protected ClassLoader libLoader = null;protected SolrResourceLoader loader = null;protected java.lang.ref.WeakReference<SolrCore> adminCore = null;- public MultiCore() {+ public CoreContainer() {}/**- * Initalize MultiCore directly from the constructor+ * Initalize CoreContainer directly from the constructor** @param dir* @param configFile@@ -75,7 +75,7 @@ public class MultiCore* @throws IOException* @throws SAXException*/- public MultiCore(String dir, File configFile ) throws ParserConfigurationException, IOException, SAXException+ public CoreContainer(String dir, File configFile ) throws ParserConfigurationException, IOException, SAXException{this.load(dir, configFile);}@@ -113,7 +113,7 @@ public class MultiCore}if( adminPath != null ) {- multiCoreHandler = this.createMultiCoreHandler();+ coreAdminHandler = this.createMultiCoreHandler();}NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core", XPathConstants.NODESET);@@ -357,9 +357,9 @@ public class MultiCore}/**- * Sets the preferred core used to handle MultiCore admin tasks.+ * Sets the preferred core used to handle CoreContainer admin tasks.* Note that getAdminCore is not symmetrical to this method since- * it will allways return an opened SolrCore.+ * it will always return an opened SolrCore.* This however can be useful implementing a "metacore" (a core of cores).*/public void setAdminCore(SolrCore core) {@@ -369,8 +369,8 @@ public class MultiCore}/**- * Gets a core to handle MultiCore admin tasks (@see SolrDispatchFilter).- * This makes the best attempt to reuse the same opened SolrCore accross calls.+ * Gets a core to handle CoreContainer admin tasks (@see SolrDispatchFilter).+ * This makes the best attempt to reuse the same opened SolrCore across calls.*/public SolrCore getAdminCore() {synchronized (cores) {@@ -391,20 +391,20 @@ public class MultiCore}/**- * Creates a MultiCoreHandler for this MultiCore.- * @return a MultiCoreHandler+ * Creates a CoreAdminHandler for this CoreContainer.+ * @return a CoreAdminHandler*/- protected MultiCoreHandler createMultiCoreHandler() {- return new MultiCoreHandler() {+ protected CoreAdminHandler createMultiCoreHandler() {+ return new CoreAdminHandler() {@Override- public MultiCore getMultiCore() {- return MultiCore.this;+ public CoreContainer getMultiCore() {+ return CoreContainer.this;}};}- public MultiCoreHandler getMultiCoreHandler() {- return multiCoreHandler;+ public CoreAdminHandler getMultiCoreHandler() {+ return coreAdminHandler;}public File getConfigFile() {diff --git a/src/java/org/apache/solr/core/CoreDescriptor.java b/src/java/org/apache/solr/core/CoreDescriptor.javaindex 0836d98c579..6e789a7348c 100644--- a/src/java/org/apache/solr/core/CoreDescriptor.java+++ b/src/java/org/apache/solr/core/CoreDescriptor.java@@ -17,13 +17,10 @@package org.apache.solr.core;-import org.xml.sax.SAXException;--import javax.xml.parsers.ParserConfigurationException;-import java.io.IOException;/*** A Solr core descriptor+ ** @since solr 1.3*/public class CoreDescriptor implements Cloneable {@@ -32,10 +29,10 @@ public class CoreDescriptor implements Cloneable {protected String configName;protected String schemaName;protected SolrCore core = null;- private final MultiCore multiCore;+ private final CoreContainer coreContainer;- public CoreDescriptor(MultiCore multiCore) {- this.multiCore = multiCore;+ public CoreDescriptor(CoreContainer coreContainer) {+ this.coreContainer = coreContainer;}/** Initialize defaults from instance directory. */@@ -58,7 +55,7 @@ public class CoreDescriptor implements Cloneable {this.instanceDir = descr.instanceDir;this.configName = descr.configName;this.schemaName = descr.schemaName;- multiCore = descr.multiCore;+ coreContainer = descr.coreContainer;}/**@return the default config name. */@@ -123,7 +120,7 @@ public class CoreDescriptor implements Cloneable {this.core = core;}- public MultiCore getMultiCore() {- return multiCore;+ public CoreContainer getMultiCore() {+ return coreContainer;}}diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.javaindex c159846b8bd..bec653287fc 100644--- a/src/java/org/apache/solr/core/SolrCore.java+++ b/src/java/org/apache/solr/core/SolrCore.java@@ -91,7 +91,7 @@ public final class SolrCore {public long getStartTime() { return startTime; }/**- * @deprecated Use {@link MultiCore#getCore(String)} instead.+ * @deprecated Use {@link CoreContainer#getCore(String)} instead.*/@Deprecatedprivate static SolrCore instance;@@ -345,7 +345,7 @@ public final class SolrCore {* @return the last core initialized. If you are using multiple cores,* this is not a function to use.*- * @deprecated Use {@link MultiCore#getCore(String)} instead.+ * @deprecated Use {@link CoreContainer#getCore(String)} instead.*/@Deprecatedpublic static SolrCore getSolrCore() {diff --git a/src/java/org/apache/solr/handler/admin/MultiCoreHandler.java b/src/java/org/apache/solr/handler/admin/CoreAdminHandler.javasimilarity index 92%rename from src/java/org/apache/solr/handler/admin/MultiCoreHandler.javarename to src/java/org/apache/solr/handler/admin/CoreAdminHandler.javaindex e1eb64eaf90..b753d5cd988 100644--- a/src/java/org/apache/solr/handler/admin/MultiCoreHandler.java+++ b/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java@@ -26,7 +26,7 @@ import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.params.MultiCoreParams.MultiCoreAction;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SimpleOrderedMap;-import org.apache.solr.core.MultiCore;+import org.apache.solr.core.CoreContainer;import org.apache.solr.core.SolrCore;import org.apache.solr.core.CoreDescriptor;import org.apache.solr.handler.RequestHandlerBase;@@ -39,12 +39,12 @@ import org.apache.solr.util.RefCounted;* @version $Id$* @since solr 1.3*/-public abstract class MultiCoreHandler extends RequestHandlerBase+public abstract class CoreAdminHandler extends RequestHandlerBase{- public MultiCoreHandler()+ public CoreAdminHandler(){super();- // Unlike most request handlers, MultiCore initialization+ // Unlike most request handlers, CoreContainer initialization// should happen in the constructor...}@@ -52,25 +52,25 @@ public abstract class MultiCoreHandler extends RequestHandlerBase@Overridefinal public void init(NamedList args) {throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,- "MultiCoreHandler should not be configured in solrconf.xml\n"++ "CoreAdminHandler should not be configured in solrconf.xml\n"+"it is a special Handler configured directly by the RequestDispatcher" );}/*** The instance of multicore this handler handles.- * This should be the MultiCore instance that created this handler.- * @return a MultiCore instance+ * This should be the CoreContainer instance that created this handler.+ * @return a CoreContainer instance*/- public abstract MultiCore getMultiCore();+ public abstract CoreContainer getMultiCore();@Overridepublic void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception{// Make sure the manager is enabled- MultiCore manager = getMultiCore();+ CoreContainer manager = getMultiCore();if( !manager.isEnabled() ) {throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,- "MultiCore support must be enabled at startup." );+ "CoreContainer support must be enabled at startup." );}boolean do_persist = false;diff --git a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.javaindex 1cf8156a524..6f16a771239 100644--- a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java@@ -52,7 +52,7 @@ public class SolrDispatchFilter implements Filterprotected CoreDescriptor singleCoreDescriptor;- protected MultiCore multicore;+ protected CoreContainer cores;protected String pathPrefix = null; // strip this from the beginning of a pathprotected String abortErrorMessage = null;protected final WeakHashMap<SolrCore, SolrRequestParsers> parsers = new WeakHashMap<SolrCore, SolrRequestParsers>();@@ -68,14 +68,14 @@ public class SolrDispatchFilter implements Filterthis.pathPrefix = config.getInitParameter( "path-prefix" );this.solrConfigFilename = config.getInitParameter("solrconfig-filename");- // multicore instantiation- this.multicore = initMultiCore(config);+ // cores instantiation+ this.cores = initMultiCore(config);- if(multicore != null && multicore.isEnabled() ) {+ if(cores != null && cores.isEnabled() ) {abortOnConfigurationError = false;singleCoreDescriptor = null;// if any core aborts on startup, then abort- for( SolrCore c : multicore.getCores() ) {+ for( SolrCore c : cores.getCores() ) {if( c.getSolrConfig().getBool( "abortOnConfigurationError",false) ) {abortOnConfigurationError = true;break;@@ -84,7 +84,7 @@ public class SolrDispatchFilter implements Filter}else {SolrConfig cfg = this.solrConfigFilename == null? new SolrConfig() : new SolrConfig(this.solrConfigFilename);- singleCoreDescriptor = new CoreDescriptor((MultiCore)null);+ singleCoreDescriptor = new CoreDescriptor((CoreContainer)null);singleCoreDescriptor.init("",cfg.getResourceLoader().getInstanceDir());SolrCore singlecore = new SolrCore( null, null, cfg, null, singleCoreDescriptor);singleCoreDescriptor.setCore(singlecore);@@ -108,7 +108,7 @@ public class SolrDispatchFilter implements Filterout.println( "Check your log files for more detailed information on what may be wrong.\n" );out.println( "If you want solr to continue after configuration errors, change: \n");out.println( " <abortOnConfigurationError>false</abortOnConfigurationError>\n" );- if (multicore != null && multicore.isEnabled()) {+ if (cores != null && cores.isEnabled()) {out.println( "in solr.xml\n" );} else {out.println( "in solrconfig.xml\n" );@@ -133,13 +133,13 @@ public class SolrDispatchFilter implements Filter}/**- * Initialize the multicore instance.+ * Initialize the cores instance.* @param config the filter configuration- * @return the multicore instance or null+ * @return the cores instance or null* @throws java.lang.Exception*/- protected MultiCore initMultiCore(FilterConfig config) throws Exception {- MultiCore mcore = new MultiCore();+ protected CoreContainer initMultiCore(FilterConfig config) throws Exception {+ CoreContainer mcore = new CoreContainer();String instanceDir = SolrResourceLoader.locateInstanceDir();File fconf = new File(instanceDir, "solr.xml");log.info("looking for solr.xml: " + fconf.getAbsolutePath());@@ -151,9 +151,9 @@ public class SolrDispatchFilter implements Filterpublic void destroy() {- if (multicore != null) {- multicore.shutdown();- multicore = null;+ if (cores != null) {+ cores.shutdown();+ cores = null;}if( singleCoreDescriptor != null ) {singleCoreDescriptor.getCore().close();@@ -189,18 +189,18 @@ public class SolrDispatchFilter implements Filterpath = path.substring( 0, idx );}- // By default use the single core. If multicore is enabled, look for one.+ // By default use the single core. If cores is enabled, look for one.final SolrCore core;- if (multicore != null && multicore.isEnabled()) {- req.setAttribute("org.apache.solr.MultiCore", multicore);+ if (cores != null && cores.isEnabled()) {+ req.setAttribute("org.apache.solr.CoreContainer", cores);// if this is the multi-core admin page, it will handle it- if( path.equals( multicore.getAdminPath() ) ) {- handler = multicore.getMultiCoreHandler();+ if( path.equals( cores.getAdminPath() ) ) {+ handler = cores.getMultiCoreHandler();// pick a core to use for output generation- core = multicore.getAdminCore();+ core = cores.getAdminCore();if( core == null ) {- throw new RuntimeException( "Can not find a valid core for the multicore admin handler" );+ throw new RuntimeException( "Can not find a valid core for the cores admin handler" );}} else {//otherwise, we should find a core from the path@@ -209,7 +209,7 @@ public class SolrDispatchFilter implements Filter// try to get the corename as a request parameter firstString corename = path.substring( 1, idx );path = path.substring( idx );- core = multicore.getCore( corename );+ core = cores.getCore( corename );} else {core = null;}@@ -231,7 +231,7 @@ public class SolrDispatchFilter implements Filter}// Determine the handler from the url path if not set- // (we might already have selected the multicore handler)+ // (we might already have selected the cores handler)if( handler == null && path.length() > 1 ) { // don't match "" or "/" as valid pathhandler = core.getRequestHandler( path );// no handler yet but allowed to handle select; let's checkdiff --git a/src/webapp/web/admin/index.jsp b/src/webapp/web/admin/index.jspindex ad4aeba78cc..0f77872a665 100644--- a/src/webapp/web/admin/index.jsp+++ b/src/webapp/web/admin/index.jsp@@ -52,7 +52,7 @@</tr><%-- List the cores (that arent this one) so we can switch --%>-<% org.apache.solr.core.MultiCore multicore = (org.apache.solr.core.MultiCore)request.getAttribute("org.apache.solr.MultiCore");+<% org.apache.solr.core.CoreContainer multicore = (org.apache.solr.core.CoreContainer)request.getAttribute("org.apache.solr.CoreContainer");if (multicore!=null) {java.util.Collection<SolrCore> cores = multicore.getCores();if (cores.size() > 1) {%><tr><td><strong>Cores:</strong><br></td><td><%diff --git a/src/webapp/web/index.jsp b/src/webapp/web/index.jspindex 502f8051c1b..b026c895c50 100644--- a/src/webapp/web/index.jsp+++ b/src/webapp/web/index.jsp@@ -28,7 +28,7 @@<a href="."><img border="0" align="right" height="61" width="142" src="admin/solr-head.gif" alt="Solr"/></a><%- org.apache.solr.core.MultiCore multicore = (org.apache.solr.core.MultiCore)request.getAttribute("org.apache.solr.MultiCore");+ org.apache.solr.core.CoreContainer multicore = (org.apache.solr.core.CoreContainer)request.getAttribute("org.apache.solr.CoreContainer");if(multicore != null && multicore.isEnabled() ) {for( org.apache.solr.core.SolrCore core : multicore.getCores() ) {%><a href="<%= core.getName() %>/admin/">Admin <%= core.getName() %></a><br/>