if(managedServer == null || config == null){
//this means that either no ManagedSolrServer is present or this
//component was not yet activated ... will be called again
return;
}
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
if(config.isAllowInitialisation()){ //are we allowed to create the SolrServer
//get the name of the config to be used (default: default.solrindex.zip")
String configName = config.getIndexConfigurationName();
IndexMetadata metadata = managedServer.getIndexMetadata(solrIndexRef.getIndex());
if(metadata == null){ //create a new index
log.info(" ... creating Managed SolrIndex {} (configName: {}) on Server {}",
new Object[]{solrIndexRef.getIndex(),configName,managedServer.getServerName()});
try {
metadata = managedServer.createSolrIndex(solrIndexRef.getIndex(), configName, null);
} catch (IOException e) {
throw new IllegalStateException("Unable to create Managed SolrIndex "
+ solrIndexRef.getIndex()+" (configName: "+configName+") on Server "
+ managedServer.getServerName()+"!",e);
}
} else if(metadata.getState() != ManagedIndexState.ACTIVE){
log.info(" ... activating Managed SolrIndex {} on Server {} (current state: {})",
new Object[]{solrIndexRef.getIndex(),managedServer.getServerName(),metadata.getState()});
try {
managedServer.activateIndex(metadata.getIndexName());
} catch (IOException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex "
+ solrIndexRef.getIndex()+" (configName: "+configName+") on Server "
+ managedServer.getServerName()+"!",e);
} catch (SAXException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex "
+ solrIndexRef.getIndex()+" (configName: "+configName+") on Server "
+ managedServer.getServerName()+"!",e);
}
} //else already active nothing todo
solrIndexRef = metadata.getIndexReference();
} //else the SolrServer will be supplied (e.g. created by installing a full index)
try {
registeredServerTracker = new RegisteredSolrServerTracker(
context, solrIndexRef,null){
@Override
public void removedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(),config);
super.removedService(reference, service);
}
@Override
public void modifiedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(),config);
super.modifiedService(reference, service);
}
@Override
public SolrServer addingService(ServiceReference reference) {
SolrServer server = super.addingService(reference);
if(solrServer != null){
log.warn("Multiple SolrServer for IndexLocation {} available!",
config.getSolrServerLocation());
} else {
updateSolrYardRegistration(server,config);
}
return server;
}
};
log.info(" ... start tracking for SolrCore based on {}",solrIndexRef);
registeredServerTracker.open(); //start tracking
} catch (InvalidSyntaxException e) {
throw new IllegalStateException("Unable to track Managed SolrIndex "
+ solrIndexRef.getIndex() + "on Server "
+ managedServer.getServerName()+"!",e);
}
}