manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1230079 - /incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
Date Wed, 11 Jan 2012 15:00:44 GMT
Author: kwright
Date: Wed Jan 11 15:00:43 2012
New Revision: 1230079

URL: http://svn.apache.org/viewvc?rev=1230079&view=rev
Log:
Fix for CONNECTORS-333.  Use the CloseHook API to free connections.  We still get a warning
message, but that's going to happen since the connection manager creates a static thread.

Modified:
    incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java

Modified: incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
URL: http://svn.apache.org/viewvc/incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java?rev=1230079&r1=1230078&r2=1230079&view=diff
==============================================================================
--- incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
(original)
+++ incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
Wed Jan 11 15:00:43 2012
@@ -77,6 +77,7 @@ public class ManifoldCFQParserPlugin ext
   String fieldAllowShare = null;
   String fieldDenyShare = null;
   int socketTimeOut;
+  Integer connectionManagerSynchronizer = new Integer(0);
   MultiThreadedHttpConnectionManager httpConnectionManager = null;
   HttpClient client = null;
   int poolSize;
@@ -106,29 +107,35 @@ public class ManifoldCFQParserPlugin ext
     fieldDenyShare = denyAttributePrefix+"share";
     Integer connectionPoolSize = (Integer)args.get("ConnectionPoolSize");
     poolSize = (connectionPoolSize==null)?50:connectionPoolSize.intValue();
-
-    // Initialize the connection pool
-    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
-    params.setTcpNoDelay(true);
-    params.setStaleCheckingEnabled(false);
-    params.setDefaultMaxConnectionsPerHost(poolSize);
-    params.setMaxTotalConnections(poolSize);
-    httpConnectionManager = new MultiThreadedHttpConnectionManager();
-    httpConnectionManager.setParams(params);
-    client = new HttpClient(httpConnectionManager);
+  }
+  
+  protected void initializeClient(SolrCore core)
+  {
+    synchronized (connectionManagerSynchronizer)
+    {
+      if (client == null)
+      {
+        // Initialize the connection pool
+        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+        params.setTcpNoDelay(true);
+        params.setStaleCheckingEnabled(false);
+        params.setDefaultMaxConnectionsPerHost(poolSize);
+        params.setMaxTotalConnections(poolSize);
+        httpConnectionManager = new MultiThreadedHttpConnectionManager();
+        httpConnectionManager.setParams(params);
+        client = new HttpClient(httpConnectionManager);
+        core.addCloseHook(new CloseHandler());
+      }
+    }
   }
 
   @Override
   public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest
req)
   {
+    initializeClient(req.getCore());
     return new ManifoldCFQueryParser(qstr,localParams,params,req);
   }
 
-  public void inform(SolrCore core)
-  {
-    core.addCloseHook(new CloseHandler());
-  }
-  
   protected class ManifoldCFQueryParser extends QParser
   {
     public ManifoldCFQueryParser(String qstr, SolrParams localParams, SolrParams params,
SolrQueryRequest req)
@@ -331,12 +338,15 @@ public class ManifoldCFQParserPlugin ext
     @Override
     public void postClose(SolrCore core)
     {
-      // Close the connection pool
-      if (httpConnectionManager != null)
+      synchronized (connectionManagerSynchronizer)
       {
-        httpConnectionManager.shutdown();
-        httpConnectionManager = null;
-        client = null;
+        // Close the connection pool
+        if (httpConnectionManager != null)
+        {
+          httpConnectionManager.shutdown();
+          httpConnectionManager = null;
+          client = null;
+        }
       }
     }
     



Mime
View raw message