manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1551664 - in /manifoldcf/branches/CONNECTORS-829/framework/core/src: main/java/org/apache/manifoldcf/core/interfaces/ main/java/org/apache/manifoldcf/core/throttler/ test/java/org/apache/manifoldcf/core/throttler/
Date Tue, 17 Dec 2013 19:37:28 GMT
Author: kwright
Date: Tue Dec 17 19:37:27 2013
New Revision: 1551664

URL: http://svn.apache.org/r1551664
Log:
Separate out the fetch throttler creation from the wait

Modified:
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IFetchThrottler.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IFetchThrottler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IFetchThrottler.java?rev=1551664&r1=1551663&r2=1551664&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IFetchThrottler.java
(original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IFetchThrottler.java
Tue Dec 17 19:37:27 2013
@@ -30,12 +30,17 @@ public interface IFetchThrottler
 
   /** Get permission to fetch a document.  This grants permission to start
   * fetching a single document, within the connection that has already been
-  * granted permission that created this object.  When done (or aborting), call
-  * IStreamThrottler.closeStream() to note the completion of the document
-  * fetch activity.
-  *@return the stream throttler to use to throttle the actual data access, or null if the
system is being shut down.
+  * granted permission that created this object.
+  *@return false if the throttler is being shut down.
   */
-  public IStreamThrottler obtainFetchDocumentPermission()
+  public boolean obtainFetchDocumentPermission()
     throws InterruptedException;
   
+  /** Open a fetch stream.  When done (or aborting), call
+  * IStreamThrottler.closeStream() to note the completion of the document
+  * fetch activity.
+  *@return the stream throttler to use to throttle the actual data access.
+  */
+  public IStreamThrottler createFetchStream();
+
 }

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java?rev=1551664&r1=1551663&r2=1551664&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
(original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
Tue Dec 17 19:37:27 2013
@@ -613,13 +613,11 @@ public class Throttler
     
     /** Get permission to fetch a document.  This grants permission to start
     * fetching a single document, within the connection that has already been
-    * granted permission that created this object.  When done (or aborting), call
-    * releaseFetchDocumentPermission() to note the completion of the document
-    * fetch activity.
-    *@param currentTime is the current time, in ms. since epoch.
-    *@return the stream throttler to use to throttle the actual data access, or null if the
system is being shut down.
+    * granted permission that created this object.
+    *@param binNames are the names of the bins.
+    *@return false if being shut down
     */
-    public IStreamThrottler obtainFetchDocumentPermission(String[] binNames)
+    public boolean obtainFetchDocumentPermission(String[] binNames)
       throws InterruptedException
     {
       // First, make sure all the bins exist, and reserve a slot in each
@@ -647,7 +645,7 @@ public class Throttler
             if (bin != null)
               bin.clearReservation();
           }
-          return null;
+          return false;
         }
         i++;
       }
@@ -679,12 +677,16 @@ public class Throttler
                 bin.clearReservation();
               i++;
             }
-            return null;
+            return false;
           }
         }
         i++;
       }
-      
+      return true;
+    }
+    
+    public IStreamThrottler createFetchStream(String[] binNames)
+    {
       // Do a "begin fetch" for all throttle bins
       synchronized (throttleBins)
       {
@@ -995,18 +997,27 @@ public class Throttler
     
     /** Get permission to fetch a document.  This grants permission to start
     * fetching a single document, within the connection that has already been
-    * granted permission that created this object.  When done (or aborting), call
-    * releaseFetchDocumentPermission() to note the completion of the document
-    * fetch activity.
-    *@return the stream throttler to use to throttle the actual data access, or null if the
system is being shut down.
+    * granted permission that created this object.
+    *@return false if the throttler is being shut down.
     */
     @Override
-    public IStreamThrottler obtainFetchDocumentPermission()
+    public boolean obtainFetchDocumentPermission()
       throws InterruptedException
     {
       return parent.obtainFetchDocumentPermission(binNames);
     }
     
+    /** Open a fetch stream.  When done (or aborting), call
+    * IStreamThrottler.closeStream() to note the completion of the document
+    * fetch activity.
+    *@return the stream throttler to use to throttle the actual data access.
+    */
+    @Override
+    public IStreamThrottler createFetchStream()
+    {
+      return parent.createFetchStream(binNames);
+    }
+
   }
   
   /** Stream throttler implementation class.

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java?rev=1551664&r1=1551663&r2=1551664&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java
(original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/test/java/org/apache/manifoldcf/core/throttler/TestThrottler.java
Tue Dec 17 19:37:27 2013
@@ -151,7 +151,7 @@ public class TestThrottler extends org.a
           // First grab a connection.
           int rval = connectionThrottler.waitConnectionAvailable();
           if (rval == IConnectionThrottler.CONNECTION_FROM_NOWHERE)
-            return;
+            throw new Exception("Unexpected return value from waitConnectionAvailable()");
           IFetchThrottler fetchThrottler;
           if (rval == IConnectionThrottler.CONNECTION_FROM_CREATION)
           {
@@ -168,30 +168,36 @@ public class TestThrottler extends org.a
           for (int l = 0; l < numberFetchesPerCycle; l++)
           {
             // Perform a fake fetch
-            IStreamThrottler streamThrottler = fetchThrottler.obtainFetchDocumentPermission();
-            if (streamThrottler == null)
-              return;
+            if (fetchThrottler.obtainFetchDocumentPermission() == false)
+              throw new Exception("Unexpected return value for obtainFetchDocumentPermission()");
             eventLog.addLogEntry(new FetchStartEvent());
-            // Do one read
-            if (streamThrottler.obtainReadPermission(1000) == false)
-              return;
-            eventLog.addLogEntry(new ReadStartEvent(1000));
-            streamThrottler.releaseReadPermission(1000, 1000);
-            eventLog.addLogEntry(new ReadDoneEvent(1000));
-            // Do another read
-            if (streamThrottler.obtainReadPermission(1000) == false)
-              return;
-            eventLog.addLogEntry(new ReadStartEvent(1000));
-            streamThrottler.releaseReadPermission(1000, 1000);
-            eventLog.addLogEntry(new ReadDoneEvent(1000));
-            // Do a third read
-            if (streamThrottler.obtainReadPermission(1000) == false)
-              return;
-            eventLog.addLogEntry(new ReadStartEvent(1000));
-            streamThrottler.releaseReadPermission(1000, 100);
-            eventLog.addLogEntry(new ReadDoneEvent(100));
-            // Close the stream
-            streamThrottler.closeStream();
+            IStreamThrottler streamThrottler = fetchThrottler.createFetchStream();
+            try
+            {
+              // Do one read
+              if (streamThrottler.obtainReadPermission(1000) == false)
+                throw new Exception("False from obtainReadPermission!");
+              eventLog.addLogEntry(new ReadStartEvent(1000));
+              streamThrottler.releaseReadPermission(1000, 1000);
+              eventLog.addLogEntry(new ReadDoneEvent(1000));
+              // Do another read
+              if (streamThrottler.obtainReadPermission(1000) == false)
+                throw new Exception("False from obtainReadPermission!");
+              eventLog.addLogEntry(new ReadStartEvent(1000));
+              streamThrottler.releaseReadPermission(1000, 1000);
+              eventLog.addLogEntry(new ReadDoneEvent(1000));
+              // Do a third read
+              if (streamThrottler.obtainReadPermission(1000) == false)
+                throw new Exception("False from obtainReadPermission!");
+              eventLog.addLogEntry(new ReadStartEvent(1000));
+              streamThrottler.releaseReadPermission(1000, 100);
+              eventLog.addLogEntry(new ReadDoneEvent(100));
+            }
+            finally
+            {
+              // Close the stream
+              streamThrottler.closeStream();
+            }
             eventLog.addLogEntry(new FetchDoneEvent());
           }
           



Mime
View raw message