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/04/15 10:41:06 UTC

svn commit: r1092632 - in /incubator/lcf/branches/CONNECTORS-32/framework: agents/src/main/java/org/apache/manifoldcf/agents/interfaces/ pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/ pull-agent/src/main/java/org/apache/manifold...

Author: kwright
Date: Fri Apr 15 08:41:06 2011
New Revision: 1092632

URL: http://svn.apache.org/viewvc?rev=1092632&view=rev
Log:
Pull up another change for CONNECTORS-179.

Modified:
    incubator/lcf/branches/CONNECTORS-32/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java
    incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java
    incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java

Modified: incubator/lcf/branches/CONNECTORS-32/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java?rev=1092632&r1=1092631&r2=1092632&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java (original)
+++ incubator/lcf/branches/CONNECTORS-32/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java Fri Apr 15 08:41:06 2011
@@ -539,7 +539,6 @@ public class OutputConnectorFactory
         }
       }
 
-      IOutputConnector rc;
       if (stack.size() == 0)
       {
         String className = key.getClassName();
@@ -559,8 +558,9 @@ public class OutputConnectorFactory
           Object o = c.newInstance(arguments);
           if (!(o instanceof IOutputConnector))
             throw new ManifoldCFException("Class '"+className+"' does not implement IOutputConnector.");
-          rc = (IOutputConnector)o;
-          rc.connect(configParams);
+          IOutputConnector newrc = (IOutputConnector)o;
+          newrc.connect(configParams);
+          stack.add(newrc);
         }
         catch (InvocationTargetException e)
         {
@@ -612,12 +612,13 @@ public class OutputConnectorFactory
             e);
         }
       }
-      else
-        rc = (IOutputConnector)stack.remove(stack.size()-1);
-
-      numFree--;
-
+      
+      // Since thread context set can fail, do that before we remove it from the pool.
+      IOutputConnector rc = (IOutputConnector)stack.get(stack.size()-1);
       rc.setThreadContext(threadContext);
+      stack.remove(stack.size()-1);
+      numFree--;
+      
       return rc;
     }
 
@@ -646,11 +647,17 @@ public class OutputConnectorFactory
       int i = 0;
       while (i < stack.size())
       {
-        IOutputConnector rc = (IOutputConnector)stack.get(i++);
+        IConnector rc = (IConnector)stack.get(i++);
         // Notify
         rc.setThreadContext(threadContext);
-        rc.poll();
-        rc.clearThreadContext();
+        try
+        {
+          rc.poll();
+        }
+        finally
+        {
+          rc.clearThreadContext();
+        }
       }
     }
 
@@ -661,11 +668,18 @@ public class OutputConnectorFactory
     {
       while (stack.size() > 0)
       {
-        IOutputConnector rc = (IOutputConnector)stack.remove(stack.size()-1);
         // Disconnect
+        IConnector rc = (IConnector)stack.get(stack.size()-1);
         rc.setThreadContext(threadContext);
-        rc.disconnect();
-        rc.clearThreadContext();
+        try
+        {
+          rc.disconnect();
+          stack.remove(stack.size()-1);
+        }
+        finally
+        {
+          rc.clearThreadContext();
+        }
       }
     }
 

Modified: incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java?rev=1092632&r1=1092631&r2=1092632&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java (original)
+++ incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java Fri Apr 15 08:41:06 2011
@@ -439,7 +439,6 @@ public class AuthorityConnectorFactory
         }
       }
 
-      IAuthorityConnector rc;
       if (stack.size() == 0)
       {
         String className = key.getClassName();
@@ -459,10 +458,9 @@ public class AuthorityConnectorFactory
           Object o = c.newInstance(arguments);
           if (!(o instanceof IAuthorityConnector))
             throw new ManifoldCFException("Class '"+className+"' does not implement IAuthorityConnector.");
-          // System.out.println("Authority connector instantiated");
-          rc = (IAuthorityConnector)o;
-          rc.connect(configParams);
-          // System.out.println("Connect has been called for authority connector");
+          IAuthorityConnector newrc = (IAuthorityConnector)o;
+          newrc.connect(configParams);
+	  stack.add(newrc);
         }
         catch (InvocationTargetException e)
         {
@@ -512,15 +510,13 @@ public class AuthorityConnectorFactory
             e);
         }
       }
-      else
-      {
-        // System.out.println("Getting existing authority connector off the stack");
-        rc = (IAuthorityConnector)stack.remove(stack.size()-1);
-      }
-
+      
+      // Since thread context set can fail, do that before we remove it from the pool.
+      IAuthorityConnector rc = (IAuthorityConnector)stack.get(stack.size()-1);
+      rc.setThreadContext(threadContext);
+      stack.remove(stack.size()-1);
       numFree--;
 
-      rc.setThreadContext(threadContext);
       return rc;
     }
 
@@ -549,11 +545,17 @@ public class AuthorityConnectorFactory
       int i = 0;
       while (i < stack.size())
       {
-        IAuthorityConnector rc = (IAuthorityConnector)stack.get(i++);
+        IConnector rc = (IConnector)stack.get(i++);
         // Notify
         rc.setThreadContext(threadContext);
-        rc.poll();
-        rc.clearThreadContext();
+        try
+        {
+          rc.poll();
+        }
+        finally
+        {
+          rc.clearThreadContext();
+        }
       }
     }
 
@@ -564,11 +566,18 @@ public class AuthorityConnectorFactory
     {
       while (stack.size() > 0)
       {
-        IAuthorityConnector rc = (IAuthorityConnector)stack.remove(stack.size()-1);
         // Disconnect
+        IConnector rc = (IConnector)stack.get(stack.size()-1);
         rc.setThreadContext(threadContext);
-        rc.disconnect();
-        rc.clearThreadContext();
+        try
+        {
+          rc.disconnect();
+          stack.remove(stack.size()-1);
+        }
+        finally
+        {
+          rc.clearThreadContext();
+        }
       }
     }
 

Modified: incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java?rev=1092632&r1=1092631&r2=1092632&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java (original)
+++ incubator/lcf/branches/CONNECTORS-32/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java Fri Apr 15 08:41:06 2011
@@ -592,7 +592,6 @@ public class RepositoryConnectorFactory
         }
       }
 
-      IRepositoryConnector rc;
       if (stack.size() == 0)
       {
         String className = key.getClassName();
@@ -612,8 +611,9 @@ public class RepositoryConnectorFactory
           Object o = c.newInstance(arguments);
           if (!(o instanceof IRepositoryConnector))
             throw new ManifoldCFException("Class '"+className+"' does not implement IRepositoryConnector.");
-          rc = (IRepositoryConnector)o;
-          rc.connect(configParams);
+          IRepositoryConnector newrc = (IRepositoryConnector)o;
+          newrc.connect(configParams);
+          stack.add(newrc);
         }
         catch (InvocationTargetException e)
         {
@@ -665,12 +665,13 @@ public class RepositoryConnectorFactory
             e);
         }
       }
-      else
-        rc = (IRepositoryConnector)stack.remove(stack.size()-1);
 
+      // Since thread context set can fail, do that before we remove it from the pool.
+      IRepositoryConnector rc = (IRepositoryConnector)stack.get(stack.size()-1);
+      rc.setThreadContext(threadContext);
+      stack.remove(stack.size()-1);
       numFree--;
 
-      rc.setThreadContext(threadContext);
       return rc;
     }
 
@@ -699,11 +700,17 @@ public class RepositoryConnectorFactory
       int i = 0;
       while (i < stack.size())
       {
-        IRepositoryConnector rc = (IRepositoryConnector)stack.get(i++);
+        IConnector rc = (IConnector)stack.get(i++);
         // Notify
         rc.setThreadContext(threadContext);
-        rc.poll();
-        rc.clearThreadContext();
+        try
+        {
+          rc.poll();
+        }
+        finally
+        {
+          rc.clearThreadContext();
+        }
       }
     }
 
@@ -714,11 +721,18 @@ public class RepositoryConnectorFactory
     {
       while (stack.size() > 0)
       {
-        IRepositoryConnector rc = (IRepositoryConnector)stack.remove(stack.size()-1);
         // Disconnect
+        IConnector rc = (IConnector)stack.get(stack.size()-1);
         rc.setThreadContext(threadContext);
-        rc.disconnect();
-        rc.clearThreadContext();
+        try
+        {
+          rc.disconnect();
+          stack.remove(stack.size()-1);
+        }
+        finally
+        {
+          rc.clearThreadContext();
+        }
       }
     }