Author: rwesten
Date: Tue Mar 6 10:31:01 2012
New Revision: 1297412
URL: http://svn.apache.org/viewvc?rev=1297412&view=rev
Log:
Fixes STANBOL-519: The getServer() method now checks if the EmbeddedSolrServer
returned since the last call has changed. If this is the case the
SolrFieldMapper is set to null forcing the reinitialisation based on the new
SolrIndex
Modified:
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
Modified:
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java?rev=1297412&r1=1297411&r2=1297412&view=diff
==============================================================================
---
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
(original)
+++
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
Tue Mar 6 10:31:01 2012
@@ -32,6 +32,9 @@ import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Tracks the {@link CoreContainer} of the {@link SolrCore} referenced by the
@@ -42,6 +45,8 @@ import org.osgi.util.tracker.ServiceTrac
*
*/
public class RegisteredSolrServerTracker extends ServiceTracker {
+
+ private final Logger log =
LoggerFactory.getLogger(RegisteredSolrServerTracker.class);
/**
* In case <code>{@link IndexReference#isPath()} == true</code> than we
need
@@ -54,6 +59,9 @@ public class RegisteredSolrServerTracker
* needed to create {@link EmbeddedSolrServer} instances
*/
private final String coreName;
+
+ private final IndexReference reference;
+
/**
* Creates a new Tracker for the parsed {@link IndexReference}
* @param context the BundleContext used for tracking
@@ -64,14 +72,35 @@ public class RegisteredSolrServerTracker
* <code>null</code>
*/
public RegisteredSolrServerTracker(BundleContext context, IndexReference
reference) throws InvalidSyntaxException{
+ this(context,reference,null);
+ }
+ /**
+ * Creates a new Tracker for the parsed {@link IndexReference}
+ * @param context the BundleContext used for tracking
+ * @param reference the index reference
+ * @param customizer Customizer parsed to the parent instance. Note that
+ * the {@link ServiceTrackerCustomizer#addingService(ServiceReference)}
+ * method of this instance is expected to directly return the
+ * {@link SolrCore} or {@link CoreContainer} referenced by the parsed
+ * {@link IndexReference}. Service Objects parsed to the
+ * {@link ServiceTrackerCustomizer#modifiedService(ServiceReference,
Object)}
+ * and {@link ServiceTrackerCustomizer#remove(ServiceReference)} will be
+ * of type {@link EmbeddedSolrServer}.
+ * @throws InvalidSyntaxException if the {@link Filter} could not be
+ * created for the parsed {@link IndexReference}.
+ * @throws IllegalArgumentException if the parsed {@link IndexReference}
is
+ * <code>null</code>
+ */
+ public RegisteredSolrServerTracker(BundleContext context, IndexReference
reference,ServiceTrackerCustomizer customizer) throws InvalidSyntaxException {
super(context,
reference != null ?
reference.isPath() ?
context.createFilter(reference.getIndexFilter()) :
context.createFilter(reference.getIndexFilter()) :
- null ,null);
+ null,customizer);
if(reference == null){
throw new IllegalArgumentException("The parsed IndexReference MUST
NOT be NULL!");
}
+ this.reference = reference;
if(reference.isPath()){
trackingSolrCore = true;
coreName = null;
@@ -83,10 +112,17 @@ public class RegisteredSolrServerTracker
@Override
public SolrServer addingService(ServiceReference reference) {
+ log.info(" ... in addingService for {} (ref: {})",
+ this.reference,reference);
String coreName;
CoreContainer server;
+ Object service = super.addingService(reference);
+ if(service == null){
+ log.warn("addingService({}) returned null -> unable to create " +
+ "EmbeddedSolrServer for IndexReference
{}",reference,this.reference);
+ }
if(trackingSolrCore){
- SolrCore core = (SolrCore)context.getService(reference);
+ SolrCore core = (SolrCore)service;
coreName = core.getName();
CoreDescriptor descriptior = core.getCoreDescriptor();
if(descriptior == null){ //core not registered with a container!
@@ -96,12 +132,24 @@ public class RegisteredSolrServerTracker
server = descriptior.getCoreContainer();
}
} else {
- server = (CoreContainer)context.getService(reference);
+ server = (CoreContainer)service;
coreName = this.coreName;
}
return new EmbeddedSolrServer(server, coreName);
}
+ @Override
+ public void modifiedService(ServiceReference reference, Object service) {
+ log.info(" ... in modifiedService for {} (ref: {}, service {})",
+ new Object[]{this.reference,reference,service});
+ super.modifiedService(reference, service);
+ }
+ @Override
+ public void removedService(ServiceReference reference, Object service) {
+ log.info(" ... in removedService for {} (ref: {}, service {})",
+ new Object[]{this.reference,reference,service});
+ super.removedService(reference, service);
+ }
/**
* Overrides to provides a Array sorted by {@link
Constants#SERVICE_RANKING}
* @see ServiceTracker#getServiceReferences()
Modified:
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1297412&r1=1297411&r2=1297412&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
(original)
+++
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
Tue Mar 6 10:31:01 2012
@@ -76,8 +76,10 @@ import org.apache.stanbol.entityhub.yard
import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEnum;
import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.component.ComponentContext;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
@@ -485,10 +487,6 @@ public class SolrYard extends AbstractYa
if(_server == null && _registeredServerTracker == null){
initSolrServer();
}
- //for remove servers and when running outside OSGI
- if(_server != null){
- server = _server;
- }
//when an internally managed Solr server is used by this SolrYard
//we dynamically return the tracked version
if(_registeredServerTracker != null){
@@ -504,6 +502,14 @@ public class SolrYard extends AbstractYa
} catch (InterruptedException e) {}
}
}
+ if(server == null || !server.equals(this._server)){
+ //reset the fieldMapper so that it is reinitialised for the
new one
+ //STANBOL-519
+ _fieldMapper = null;
+ }
+ } else {
+ //for remove servers and when running outside OSGI
+ server = _server;
}
//the server is not available -> throw an exception!
if(server != null){
@@ -570,7 +576,7 @@ public class SolrYard extends AbstractYa
} else { //within OSGI dynamically track the service
try {
_registeredServerTracker = new
RegisteredSolrServerTracker(
- context.getBundleContext(), indexReference);
+ context.getBundleContext(), indexReference, null);
_registeredServerTracker.open(); //start tracking
} catch (InvalidSyntaxException e) {
throw new YardException("Unable to track configured
SolrServer'"+