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/14 14:19:21 UTC
svn commit: r1550933 -
/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
Author: kwright
Date: Sat Dec 14 13:19:21 2013
New Revision: 1550933
URL: http://svn.apache.org/r1550933
Log:
More architecture work
Modified:
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/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=1550933&r1=1550932&r2=1550933&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 Sat Dec 14 13:19:21 2013
@@ -358,7 +358,8 @@ public class Throttler
}
}
- /** This class represents a throttling group, of a specific throttling group type.
+ /** This class represents a throttling group, of a specific throttling group type. It basically
+ * describes an entire self-consistent throttling environment.
*/
protected class ThrottlingGroup
{
@@ -405,6 +406,8 @@ public class Throttler
this.throttleSpec = throttleSpec;
}
+ // Connection acquisition methods
+
/** Obtain connection permission.
*@return null if we are marked as 'not alive'.
*/
@@ -417,8 +420,63 @@ public class Throttler
// MHL
// Wait on each reserved bin in turn
// MHL
- return null;
+ return new FetchThrottler(this, binNames);
+ }
+
+ // IFetchThrottler support methods
+
+ /** 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.
+ */
+ public IStreamThrottler obtainFetchDocumentPermission(String[] binNames, long currentTime)
+ throws InterruptedException
+ {
+ // MHL
+ return new StreamThrottler(this, binNames);
+ }
+
+ /** Release permission to fetch a document. Call this only when you
+ * called obtainFetchDocumentPermission() successfully earlier.
+ *@param currentTime is the current time, in ms. since epoch.
+ */
+ public void releaseFetchDocumentPermission(String[] binNames, long currentTime)
+ {
+ // MHL
+ }
+
+ // IStreamThrottler support methods
+
+ /** Obtain permission to read a block of bytes. This method may wait until it is OK to proceed.
+ * The throttle group, bin names, etc are already known
+ * to this specific interface object, so it is unnecessary to include them here.
+ *@param currentTime is the current time, in ms. since epoch.
+ *@param byteCount is the number of bytes to get permissions to read.
+ *@return true if the wait took place as planned, or false if the system is being shut down.
+ */
+ public boolean obtainReadPermission(String[] binNames, long currentTime, int byteCount)
+ throws InterruptedException
+ {
+ // MHL
+ return false;
}
+
+ /** Note the completion of the read of a block of bytes. Call this after
+ * obtainReadPermission() was successfully called, and bytes were successfully read.
+ *@param currentTime is the current time, in ms. since epoch.
+ *@param origByteCount is the originally requested number of bytes to get permissions to read.
+ *@param actualByteCount is the number of bytes actually read.
+ */
+ public void releaseReadPermission(String[] binNames, long currentTime, int origByteCount, int actualByteCount)
+ {
+ // MHL
+ }
+
+ // Bookkeeping methods
/** Call this periodically.
*/
@@ -477,4 +535,87 @@ public class Throttler
}
}
+ /** Fetch throttler implementation class.
+ * This basically stores some parameters and links back to ThrottlingGroup.
+ */
+ protected static class FetchThrottler implements IFetchThrottler
+ {
+ protected final ThrottlingGroup parent;
+ protected final String[] binNames;
+
+ public FetchThrottler(ThrottlingGroup parent, String[] binNames)
+ {
+ this.parent = parent;
+ this.binNames = binNames;
+ }
+
+ /** 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.
+ */
+ @Override
+ public IStreamThrottler obtainFetchDocumentPermission(long currentTime)
+ throws InterruptedException
+ {
+ return parent.obtainFetchDocumentPermission(binNames, currentTime);
+ }
+
+ /** Release permission to fetch a document. Call this only when you
+ * called obtainFetchDocumentPermission() successfully earlier.
+ *@param currentTime is the current time, in ms. since epoch.
+ */
+ @Override
+ public void releaseFetchDocumentPermission(long currentTime)
+ {
+ parent.releaseFetchDocumentPermission(binNames, currentTime);
+ }
+
+ }
+
+ /** Stream throttler implementation class.
+ * This basically stores some parameters and links back to ThrottlingGroup.
+ */
+ protected static class StreamThrottler implements IStreamThrottler
+ {
+ protected final ThrottlingGroup parent;
+ protected final String[] binNames;
+
+ public StreamThrottler(ThrottlingGroup parent, String[] binNames)
+ {
+ this.parent = parent;
+ this.binNames = binNames;
+ }
+
+ /** Obtain permission to read a block of bytes. This method may wait until it is OK to proceed.
+ * The throttle group, bin names, etc are already known
+ * to this specific interface object, so it is unnecessary to include them here.
+ *@param currentTime is the current time, in ms. since epoch.
+ *@param byteCount is the number of bytes to get permissions to read.
+ *@return true if the wait took place as planned, or false if the system is being shut down.
+ */
+ @Override
+ public boolean obtainReadPermission(long currentTime, int byteCount)
+ throws InterruptedException
+ {
+ return parent.obtainReadPermission(binNames, currentTime, byteCount);
+ }
+
+ /** Note the completion of the read of a block of bytes. Call this after
+ * obtainReadPermission() was successfully called, and bytes were successfully read.
+ *@param currentTime is the current time, in ms. since epoch.
+ *@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(long currentTime, int origByteCount, int actualByteCount)
+ {
+ parent.releaseReadPermission(binNames, currentTime, origByteCount, actualByteCount);
+ }
+
+ }
+
}