manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1550331 - in /manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core: system/ManifoldCF.java throttler/ConnectionThrottler.java throttler/Throttler.java
Date Thu, 12 Dec 2013 02:18:04 GMT
Author: kwright
Date: Thu Dec 12 02:18:04 2013
New Revision: 1550331

URL: http://svn.apache.org/r1550331
Log:
Hook up connection throttler to shutdown hook.

Modified:
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
    manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.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/system/ManifoldCF.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java?rev=1550331&r1=1550330&r2=1550331&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
(original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
Thu Dec 12 02:18:04 2013
@@ -253,6 +253,8 @@ public class ManifoldCF
           masterDatabaseUsername = LockManagerFactory.getStringProperty(threadContext,masterDatabaseUsernameProperty,"manifoldcf");
           masterDatabasePassword = LockManagerFactory.getStringProperty(threadContext,masterDatabasePasswordProperty,"local_pg_passwd");
 
+          // Register the throttler for cleanup on shutdown
+          addShutdownHook(new ThrottlerShutdown());
           // Register the file tracker for cleanup on shutdown
           tracker = new FileTrack();
           addShutdownHook(tracker);
@@ -1383,6 +1385,38 @@ public class ManifoldCF
 
   }
 
+  /** Class that cleans up throttler on exit */
+  protected static class ThrottlerShutdown implements IShutdownHook
+  {
+    public ThrottlerShutdown()
+    {
+    }
+    
+    @Override
+    public void doCleanup(IThreadContext threadContext)
+      throws ManifoldCFException
+    {
+      IConnectionThrottler connectionThrottler = ConnectionThrottlerFactory.make(threadContext);
+      connectionThrottler.destroy();
+    }
+    
+    /** Finalizer, which is designed to catch class unloading that tomcat 5.5 does.
+    */
+    protected void finalize()
+      throws Throwable
+    {
+      try
+      {
+        doCleanup(ThreadContextFactory.make());
+      }
+      finally
+      {
+        super.finalize();
+      }
+    }
+
+  }
+  
   /** Class that cleans up database handles on exit */
   protected static class DatabaseShutdown implements IShutdownHook
   {

Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java?rev=1550331&r1=1550330&r2=1550331&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java
(original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java
Thu Dec 12 02:18:04 2013
@@ -48,6 +48,7 @@ public class ConnectionThrottler impleme
   *@param binNames is the set of bin names to throttle for, within the throttle group.
   *@param currentTime is the current time, in ms. since epoch.
   */
+  @Override
   public void obtainConnectionPermission(String throttleGroup,
     IThrottleSpec throttleSpec, String[] binNames, long currentTime)
     throws ManifoldCFException
@@ -62,6 +63,7 @@ public class ConnectionThrottler impleme
   *@param throttleSpec is the throttle specification to use for the throttle group,
   *@param currentTime is the current time, in ms. since epoch.
   */
+  @Override
   public void releaseConnectionPermission(String throttleGroup,
     IThrottleSpec throttleSpec, String[] binNames, long currentTime)
     throws ManifoldCFException
@@ -79,6 +81,7 @@ public class ConnectionThrottler impleme
   *@param binNames is the set of bin names describing this documemnt.
   *@param currentTime is the current time, in ms. since epoch.
   */
+  @Override
   public void obtainFetchDocumentPermission(String throttleGroup,
     IThrottleSpec throttleSpec, String[] binNames, long currentTime)
     throws ManifoldCFException
@@ -95,6 +98,7 @@ public class ConnectionThrottler impleme
   *@param binNames is the set of bin names describing this documemnt.
   *@param currentTime is the current time, in ms. since epoch.
   */
+  @Override
   public void releaseFetchDocumentPermission(String throttleGroup,
     IThrottleSpec throttleSpec, String[] binNames, long currentTime)
     throws ManifoldCFException
@@ -110,6 +114,7 @@ public class ConnectionThrottler impleme
   *@param currentTime is the current time, in ms. since epoch.
   *@param byteCount is the number of bytes to get permissions to read.
   */
+  @Override
   public void obtainReadPermission(String throttleGroup,
     IThrottleSpec throttleSpec, String[] binNames, long currentTime, int byteCount)
     throws ManifoldCFException
@@ -127,6 +132,7 @@ public class ConnectionThrottler impleme
   *@param origByteCount is the originally requested number of bytes to get permissions to
read.
   *@param actualByteCount is the number of bytes actually read.
   */
+  @Override
   public void releaseReadPermission(String throttleGroup,
     IThrottleSpec throttleSpec, String[] binNames, long currentTime, int origByteCount, int
actualByteCount)
     throws ManifoldCFException
@@ -137,6 +143,7 @@ public class ConnectionThrottler impleme
 
   /** Poll periodically.
   */
+  @Override
   public void poll()
     throws ManifoldCFException
   {
@@ -145,6 +152,7 @@ public class ConnectionThrottler impleme
   
   /** Free unused resources.
   */
+  @Override
   public void freeUnusedResources()
     throws ManifoldCFException
   {
@@ -153,6 +161,7 @@ public class ConnectionThrottler impleme
   
   /** Shut down throttler permanently.
   */
+  @Override
   public void destroy()
     throws ManifoldCFException
   {

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=1550331&r1=1550330&r2=1550331&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
Thu Dec 12 02:18:04 2013
@@ -41,6 +41,15 @@ public class Throttler
   {
   }
   
+  /** Check if throttle group name is still valid.
+  * This can be overridden, but right now nobody does it.
+  */
+  protected boolean isThrottleGroupValid(IThreadContext threadContext, String throttleGroupName)
+    throws ManifoldCFException
+  {
+    return true;
+  }
+  
   /** Get permission to use a connection, which is described by the passed array of bin names.
   * The connection can be used multiple
   * times until the releaseConnectionPermission() method is called.
@@ -141,7 +150,23 @@ public class Throttler
   public void poll(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // MHL
+    // Go through the whole pool and notify everyone
+    synchronized (poolHash)
+    {
+      Iterator<String> iter = poolHash.keySet().iterator();
+      while (iter.hasNext())
+      {
+        String throttleGroup = iter.next();
+        Pool p = poolHash.get(throttleGroup);
+        if (isThrottleGroupValid(threadContext,throttleGroup))
+          p.poll(threadContext);
+        else
+        {
+          p.destroy(threadContext);
+          iter.remove();
+        }
+      }
+    }
   }
   
   /** Free unused resources.
@@ -161,7 +186,7 @@ public class Throttler
     }
   }
   
-  /** Shut down throttler permanently.
+  /** Shut down all throttlers and deregister them.
   */
   public void destroy(IThreadContext threadContext)
     throws ManifoldCFException



Mime
View raw message