You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/10/06 02:36:42 UTC

svn commit: r1179482 - /incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java

Author: kwright
Date: Thu Oct  6 00:36:41 2011
New Revision: 1179482

URL: http://svn.apache.org/viewvc?rev=1179482&view=rev
Log:
Make a specialized thread for each operation.

Modified:
    incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java

Modified: incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java?rev=1179482&r1=1179481&r2=1179482&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java (original)
+++ incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java Thu Oct  6 00:36:41 2011
@@ -138,63 +138,8 @@ public class WikiConnector extends org.a
       hasBeenSetup = false;
       getSession();
 
-      // Now, set up trial data fetch
-      String checkURL = getCheckURL();
-      
-      HttpClient client = getInitializedClient();
-      try
-      {
-        // Set up fetch using our special stuff if it's https
-        GetMethod method = new GetMethod(checkURL);
-        try
-        {
-          method.getParams().setParameter("http.socket.timeout", new Integer(300000));
-          int statusCode = executeMethodViaThread(client,method);
-          switch (statusCode)
-          {
-          case HttpStatus.SC_OK:
-            return super.check();
-
-          default:
-            return "Fetch test returned an unexpected response code of "+Integer.toString(statusCode);
-          }
-        }
-        catch (InterruptedException e)
-        {
-          // Drop the connection on the floor
-          method = null;
-          throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-        }
-        catch (java.net.SocketTimeoutException e)
-        {
-          return "Fetch test timed out reading from the Wiki server: "+e.getMessage();
-        }
-        catch (java.net.SocketException e)
-        {
-          return "Fetch test received a socket error reading from Wiki server: "+e.getMessage();
-        }
-        catch (org.apache.commons.httpclient.ConnectTimeoutException e)
-        {
-          return "Fetch test connection timed out reading from Wiki server: "+e.getMessage();
-        }
-        catch (InterruptedIOException e)
-        {
-          throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-        }
-        catch (IOException e)
-        {
-          return "Fetch test had an IO failure: "+e.getMessage();
-        }
-        finally
-        {
-          if (method != null)
-            method.releaseConnection();
-        }
-      }
-      catch (IllegalStateException e)
-      {
-        return "Fetch test had a state exception talking to Livelink HTTP Server: "+e.getMessage();
-      }
+      executeCheckViaThread();
+      return super.check();
     }
     catch (ServiceInterruption e)
     {
@@ -630,6 +575,123 @@ public class WikiConnector extends org.a
     return client;
   }
 
+  /** Create and initialize an HttpMethodBase */
+  protected HttpMethodBase getInitializedMethod(String URL)
+  {
+    GetMethod method = new GetMethod(URL);
+    method.getParams().setParameter("http.socket.timeout", new Integer(300000));
+    return method;
+  }
+
+  /** Execute a check() operation via a thread */
+  protected void executeCheckViaThread()
+    throws ManifoldCFException, ServiceInterruption
+  {
+    HttpClient client = getInitializedClient();
+    HttpMethodBase executeMethod = getInitializedMethod(getCheckURL());
+    try
+    {
+      ExecuteCheckThread t = new ExecuteCheckThread(client,executeMethod);
+      try
+      {
+        t.start();
+        t.join();
+        Throwable thr = t.getException();
+        if (thr != null)
+        {
+          if (thr instanceof IOException)
+            throw (IOException)thr;
+          else if (thr instanceof RuntimeException)
+            throw (RuntimeException)thr;
+          else
+            throw (Error)thr;
+        }
+      }
+      catch (InterruptedException e)
+      {
+        t.interrupt();
+        // We need the caller to abandon any connections left around, so rethrow in a way that forces them to process the event properly.
+        throw e;
+      }
+    }
+    catch (InterruptedException e)
+    {
+      // Drop the connection on the floor
+      executeMethod = null;
+      throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
+    }
+    catch (java.net.SocketTimeoutException e)
+    {
+      long currentTime = System.currentTimeMillis();
+      throw new ServiceInterruption("Fetch test timed out reading from the Wiki server: "+e.getMessage(),e,currentTime+300000L,currentTime+12L * 60000L,-1,false);
+    }
+    catch (java.net.SocketException e)
+    {
+      long currentTime = System.currentTimeMillis();
+      throw new ServiceInterruption("Fetch test received a socket error reading from Wiki server: "+e.getMessage(),e,currentTime+300000L,currentTime+12L * 60000L,-1,false);
+    }
+    catch (org.apache.commons.httpclient.ConnectTimeoutException e)
+    {
+      long currentTime = System.currentTimeMillis();
+      throw new ServiceInterruption("Fetch test connection timed out reading from Wiki server: "+e.getMessage(),e,currentTime+300000L,currentTime+12L * 60000L,-1,false);
+    }
+    catch (InterruptedIOException e)
+    {
+      executeMethod = null;
+      throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
+    }
+    catch (IOException e)
+    {
+      throw new ManifoldCFException("Fetch test had an IO failure: "+e.getMessage(),e);
+    }
+    finally
+    {
+      if (executeMethod != null)
+        executeMethod.releaseConnection();
+    }
+  }
+  
+  /** Thread to execute a check */
+  protected static class ExecuteCheckThread extends Thread
+  {
+    protected HttpClient client;
+    protected HttpMethodBase executeMethod;
+    protected Throwable exception = null;
+    protected int rval = 0;
+
+    public ExecuteCheckThread(HttpClient client, HttpMethodBase executeMethod)
+    {
+      super();
+      setDaemon(true);
+      this.client = client;
+      this.executeMethod = executeMethod;
+    }
+
+    public void run()
+    {
+      try
+      {
+        // Call the execute method appropriately
+        int rval = client.executeMethod(executeMethod);
+        if (rval != 200)
+          throw new ManifoldCFException("Unexpected response code: "+rval);
+        // Read response and make sure it's valid
+        // MHL
+      }
+      catch (Throwable e)
+      {
+        this.exception = e;
+      }
+    }
+
+    public Throwable getException()
+    {
+      return exception;
+    }
+
+  }
+
+
   /** Execute an HttpClient method via thread, so we don't get stuck in socket wait */
   protected static int executeMethodViaThread(HttpClient client, HttpMethodBase executeMethod)
     throws InterruptedException, IOException