YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.share.ShareConcurrencyLimiter Class Reference

Caps the number of responses that are streaming from one share at the same time. More...

Collaboration diagram for de.yaacc.share.ShareConcurrencyLimiter:
Collaboration graph

Classes

class  Lease
 One running response; release() is idempotent.
 
enum  State
 

Public Member Functions

 ShareConcurrencyLimiter (int max)
 
 ShareConcurrencyLimiter (int max, LongSupplier clock)
 
Lease tryAcquire (String key)
 
int expireIdle (long idleMillis)
 Takes the slot away from every lease that made no progress for more than idleMillis.
 
int activeCount (String key)
 
int trackedKeys ()
 

Static Public Member Functions

static ShareConcurrencyLimiter shared ()
 The limiter of the whole process (the HTTP server's responses and the sweeper share it).
 

Detailed Description

Caps the number of responses that are streaming from one share at the same time.

A response takes a Lease before it starts and gives it back when it ends; the lease can be released any number of times (the HTTP library may report the end of a response through more than one callback). Plain Java, thread safe.

Watchdog: a response reports its progress to the lease (Lease#noteProgress); a periodic expireIdle takes the slot away from a lease that made no progress for the idle time, so a stalled or trickling reader cannot hold the slots of a share. The response itself is not cut off: if it is called again (the reader resumed after a pause) it asks for a slot again (Lease#tryReacquire(), same cap) and aborts only if the share is full. The slot is given back exactly once, however often a lease expired and resumed.

Constructor & Destructor Documentation

◆ ShareConcurrencyLimiter() [1/2]

de.yaacc.share.ShareConcurrencyLimiter.ShareConcurrencyLimiter ( int max)
Exceptions
IllegalArgumentExceptionif max is not positive

◆ ShareConcurrencyLimiter() [2/2]

de.yaacc.share.ShareConcurrencyLimiter.ShareConcurrencyLimiter ( int max,
LongSupplier clock )
Parameters
clockmonotonic milliseconds
Exceptions
IllegalArgumentExceptionif max is not positive

Member Function Documentation

◆ activeCount()

int de.yaacc.share.ShareConcurrencyLimiter.activeCount ( String key)
Returns
the number of responses currently holding a lease for the key

◆ expireIdle()

int de.yaacc.share.ShareConcurrencyLimiter.expireIdle ( long idleMillis)

Takes the slot away from every lease that made no progress for more than idleMillis.

Call it periodically (the share sweeper does, every minute).

Returns
the number of leases that were expired
Exceptions
IllegalArgumentExceptionif idleMillis is not positive

◆ trackedKeys()

int de.yaacc.share.ShareConcurrencyLimiter.trackedKeys ( )
Returns
the number of keys with at least one lease (bookkeeping size, for tests)

◆ tryAcquire()

Lease de.yaacc.share.ShareConcurrencyLimiter.tryAcquire ( String key)
Parameters
keya well-formed share key (ShareRegistry#isWellFormedKey)
Returns
a lease, or null if the share already serves the maximum or the key is malformed
Here is the call graph for this function:

The documentation for this class was generated from the following file: