Class Throttler.ThrottlingGroup
- java.lang.Object
-
- org.apache.manifoldcf.connectorcommon.throttler.Throttler.ThrottlingGroup
-
- Enclosing class:
- Throttler
protected class Throttler.ThrottlingGroup extends java.lang.Object
This 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>
connectionBins
The connection binsprotected java.util.Map<java.lang.String,FetchBin>
fetchBins
The fetch binsprotected java.util.Map<java.lang.String,ThrottleBin>
throttleBins
The throttle binsprotected IThrottleSpec
throttleSpec
The current throttle specprotected java.lang.String
throttlingGroupName
The 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 boolean
checkDestroyPooledConnection(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)
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.void
closeStream(java.lang.String[] binNames)
Note the stream being closed.IStreamThrottler
createFetchStream(java.lang.String[] binNames)
void
destroy(IThreadContext threadContext)
Destroy this pool.void
freeUnusedResources(IThreadContext threadContext)
Free unused resources.IFetchThrottler
getNewConnectionFetchThrottler(java.lang.String[] binNames)
void
noteConnectionDestroyed(java.lang.String[] binNames)
void
noteConnectionReturnedToPool(java.lang.String[] binNames, java.util.concurrent.atomic.AtomicInteger[] poolCounts)
boolean
noteReturnedConnection(java.lang.String[] binNames)
IConnectionThrottler
obtainConnectionThrottler(IThreadContext threadContext, java.lang.String[] binNames)
Create a bunch of bins, corresponding to the bin names specified.boolean
obtainFetchDocumentPermission(java.lang.String[] binNames, IBreakCheck breakCheck)
Get permission to fetch a document.boolean
obtainReadPermission(java.lang.String[] binNames, int byteCount, IBreakCheck breakCheck)
Obtain permission to read a block of bytes.void
poll(IThreadContext threadContext)
Call this periodically.void
releaseReadPermission(java.lang.String[] binNames, int origByteCount, int actualByteCount)
Note the completion of the read of a block of bytes.void
updateThrottleSpecification(IThrottleSpec throttleSpec)
Update the throttle spec.int
waitConnectionAvailable(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, BreakException
Wait 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.InterruptedException
BreakException
-
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, BreakException
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.- Parameters:
binNames
- are the names of the bins.- Returns:
- false if being shut down
- Throws:
java.lang.InterruptedException
BreakException
-
createFetchStream
public IStreamThrottler createFetchStream(java.lang.String[] binNames)
-
obtainReadPermission
public boolean obtainReadPermission(java.lang.String[] binNames, int byteCount, IBreakCheck breakCheck) throws java.lang.InterruptedException, BreakException
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.- 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.InterruptedException
BreakException
-
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
-
-