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 2013/12/28 15:19:52 UTC

svn commit: r1553831 - in /manifoldcf/trunk/framework/core/src: main/java/org/apache/manifoldcf/core/connectorpool/ main/java/org/apache/manifoldcf/core/database/ test/java/org/apache/manifoldcf/core/throttler/

Author: kwright
Date: Sat Dec 28 14:19:52 2013
New Revision: 1553831

URL: http://svn.apache.org/r1553831
Log:
Various minor fixes, including exception handling when getting connections.

Modified:
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
    manifoldcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java?rev=1553831&r1=1553830&r2=1553831&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java Sat Dec 28 14:19:52 2013
@@ -301,7 +301,21 @@ public abstract class ConnectorPool<T ex
       p = poolHash.get(connectionName);
     }
 
-    p.releaseConnector(threadContext, connector);
+    if (p != null)
+      p.releaseConnector(threadContext, connector);
+    else
+    {
+      // Destroy the connector instance, since the pool is gone and that means we're shutting down
+      connector.setThreadContext(threadContext);
+      try
+      {
+        connector.disconnect();
+      }
+      finally
+      {
+        connector.clearThreadContext();
+      }
+    }
   }
 
   /** Idle notification for inactive output connector handles.

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java?rev=1553831&r1=1553830&r2=1553831&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java Sat Dec 28 14:19:52 2013
@@ -64,14 +64,7 @@ public class ConnectionFactory
     {
       // Hope for a connection now
       WrappedConnection rval;
-      ConnectionPool cp = null;
-      try
-      {
-        cp = cpm.getPool(database);
-      }
-      catch (Exception e)
-      {
-      }
+      ConnectionPool cp = cpm.getPool(database);
       if (cp == null)
       {
         cpm.addAlias(database, jdbcDriver, jdbcUrl,
@@ -81,9 +74,25 @@ public class ConnectionFactory
       }
       return getConnectionWithRetries(cp);
     }
-    catch (Exception e)
+    catch (InterruptedException e)
     {
-      throw new ManifoldCFException("Error getting connection: "+e.getMessage(),e,ManifoldCFException.DATABASE_ERROR);
+      throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
+    }
+    catch (SQLException e)
+    {
+      throw new ManifoldCFException("Error getting connection: "+e.getMessage(),e,ManifoldCFException.DATABASE_CONNECTION_ERROR);
+    }
+    catch (ClassNotFoundException e)
+    {
+      throw new ManifoldCFException("Fatal error getting connection: "+e.getMessage(),e,ManifoldCFException.SETUP_ERROR);
+    }
+    catch (InstantiationException e)
+    {
+      throw new ManifoldCFException("Fatal error getting connection: "+e.getMessage(),e,ManifoldCFException.SETUP_ERROR);
+    }
+    catch (IllegalAccessException e)
+    {
+      throw new ManifoldCFException("Fatal error getting connection: "+e.getMessage(),e,ManifoldCFException.SETUP_ERROR);
     }
   }
 
@@ -100,7 +109,7 @@ public class ConnectionFactory
   }
 
   protected static WrappedConnection getConnectionWithRetries(ConnectionPool cp)
-    throws SQLException, ManifoldCFException
+    throws SQLException, InterruptedException
   {
     // If we have a problem, we will wait a grand total of 30 seconds
     int retryCount = 3;
@@ -117,19 +126,8 @@ public class ConnectionFactory
         // Eat the exception and try again
         retryCount--;
       }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
-      }
-      try
-      {
-        // Ten seconds is a long time
-        ManifoldCF.sleep(10000L);
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
-      }
+      // Ten seconds is a long time
+      ManifoldCF.sleep(10000L);
     }
 
   }

Modified: manifoldcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java?rev=1553831&r1=1553830&r2=1553831&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java (original)
+++ manifoldcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java Sat Dec 28 14:19:52 2013
@@ -267,9 +267,9 @@ public class TestThrottler extends org.a
     public double getMinimumMillisecondsPerByte(String binName)
     {
       if (binName.equals("B"))
-        return 1.0;
+        return 0.5;
       if (binName.equals("C"))
-        return 1.5;
+        return 0.75;
       return 0.0;
     }
 
@@ -471,7 +471,7 @@ public class TestThrottler extends org.a
       else
       {
         // Calculate running minimum amount of time it should have taken for the bytes given
-        long minTime = (long)(((double)state.byteTotal) * 1.5 + 0.5);
+        long minTime = (long)(((double)state.byteTotal) * 0.75 + 0.5);
         if (timestamp - state.firstByteReadTime < minTime)
           throw new Exception("Took too short a time to read "+state.byteTotal+" bytes: "+(timestamp - state.firstByteReadTime));
       }