Class Throttler.ThrottlingGroup
- java.lang.Object
-
- org.apache.manifoldcf.connectorcommon.throttler.Throttler.ThrottlingGroup
-
- Enclosing class:
- Throttler
protected class Throttler.ThrottlingGroup extends java.lang.ObjectThis class represents a throttling group, of a specific throttling group type. It basically describes an entire self-consistent throttling environment.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,ConnectionBin>connectionBinsThe connection binsprotected java.util.Map<java.lang.String,FetchBin>fetchBinsThe fetch binsprotected java.util.Map<java.lang.String,ThrottleBin>throttleBinsThe throttle binsprotected IThrottleSpecthrottleSpecThe current throttle specprotected java.lang.StringthrottlingGroupNameThe throttling group name
-
Constructor Summary
Constructors Constructor Description ThrottlingGroup(IThreadContext threadContext, java.lang.String throttlingGroupType, java.lang.String throttleGroup, IThrottleSpec throttleSpec)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckDestroyPooledConnection(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)booleancheckExpireConnection(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)Connection expiration is tricky, because even though a connection may be identified as being expired, at the very same moment it could be handed out in another thread.voidcloseStream(java.lang.String[] binNames)Note the stream being closed.IStreamThrottlercreateFetchStream(java.lang.String[] binNames)voiddestroy(IThreadContext threadContext)Destroy this pool.voidfreeUnusedResources(IThreadContext threadContext)Free unused resources.IFetchThrottlergetNewConnectionFetchThrottler(java.lang.String[] binNames)voidnoteConnectionDestroyed(java.lang.String[] binNames)voidnoteConnectionReturnedToPool(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)booleannoteReturnedConnection(java.lang.String[] binNames)IConnectionThrottlerobtainConnectionThrottler(IThreadContext threadContext, java.lang.String[] binNames)Create a bunch of bins, corresponding to the bin names specified.booleanobtainFetchDocumentPermission(java.lang.String[] binNames, IBreakCheck breakCheck)Get permission to fetch a document.booleanobtainReadPermission(java.lang.String[] binNames, int byteCount, IBreakCheck breakCheck)Obtain permission to read a block of bytes.voidpoll(IThreadContext threadContext)Call this periodically.voidreleaseReadPermission(java.lang.String[] binNames, int origByteCount, int actualByteCount)Note the completion of the read of a block of bytes.voidupdateThrottleSpecification(IThrottleSpec throttleSpec)Update the throttle spec.intwaitConnectionAvailable(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts, IBreakCheck breakCheck)Wait for a connection to become available.
-
-
-
Field Detail
-
throttlingGroupName
protected final java.lang.String throttlingGroupName
The throttling group name
-
throttleSpec
protected IThrottleSpec throttleSpec
The current throttle spec
-
connectionBins
protected final java.util.Map<java.lang.String,ConnectionBin> connectionBins
The connection bins
-
fetchBins
protected final java.util.Map<java.lang.String,FetchBin> fetchBins
The fetch bins
-
throttleBins
protected final java.util.Map<java.lang.String,ThrottleBin> throttleBins
The throttle bins
-
-
Constructor Detail
-
ThrottlingGroup
public ThrottlingGroup(IThreadContext threadContext, java.lang.String throttlingGroupType, java.lang.String throttleGroup, IThrottleSpec throttleSpec) throws ManifoldCFException
Constructor- Throws:
ManifoldCFException
-
-
Method Detail
-
obtainConnectionThrottler
public IConnectionThrottler obtainConnectionThrottler(IThreadContext threadContext, java.lang.String[] binNames) throws ManifoldCFException
Create a bunch of bins, corresponding to the bin names specified. Note that this also registers them as services etc.- Parameters:
binNames- describes the set of bins to create.- Throws:
ManifoldCFException
-
updateThrottleSpecification
public void updateThrottleSpecification(IThrottleSpec throttleSpec) throws ManifoldCFException
Update the throttle spec.- Parameters:
throttleSpec- is the new throttle spec for this throttle group.- Throws:
ManifoldCFException
-
waitConnectionAvailable
public int waitConnectionAvailable(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts, IBreakCheck breakCheck) throws java.lang.InterruptedException, BreakExceptionWait for a connection to become available.- Parameters:
poolCounts- is a description of how many connections are available in the current pool, across all bins.- Returns:
- the IConnectionThrottler codes for results.
- Throws:
java.lang.InterruptedExceptionBreakException
-
getNewConnectionFetchThrottler
public IFetchThrottler getNewConnectionFetchThrottler(java.lang.String[] binNames)
-
noteReturnedConnection
public boolean noteReturnedConnection(java.lang.String[] binNames)
-
checkDestroyPooledConnection
public boolean checkDestroyPooledConnection(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)
-
checkExpireConnection
public boolean checkExpireConnection(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)Connection expiration is tricky, because even though a connection may be identified as being expired, at the very same moment it could be handed out in another thread. So there is a natural race condition present. The way the connection throttler deals with that is to allow the caller to reserve a connection for expiration. This must be called BEFORE the actual identified connection is removed from the connection pool. If the value returned by this method is "true", then a connection MUST be removed from the pool and destroyed, whether or not the identified connection is actually still available for destruction or not.- Returns:
- true if a connection from the pool can be expired. If true is returned, noteConnectionDestruction() MUST be called once the connection has actually been destroyed.
-
noteConnectionReturnedToPool
public void noteConnectionReturnedToPool(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)
-
noteConnectionDestroyed
public void noteConnectionDestroyed(java.lang.String[] binNames)
-
obtainFetchDocumentPermission
public boolean obtainFetchDocumentPermission(java.lang.String[] binNames, IBreakCheck breakCheck) throws java.lang.InterruptedException, BreakExceptionGet 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.- Parameters:
binNames- are the names of the bins.- Returns:
- false if being shut down
- Throws:
java.lang.InterruptedExceptionBreakException
-
createFetchStream
public IStreamThrottler createFetchStream(java.lang.String[] binNames)
-
obtainReadPermission
public boolean obtainReadPermission(java.lang.String[] binNames, int byteCount, IBreakCheck breakCheck) throws java.lang.InterruptedException, BreakExceptionObtain 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.- Parameters:
byteCount- is the number of bytes to get permissions to read.- Returns:
- true if the wait took place as planned, or false if the system is being shut down.
- Throws:
java.lang.InterruptedExceptionBreakException
-
releaseReadPermission
public void releaseReadPermission(java.lang.String[] binNames, int origByteCount, int actualByteCount)Note the completion of the read of a block of bytes. Call this after obtainReadPermission() was successfully called, and bytes were successfully read.- Parameters:
origByteCount- is the originally requested number of bytes to get permissions to read.actualByteCount- is the number of bytes actually read.
-
closeStream
public void closeStream(java.lang.String[] binNames)
Note the stream being closed.
-
poll
public void poll(IThreadContext threadContext) throws ManifoldCFException
Call this periodically.- Throws:
ManifoldCFException
-
freeUnusedResources
public void freeUnusedResources(IThreadContext threadContext) throws ManifoldCFException
Free unused resources.- Throws:
ManifoldCFException
-
destroy
public void destroy(IThreadContext threadContext) throws ManifoldCFException
Destroy this pool.- Throws:
ManifoldCFException
-
-