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/16 16:09:21 UTC

svn commit: r1551225 - in /manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core: interfaces/ throttler/

Author: kwright
Date: Mon Dec 16 15:09:20 2013
New Revision: 1551225

URL: http://svn.apache.org/r1551225
Log:
First move towards making all bins be their own registered services.

Modified:
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IThrottleGroups.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/FetchBin.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleBin.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleGroups.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IThrottleGroups.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IThrottleGroups.java?rev=1551225&r1=1551224&r2=1551225&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IThrottleGroups.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IThrottleGroups.java Mon Dec 16 15:09:20 2013
@@ -59,7 +59,8 @@ public interface IThrottleGroups
   *@param binNames are the connection type bin names.
   *@return the connection throttling object, or null if the pool is being shut down.
   */
-  public IConnectionThrottler obtainConnectionThrottler(String throttleGroupType, String throttleGroup, String[] binNames);
+  public IConnectionThrottler obtainConnectionThrottler(String throttleGroupType, String throttleGroup, String[] binNames)
+    throws ManifoldCFException;
   
   /** Poll periodically, to update cluster-wide statistics and allocation.
   *@param throttleGroupType is the throttle group type to update.

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java?rev=1551225&r1=1551224&r2=1551225&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java Mon Dec 16 15:09:20 2013
@@ -56,7 +56,7 @@ public class ConnectionBin
   protected int inUseConnections = 0;
 
   /** Constructor. */
-  public ConnectionBin(String binName)
+  public ConnectionBin(IThreadContext threadContext, String binName)
   {
     this.binName = binName;
   }
@@ -207,7 +207,8 @@ public class ConnectionBin
 
   /** Shut down the bin, and release everything that is waiting on it.
   */
-  public synchronized void shutDown()
+  public synchronized void shutDown(IThreadContext threadContext)
+    throws ManifoldCFException
   {
     isAlive = false;
     notifyAll();

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/FetchBin.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/FetchBin.java?rev=1551225&r1=1551224&r2=1551225&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/FetchBin.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/FetchBin.java Mon Dec 16 15:09:20 2013
@@ -42,7 +42,7 @@ public class FetchBin
   protected boolean reserveNextFetch = false;
 
   /** Constructor. */
-  public FetchBin(String binName)
+  public FetchBin(IThreadContext threadContext, String binName)
   {
     this.binName = binName;
   }
@@ -134,7 +134,8 @@ public class FetchBin
   
   /** Shut the bin down, and wake up all threads waiting on it.
   */
-  public synchronized void shutDown()
+  public synchronized void shutDown(IThreadContext threadContext)
+    throws ManifoldCFException
   {
     isAlive = false;
     notifyAll();

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleBin.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleBin.java?rev=1551225&r1=1551224&r2=1551225&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleBin.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleBin.java Mon Dec 16 15:09:20 2013
@@ -87,7 +87,7 @@ public class ThrottleBin
   protected double minimumMillisecondsPerByte = Double.MAX_VALUE;
   
   /** Constructor. */
-  public ThrottleBin(String binName)
+  public ThrottleBin(IThreadContext threadContext, String binName)
   {
     this.binName = binName;
   }
@@ -254,7 +254,8 @@ public class ThrottleBin
 
   /** Shut down this bin.
   */
-  public synchronized void shutDown()
+  public synchronized void shutDown(IThreadContext threadContext)
+    throws ManifoldCFException
   {
     isAlive = false;
     notifyAll();

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleGroups.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleGroups.java?rev=1551225&r1=1551224&r2=1551225&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleGroups.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ThrottleGroups.java Mon Dec 16 15:09:20 2013
@@ -88,9 +88,10 @@ public class ThrottleGroups implements I
   */
   @Override
   public IConnectionThrottler obtainConnectionThrottler(String throttleGroupType, String throttleGroup, String[] binNames)
+    throws ManifoldCFException
   {
     java.util.Arrays.sort(binNames);
-    return throttler.obtainConnectionThrottler(throttleGroupType, throttleGroup, binNames);
+    return throttler.obtainConnectionThrottler(threadContext, throttleGroupType, throttleGroup, binNames);
   }
 
   /** Poll periodically, to update cluster-wide statistics and allocation.

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=1551225&r1=1551224&r2=1551225&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 Mon Dec 16 15:09:20 2013
@@ -126,14 +126,15 @@ public class Throttler
   *@param binNames are the connection type bin names.
   *@return the connection throttling object, or null if the pool is being shut down.
   */
-  public IConnectionThrottler obtainConnectionThrottler(String throttleGroupType, String throttleGroup, String[] binNames)
+  public IConnectionThrottler obtainConnectionThrottler(IThreadContext threadContext, String throttleGroupType, String throttleGroup, String[] binNames)
+    throws ManifoldCFException
   {
     // No waiting, so lock the entire tree.
     synchronized (throttleGroupsHash)
     {
       ThrottlingGroups tg = throttleGroupsHash.get(throttleGroupType);
       if (tg != null)
-        return tg.obtainConnectionThrottler(throttleGroup, binNames);
+        return tg.obtainConnectionThrottler(threadContext, throttleGroup, binNames);
       return null;
     }
   }
@@ -233,14 +234,15 @@ public class Throttler
     /** Obtain connection throttler.
     *@return the throttler, or null of the hierarchy has changed.
     */
-    public IConnectionThrottler obtainConnectionThrottler(String throttleGroup, String[] binNames)
+    public IConnectionThrottler obtainConnectionThrottler(IThreadContext threadContext, String throttleGroup, String[] binNames)
+      throws ManifoldCFException
     {
       synchronized (groups)
       {
         ThrottlingGroup g = groups.get(throttleGroup);
         if (g == null)
           return null;
-        return g.obtainConnectionThrottler(binNames);
+        return g.obtainConnectionThrottler(threadContext, binNames);
       }
     }
     
@@ -348,6 +350,55 @@ public class Throttler
       poll(threadContext);
     }
 
+    /** Create a bunch of bins, corresponding to the bin names specified.
+    * Note that this also registers them as services etc.
+    *@param binNames describes the set of bins to create.
+    */
+    public synchronized IConnectionThrottler obtainConnectionThrottler(IThreadContext threadContext, String[] binNames)
+      throws ManifoldCFException
+    {
+      synchronized (connectionBins)
+      {
+        for (String binName : binNames)
+        {
+          ConnectionBin bin = connectionBins.get(binName);
+          if (bin == null)
+          {
+            bin = new ConnectionBin(threadContext, binName);
+            connectionBins.put(binName, bin);
+          }
+        }
+      }
+      
+      synchronized (fetchBins)
+      {
+        for (String binName : binNames)
+        {
+          FetchBin bin = fetchBins.get(binName);
+          if (bin == null)
+          {
+            bin = new FetchBin(threadContext, binName);
+            fetchBins.put(binName, bin);
+          }
+        }
+      }
+      
+      synchronized (throttleBins)
+      {
+        for (String binName : binNames)
+        {
+          ThrottleBin bin = throttleBins.get(binName);
+          if (bin == null)
+          {
+            bin = new ThrottleBin(threadContext, binName);
+            throttleBins.put(binName, bin);
+          }
+        }
+      }
+      
+      return new ConnectionThrottler(this, binNames);
+    }
+    
     /** Update the throttle spec.
     *@param throttleSpec is the new throttle spec for this throttle group.
     */
@@ -357,11 +408,6 @@ public class Throttler
       this.throttleSpec = throttleSpec;
     }
     
-    /** Obtain a connection throttler */
-    public IConnectionThrottler obtainConnectionThrottler(String[] binNames)
-    {
-      return new ConnectionThrottler(this, binNames);
-    }
     
     // IConnectionThrottler support methods
     
@@ -398,37 +444,35 @@ public class Throttler
           synchronized (connectionBins)
           {
             bin = connectionBins.get(binName);
-            if (bin == null)
-            {
-              bin = new ConnectionBin(binName);
-              connectionBins.put(binName, bin);
-            }
           }
-          // Reserve a slot
-          int result = bin.waitConnectionAvailable(poolCount);
-          if (result == IConnectionThrottler.CONNECTION_FROM_NOWHERE ||
-            (currentRecommendation != IConnectionThrottler.CONNECTION_FROM_NOWHERE && currentRecommendation != result))
+          if (bin != null)
           {
-            // Release previous reservations, and either return, or retry
-            while (i > 0)
+            // Reserve a slot
+            int result = bin.waitConnectionAvailable(poolCount);
+            if (result == IConnectionThrottler.CONNECTION_FROM_NOWHERE ||
+              (currentRecommendation != IConnectionThrottler.CONNECTION_FROM_NOWHERE && currentRecommendation != result))
             {
-              i--;
-              binName = binNames[i];
-              synchronized (connectionBins)
+              // Release previous reservations, and either return, or retry
+              while (i > 0)
               {
-                bin = connectionBins.get(binName);
+                i--;
+                binName = binNames[i];
+                synchronized (connectionBins)
+                {
+                  bin = connectionBins.get(binName);
+                }
+                if (bin != null)
+                  bin.undoReservation(currentRecommendation, poolCount);
               }
-              if (bin != null)
-                bin.undoReservation(currentRecommendation, poolCount);
+              if (result == IConnectionThrottler.CONNECTION_FROM_NOWHERE)
+                return result;
+              // Break out of the outer loop so we can retry
+              retry = true;
+              break;
             }
-            if (result == IConnectionThrottler.CONNECTION_FROM_NOWHERE)
-              return result;
-            // Break out of the outer loop so we can retry
-            retry = true;
-            break;
+            if (currentRecommendation == IConnectionThrottler.CONNECTION_FROM_NOWHERE)
+              currentRecommendation = result;
           }
-          if (currentRecommendation == IConnectionThrottler.CONNECTION_FROM_NOWHERE)
-            currentRecommendation = result;
           i++;
         }
         
@@ -582,11 +626,6 @@ public class Throttler
         synchronized (fetchBins)
         {
           bin = fetchBins.get(binName);
-          if (bin == null)
-          {
-            bin = new FetchBin(binName);
-            fetchBins.put(binName, bin);
-          }
         }
         // Reserve a slot
         if (bin == null || !bin.reserveFetchRequest())
@@ -647,12 +686,8 @@ public class Throttler
         for (String binName : binNames)
         {
           ThrottleBin bin = throttleBins.get(binName);
-          if (bin == null)
-          {
-            bin = new ThrottleBin(binName);
-            throttleBins.put(binName,bin);
-          }
-          bin.beginFetch();
+          if (bin != null)
+            bin.beginFetch();
         }
       }
       
@@ -789,7 +824,7 @@ public class Throttler
         while (binIter.hasNext())
         {
           ConnectionBin bin = binIter.next();
-          bin.shutDown();
+          bin.shutDown(threadContext);
           binIter.remove();
         }
       }
@@ -800,7 +835,7 @@ public class Throttler
         while (binIter.hasNext())
         {
           FetchBin bin = binIter.next();
-          bin.shutDown();
+          bin.shutDown(threadContext);
           binIter.remove();
         }
       }
@@ -811,7 +846,7 @@ public class Throttler
         while (binIter.hasNext())
         {
           ThrottleBin bin = binIter.next();
-          bin.shutDown();
+          bin.shutDown(threadContext);
           binIter.remove();
         }
       }