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

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@640843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2008-03-25 15:01:23 +00:00
parent f0f2b88680
commit 5e3d3a2df0
6 changed files with 28 additions and 65 deletions

View File

@ -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/"; }

View File

@ -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);
}
//-------------------------------------------------------------------

View File

@ -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;
}
}

View File

@ -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 );

View File

@ -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()) {

View File

@ -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/>