Skip to content

Apache Lucene open-source search software

SOLR-1532 -- Allow StreamingUpdateSolrServer to use a provided HttpClient

Shalin Shekhar Mangar0e8eb2a2d8b2
diff --git a/CHANGES.txt b/CHANGES.txt
index 46890c1b5dd..94d45959c8b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -67,6 +67,8 @@ New Features
* SOLR-1621: Allow current single core deployments to be specified by solr.xml (Mark Miller , noble)
+* SOLR-1532: Allow StreamingUpdateSolrServer to use a provided HttpClient (Gabriele Renzi via shalin)
+
Optimizations
----------------------
diff --git a/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java b/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
index a93a6194d82..a0185cb39f0 100644
--- a/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
+++ b/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
@@ -27,6 +27,7 @@ import java.util.concurrent.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
@@ -61,10 +62,26 @@ public class StreamingUpdateSolrServer extends CommonsHttpSolrServer
final Queue<Runner> runners;
volatile CountDownLatch lock = null; // used to block everything
final int threadCount;
-
- public StreamingUpdateSolrServer(String solrServerUrl, int queueSize, int threadCount ) throws MalformedURLException {
- super( solrServerUrl );
- queue = new LinkedBlockingQueue<UpdateRequest>( queueSize );
+
+ /**
+ * Uses an internal MultiThreadedHttpConnectionManager to manage http connections
+ *
+ * @param solrServerUrl The solr server url
+ * @param queueSize The buffer size before the documents are sent o the server
+ * @param threadCount The number of backgtound threads used to empty the queue
+ * @throws MalformedURLException
+ */
+ public StreamingUpdateSolrServer(String solrServerUrl, int queueSize, int threadCount) throws MalformedURLException {
+ this(solrServerUrl, null, queueSize, threadCount);
+ }
+
+ /**
+ * Uses the supplied HttpClient to send documents to the solr server, the HttpClient should be instantiated using a
+ * MultiThreadedHttpConnectionManager.
+ */
+ public StreamingUpdateSolrServer(String solrServerUrl, HttpClient client, int queueSize, int threadCount) throws MalformedURLException {
+ super(solrServerUrl, client);
+ queue = new LinkedBlockingQueue<UpdateRequest>(queueSize);
this.threadCount = threadCount;
runners = new LinkedList<Runner>();
}