incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1226451 - in /incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf: ManifoldCFQParserPlugin.java ManifoldCFSearchComponent.java
Date Mon, 02 Jan 2012 16:06:34 GMT
Author: kwright
Date: Mon Jan  2 16:06:34 2012
New Revision: 1226451

URL: http://svn.apache.org/viewvc?rev=1226451&view=rev
Log:
Add CloseHook support.  This fixes the problem for the search component, but not for the query
parser plugin.  Part of CONNECTORS-333.

Modified:
    incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
    incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.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=1226451&r1=1226450&r2=1226451&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
Mon Jan  2 16:06:34 2012
@@ -35,6 +35,9 @@ import org.apache.solr.common.params.Sol
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.handler.component.ResponseBuilder;
 import org.apache.solr.handler.component.SearchComponent;
+import org.apache.solr.core.CloseHook;
+import org.apache.solr.util.plugin.SolrCoreAware;
+import org.apache.solr.core.SolrCore;
 import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.methods.*;
 import org.apache.commons.httpclient.params.*;
@@ -74,26 +77,12 @@ public class ManifoldCFQParserPlugin ext
   String fieldAllowShare = null;
   String fieldDenyShare = null;
   int socketTimeOut;
-  MultiThreadedHttpConnectionManager httpConnectionManager;
-  HttpClient client;
+  MultiThreadedHttpConnectionManager httpConnectionManager = null;
+  HttpClient client = null;
   
   public ManifoldCFQParserPlugin()
   {
     super();
-    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
-    params.setTcpNoDelay(true);
-    params.setStaleCheckingEnabled(false);
-    httpConnectionManager = new MultiThreadedHttpConnectionManager();
-    httpConnectionManager.setParams(params);
-    client = new HttpClient(httpConnectionManager);
-  }
-
-  @Override
-  protected void finalize()
-    throws Throwable
-  {
-    super.finalize();
-    httpConnectionManager.shutdown();
   }
 
   @Override
@@ -114,6 +103,15 @@ public class ManifoldCFQParserPlugin ext
     fieldDenyDocument = denyAttributePrefix+"document";
     fieldAllowShare = allowAttributePrefix+"share";
     fieldDenyShare = denyAttributePrefix+"share";
+
+    // Initialize the connection pool
+    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+    params.setTcpNoDelay(true);
+    params.setStaleCheckingEnabled(false);
+    httpConnectionManager = new MultiThreadedHttpConnectionManager();
+    httpConnectionManager.setParams(params);
+    // MHL to set the pool size
+    client = new HttpClient(httpConnectionManager);
   }
 
   @Override
@@ -122,6 +120,11 @@ public class ManifoldCFQParserPlugin ext
     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)
@@ -307,5 +310,32 @@ public class ManifoldCFQParserPlugin ext
       }
     }
   }
-  
+
+  /** CloseHook implementation.
+  */
+  protected class CloseHandler extends CloseHook
+  {
+    public CloseHandler()
+    {
+    }
+    
+    @Override
+    public void preClose(SolrCore core)
+    {
+    }
+    
+    @Override
+    public void postClose(SolrCore core)
+    {
+      // Close the connection pool
+      if (httpConnectionManager != null)
+      {
+        httpConnectionManager.shutdown();
+        httpConnectionManager = null;
+        client = null;
+      }
+    }
+    
+  }
+
 }
\ No newline at end of file

Modified: incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java
URL: http://svn.apache.org/viewvc/incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java?rev=1226451&r1=1226450&r2=1226451&view=diff
==============================================================================
--- incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java
(original)
+++ incubator/lcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java
Mon Jan  2 16:06:34 2012
@@ -26,6 +26,9 @@ import org.apache.solr.common.params.Sol
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.handler.component.ResponseBuilder;
 import org.apache.solr.handler.component.SearchComponent;
+import org.apache.solr.core.CloseHook;
+import org.apache.solr.util.plugin.SolrCoreAware;
+import org.apache.solr.core.SolrCore;
 import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.methods.*;
 import org.apache.commons.httpclient.params.*;
@@ -39,7 +42,7 @@ import java.net.*;
 * SearchComponent plugin for ManifoldCF-specific document-level access control.
 * Configuration is under the SolrACLSecurity name.
 */
-public class ManifoldCFSearchComponent extends SearchComponent
+public class ManifoldCFSearchComponent extends SearchComponent implements SolrCoreAware
 {
   /** The component name */
   static final public String COMPONENT_NAME = "mcf";
@@ -66,26 +69,12 @@ public class ManifoldCFSearchComponent e
   String fieldAllowShare = null;
   String fieldDenyShare = null;
   int socketTimeOut;
-  MultiThreadedHttpConnectionManager httpConnectionManager;
-  HttpClient client;
+  MultiThreadedHttpConnectionManager httpConnectionManager = null;
+  HttpClient client = null;
   
   public ManifoldCFSearchComponent()
   {
     super();
-    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
-    params.setTcpNoDelay(true);
-    params.setStaleCheckingEnabled(false);
-    httpConnectionManager = new MultiThreadedHttpConnectionManager();
-    httpConnectionManager.setParams(params);
-    client = new HttpClient(httpConnectionManager);
-  }
-
-  @Override
-  protected void finalize()
-    throws Throwable
-  {
-    super.finalize();
-    httpConnectionManager.shutdown();
   }
 
   @Override
@@ -107,6 +96,16 @@ public class ManifoldCFSearchComponent e
     fieldDenyDocument = denyAttributePrefix+"document";
     fieldAllowShare = allowAttributePrefix+"share";
     fieldDenyShare = denyAttributePrefix+"share";
+    
+    // Initialize the connection pool
+    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+    params.setTcpNoDelay(true);
+    params.setStaleCheckingEnabled(false);
+    httpConnectionManager = new MultiThreadedHttpConnectionManager();
+    httpConnectionManager.setParams(params);
+    // MHL to set the pool size
+    client = new HttpClient(httpConnectionManager);
+
   }
 
   @Override
@@ -263,7 +262,12 @@ public class ManifoldCFSearchComponent e
   {
     return "$URL$";
   }
-	
+
+  public void inform(SolrCore core)
+  {
+    core.addCloseHook(new CloseHandler());
+  }
+  
   // Protected methods
   
   /** Get access tokens given a username */
@@ -333,4 +337,31 @@ public class ManifoldCFSearchComponent e
     }
   }
   
+  /** CloseHook implementation.
+  */
+  protected class CloseHandler extends CloseHook
+  {
+    public CloseHandler()
+    {
+    }
+    
+    @Override
+    public void preClose(SolrCore core)
+    {
+    }
+    
+    @Override
+    public void postClose(SolrCore core)
+    {
+      // Close the connection pool
+      if (httpConnectionManager != null)
+      {
+        httpConnectionManager.shutdown();
+        httpConnectionManager = null;
+        client = null;
+      }
+    }
+    
+  }
+  
 }
\ No newline at end of file



Mime
View raw message