Skip to content

Apache Lucene open-source search software

SOLR-350 -- removed static access for SolrMultiCore. Also adding a new constructor to MultiCore

Ryan McKinley5e3d3a2df043
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.java
index 81df7103f68..65bcba9e600 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
@@ -34,8 +34,7 @@ import org.apache.solr.core.MultiCore;
*/
public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
{
- @SuppressWarnings("deprecation")
- protected static final MultiCore multicore = org.apache.solr.core.SolrMultiCore.getInstance();
+ protected static final MultiCore multicore = new MultiCore();
@Override public String getSolrHome() { return "../../../example/multicore/"; }
diff --git a/src/java/org/apache/solr/core/MultiCore.java b/src/java/org/apache/solr/core/MultiCore.java
index 4864563d879..f517df90677 100644
--- a/src/java/org/apache/solr/core/MultiCore.java
+++ b/src/java/org/apache/solr/core/MultiCore.java
@@ -63,6 +63,21 @@ public class MultiCore
protected java.lang.ref.WeakReference<SolrCore> adminCore = null;
public MultiCore() {
+
+ }
+
+ /**
+ * Initalize MultiCore directly from the constructor
+ *
+ * @param dir
+ * @param configFile
+ * @throws ParserConfigurationException
+ * @throws IOException
+ * @throws SAXException
+ */
+ public MultiCore(String dir, File configFile ) throws ParserConfigurationException, IOException, SAXException
+ {
+ this.load(dir, configFile);
}
//-------------------------------------------------------------------
diff --git a/src/java/org/apache/solr/core/SolrMultiCore.java b/src/java/org/apache/solr/core/SolrMultiCore.java
deleted file mode 100644
index 350fa8f0548..00000000000
--- a/src/java/org/apache/solr/core/SolrMultiCore.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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;
-
-/**
- * A MultiCore singleton.
- * Marked as deprecated to avoid usage proliferation of core code that would
- * assume MultiCore being a singleton. In solr 2.0, the MultiCore factory
- * should be popluated with a standard tool like spring. Until then, this is
- * a simple static factory that should not be used widely.
- *
- * @version $Id$
- * @since solr 1.3
- */
-@Deprecated
-public final class SolrMultiCore extends MultiCore
-{
- private static MultiCore instance = null;
-
- // no one else can make the registry
- private SolrMultiCore() {}
-
- /** Returns a default MultiCore singleton.
- * @return
- */
- public static synchronized MultiCore getInstance() {
- if (instance == null) {
- instance = new SolrMultiCore();
- }
- return instance;
- }
-}
diff --git a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
index 75fb924ac93..74fc7ba0398 100644
--- a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -74,7 +74,7 @@ public class SolrDispatchFilter implements Filter
this.multicore = initMultiCore(config);
if(multicore != null && multicore.isEnabled() ) {
- abortOnConfigurationError = false;
+ abortOnConfigurationError = false;
singlecore = null;
// if any core aborts on startup, then abort
for( SolrCore c : multicore.getCores() ) {
@@ -132,24 +132,18 @@ public class SolrDispatchFilter implements Filter
}
/**
- * Initializes the multicore instance.
+ * Initialize the multicore instance.
* @param config the filter configuration
* @return the multicore instance or null
* @throws java.lang.Exception
*/
protected MultiCore initMultiCore(FilterConfig config) throws Exception {
- @SuppressWarnings("deprecation") // since SolrDispatchFilter can be derived & initMultiCore can be overriden
- MultiCore mcore = org.apache.solr.core.SolrMultiCore.getInstance();
- if (mcore.isEnabled()) {
- log.info("Using existing multicore configuration");
- } else {
- // multicore load
- String instanceDir = SolrResourceLoader.locateInstanceDir();
- File fconf = new File(instanceDir, "multicore.xml");
- log.info("looking for multicore.xml: " + fconf.getAbsolutePath());
- if (fconf.exists()) {
- mcore.load(instanceDir, fconf);
- }
+ MultiCore mcore = new MultiCore();
+ String instanceDir = SolrResourceLoader.locateInstanceDir();
+ File fconf = new File(instanceDir, "multicore.xml");
+ log.info("looking for multicore.xml: " + fconf.getAbsolutePath());
+ if (fconf.exists()) {
+ mcore.load(instanceDir, fconf);
}
return mcore;
}
@@ -302,6 +296,7 @@ public class SolrDispatchFilter implements Filter
// a servlet/jsp can retrieve it
else {
req.setAttribute("org.apache.solr.SolrCore", core);
+ req.setAttribute("org.apache.solr.MultiCore", multicore);
// Modify the request so each core gets its own /admin
if( singlecore == null && path.startsWith( "/admin" ) ) {
req.getRequestDispatcher( pathPrefix == null ? path : pathPrefix + path ).forward( request, response );
diff --git a/src/webapp/web/admin/index.jsp b/src/webapp/web/admin/index.jsp
index 21a8f3c90fe..8b88482aa8a 100644
--- a/src/webapp/web/admin/index.jsp
+++ b/src/webapp/web/admin/index.jsp
@@ -48,7 +48,8 @@
</tr>
<%-- List the cores (that arent this one) so we can switch --%>
-<% java.util.Collection<SolrCore> cores = org.apache.solr.core.SolrMultiCore.getInstance().getCores();
+<% org.apache.solr.core.MultiCore multicore = (org.apache.solr.core.MultiCore)request.getAttribute("org.apache.solr.MultiCore");
+ java.util.Collection<SolrCore> cores = multicore.getCores();
if (cores.size() > 1) {%><tr><td><strong>Cores:</strong><br></td><td><%
java.util.Iterator<SolrCore> icore = cores.iterator();
while (icore.hasNext()) {
diff --git a/src/webapp/web/index.jsp b/src/webapp/web/index.jsp
index 4848dc1e196..f61fe9561c4 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.SolrMultiCore.getInstance();
+ org.apache.solr.core.MultiCore multicore = (org.apache.solr.core.MultiCore)request.getAttribute("org.apache.solr.core.MultiCore");
if( multicore.isEnabled() ) {
for( org.apache.solr.core.SolrCore core : multicore.getCores() ) {%>
<a href="<%= core.getName() %>/admin/">Admin <%= core.getName() %> </a><br/>