SOLR-1427: redo of Grant's previous commit that yonik rolled back - but this time with the registration postponed until the latch is released

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@817499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2009-09-22 04:28:30 +00:00
parent 3ccd7bb75c
commit ab13635017
3 changed files with 53 additions and 1 deletions

View File

@ -591,6 +591,14 @@ public final class SolrCore implements SolrInfoMBean {
}
infoRegistry.put("core", this);
// register any SolrInfoMBeans SolrResourceLoader initialized
//
// this must happen after the latch is released, because a JMX server impl may
// choose to block on registering until properties can be fetched from an MBean,
// and a SolrCoreAware MBean may have properties that depend on getting a Searcher
// from the core.
resourceLoader.inform(infoRegistry);
}
private SolrHighlighter initHighLighter() {
@ -829,7 +837,11 @@ public final class SolrCore implements SolrInfoMBean {
}
private <T> void addIfNotPresent(Map<String ,T> registry, String name, Class<? extends T> c){
if(!registry.containsKey(name)){
registry.put(name, (T) resourceLoader.newInstance(c.getName()));
T searchComp = (T) resourceLoader.newInstance(c.getName());
registry.put(name, searchComp);
if (searchComp instanceof SolrInfoMBean){
infoRegistry.put(((SolrInfoMBean)searchComp).getName(), (SolrInfoMBean)searchComp);
}
}
}

View File

@ -68,6 +68,7 @@ public class SolrResourceLoader implements ResourceLoader
private String dataDir;
private final List<SolrCoreAware> waitingForCore = new ArrayList<SolrCoreAware>();
private final List<SolrInfoMBean> infoMBeans = new ArrayList<SolrInfoMBean>();
private final List<ResourceLoaderAware> waitingForResources = new ArrayList<ResourceLoaderAware>();
private static final Charset UTF_8 = Charset.forName("UTF-8");
@ -345,6 +346,10 @@ public class SolrResourceLoader implements ResourceLoader
assertAwareCompatibility( ResourceLoaderAware.class, obj );
waitingForResources.add( (ResourceLoaderAware)obj );
}
if (obj instanceof SolrInfoMBean){
//TODO: Assert here?
infoMBeans.add((SolrInfoMBean) obj);
}
return obj;
}
@ -401,6 +406,10 @@ public class SolrResourceLoader implements ResourceLoader
assertAwareCompatibility( ResourceLoaderAware.class, obj );
waitingForResources.add( (ResourceLoaderAware)obj );
}
if (obj instanceof SolrInfoMBean){
//TODO: Assert here?
infoMBeans.add((SolrInfoMBean) obj);
}
return obj;
}
@ -427,6 +436,16 @@ public class SolrResourceLoader implements ResourceLoader
}
waitingForResources.clear();
}
/**
* Register any {@link org.apache.solr.core.SolrInfoMBean}s
* @param infoRegistry The Info Registry
*/
public void inform(Map<String, SolrInfoMBean> infoRegistry) {
for (SolrInfoMBean bean : infoMBeans) {
infoRegistry.put(bean.getName(), bean);
}
}
/**
* Determines the solrhome from the environment.
* Tries JNDI (java:comp/env/solr/home) then system property (solr.solr.home);
@ -535,4 +554,5 @@ public class SolrResourceLoader implements ResourceLoader
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, builder.toString() );
}
}

View File

@ -18,6 +18,8 @@
package org.apache.solr.core;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.handler.component.SpellCheckComponent;
import org.apache.solr.handler.component.QueryComponent;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.SolrRequestHandler;
@ -164,6 +166,24 @@ public class SolrCoreTest extends AbstractSolrTestCase {
service.shutdown();
assertTrue("Running for too long...", service.awaitTermination(60, TimeUnit.SECONDS));
}
public void testInfoRegistry() throws Exception {
//TEst that SolrInfoMBeans are registered, including SearchComponents
SolrCore core = h.getCore();
Map<String, SolrInfoMBean> infoRegistry = core.getInfoRegistry();
assertTrue("infoRegistry Size: " + infoRegistry.size() + " is not greater than: " + 0, infoRegistry.size() > 0);
//try out some that we know are in the config
SolrInfoMBean bean = infoRegistry.get(SpellCheckComponent.class.getName());
assertNotNull("bean not registered", bean);
//try a default one
bean = infoRegistry.get(QueryComponent.class.getName());
assertNotNull("bean not registered", bean);
//try a Req Handler, which are stored by name, not clas
bean = infoRegistry.get("standard");
assertNotNull("bean not registered", bean);
}
}