You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/10/15 16:34:40 UTC
svn commit: r1398306 - in
/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr:
IndexReference.java RegisteredSolrServerTracker.java SolrServerAdapter.java
utils/StreamQueryRequest.java
Author: rwesten
Date: Mon Oct 15 14:34:40 2012
New Revision: 1398306
URL: http://svn.apache.org/viewvc?rev=1398306&view=rev
Log:
Patch for STANBOL-778: RegisteredSolrServerTracker now tracks (by default) all services; addingService method adapted to check if retrieved service can be cast to the BundleContexts classloaders types; Also added toString() method to IndexReference for logging reasons.
Modified:
stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/IndexReference.java
stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/SolrServerAdapter.java
stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/utils/StreamQueryRequest.java
Modified: stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/IndexReference.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/IndexReference.java?rev=1398306&r1=1398305&r2=1398306&view=diff
==============================================================================
--- stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/IndexReference.java (original)
+++ stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/IndexReference.java Mon Oct 15 14:34:40 2012
@@ -17,14 +17,12 @@
package org.apache.stanbol.commons.solr;
import java.io.File;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.osgi.framework.Constants;
@@ -199,4 +197,9 @@ public class IndexReference {
filterString.append(String.format(CONSTRAINT, SolrConstants.PROPERTY_SERVER_NAME,getServer()));
}
}
+
+ @Override
+ public String toString() {
+ return String.format("IndexReference[server:%s,index:%s]",getServer(),getIndex());
+ }
}
Modified: stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java?rev=1398306&r1=1398305&r2=1398306&view=diff
==============================================================================
--- stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java (original)
+++ stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java Mon Oct 15 14:34:40 2012
@@ -109,6 +109,10 @@ public class RegisteredSolrServerTracker
coreName = reference.getIndex();
}
}
+ @Override
+ public void open() {
+ super.open(true); //track all services by default
+ }
@Override
public SolrServer addingService(ServiceReference reference) {
@@ -122,7 +126,20 @@ public class RegisteredSolrServerTracker
"EmbeddedSolrServer for IndexReference {}",reference,this.reference);
}
if(trackingSolrCore){
- SolrCore core = (SolrCore)service;
+ SolrCore core;
+ //as we (might) track all services the Class of the returned service
+ //might not be the same as for this classloader
+ if(service instanceof SolrCore){
+ core = (SolrCore)service;
+ } else {
+ log.warn("SolrCore fitting to IndexReference {} is incompatible to the" +
+ "classloader of bundle [{}]{} - Service [{}] ignored!",
+ new Object[]{reference,context.getBundle().getBundleId(),
+ context.getBundle().getSymbolicName()},
+ reference.getProperty(Constants.SERVICE_ID));
+ context.ungetService(reference);
+ return null;
+ }
coreName = core.getName();
CoreDescriptor descriptior = core.getCoreDescriptor();
if(descriptior == null){ //core not registered with a container!
@@ -132,7 +149,17 @@ public class RegisteredSolrServerTracker
server = descriptior.getCoreContainer();
}
} else {
- server = (CoreContainer)service;
+ if(service instanceof CoreContainer){
+ server = (CoreContainer)service;
+ } else {
+ log.warn("Solr CoreContainer fitting to IndexReference {} is incompatible to the" +
+ "classloader of bundle [{}]{} - Service [{}] ignored!",
+ new Object[]{reference,context.getBundle().getBundleId(),
+ context.getBundle().getSymbolicName()},
+ reference.getProperty(Constants.SERVICE_ID));
+ context.ungetService(reference);
+ return null;
+ }
coreName = this.coreName;
}
return new EmbeddedSolrServer(server, coreName);
Modified: stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/SolrServerAdapter.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/SolrServerAdapter.java?rev=1398306&r1=1398305&r2=1398306&view=diff
==============================================================================
--- stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/SolrServerAdapter.java (original)
+++ stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/SolrServerAdapter.java Mon Oct 15 14:34:40 2012
@@ -18,12 +18,10 @@ package org.apache.stanbol.commons.solr;
import static org.apache.stanbol.commons.solr.SolrConstants.*;
import static org.osgi.framework.Constants.SERVICE_ID;
-import static org.osgi.framework.Constants.SERVICE_PID;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
@@ -33,13 +31,11 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
-import java.util.Map.Entry;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathFactory;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
-import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.core.CloseHook;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
@@ -299,7 +295,7 @@ public class SolrServerAdapter {
* (Rupert Westenthaler 20010209)
*/
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(SolrServerAdapter.class.getClassLoader());
+ Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
return classLoader;
}
/**
Modified: stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/utils/StreamQueryRequest.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/utils/StreamQueryRequest.java?rev=1398306&r1=1398305&r2=1398306&view=diff
==============================================================================
--- stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/utils/StreamQueryRequest.java (original)
+++ stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/utils/StreamQueryRequest.java Mon Oct 15 14:34:40 2012
@@ -16,7 +16,6 @@
*/
package org.apache.stanbol.commons.solr.utils;
-import java.io.File;
import java.util.Arrays;
import java.util.Collection;