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

Remembers which registry keys no player has claimed yet. More...

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

Public Member Functions

 UnclaimedShares (long claimWindowMillis, int maxEntries)
 
synchronized void registered (String key, long nowMillis)
 A key was registered at nowMillis.
 
synchronized void claimed (String key)
 A player took the key: it is never reported.
 
synchronized void released (String key)
 The key was given up in another way (released, removed): it is never reported.
 
synchronized List< String > dueForRemoval (long nowMillis)
 
synchronized int size ()
 

Static Public Attributes

static final long DEFAULT_CLAIM_WINDOW_MILLIS = ShareLimits.CLAIM_WINDOW_MILLIS
 The claim window used by default, see ShareLimits#CLAIM_WINDOW_MILLIS.
 
static final int DEFAULT_MAX_ENTRIES = 64
 Tracked keys at most; the registry itself holds only a handful of shares.
 

Detailed Description

Remembers which registry keys no player has claimed yet.

Plain Java, thread-safe, time passed in.

Today only a player releases a share, so a share that no player ever picked up (the receiver went away, the player could not be created) would keep its registry slot, and for a file its open descriptor, until the absolute maximum of six hours. The glue calls registered right after ShareRegistry.register, claimed when a player took the key, released when it is given up in any other way, and from the sweeper dueForRemoval; the keys it returns are removed from the registry by the caller (which closes the source).

  • A key is due when it was registered MORE than the claim window ago (exactly at the window it is not yet due) and was neither claimed nor released. dueForRemoval forgets the keys it returns, so each is reported once.
  • A claimed or released that arrives before registered (a player can be fast) is remembered for a bounded number of keys and wins.
  • Bounded: at most maxEntries keys are tracked. When a registration pushes the oldest one out, that key is not forgotten silently: it is queued and returned as due by the next dueForRemoval, so the caller still removes it. (That queue is itself capped at {@value MAX_OVERFLOW}; the registry holds only a few shares at once, so this is never reached in practice.)
  • All methods are idempotent; null and empty keys are ignored.

Constructor & Destructor Documentation

◆ UnclaimedShares()

de.yaacc.share.UnclaimedShares.UnclaimedShares ( long claimWindowMillis,
int maxEntries )
Exceptions
IllegalArgumentExceptionif the window or the cap is not positive

Member Function Documentation

◆ dueForRemoval()

synchronized List< String > de.yaacc.share.UnclaimedShares.dueForRemoval ( long nowMillis)
Parameters
nowMillisthe current time, same clock as registered
Returns
the keys the caller must remove from the registry now: registered more than the claim window ago and never claimed or released, plus keys the cap pushed out; each key is returned once. A clock that ran backwards makes nothing due.

◆ registered()

synchronized void de.yaacc.share.UnclaimedShares.registered ( String key,
long nowMillis )

A key was registered at nowMillis.

Registering a known key again keeps the first time; a key that was claimed or released before is not tracked.

◆ size()

synchronized int de.yaacc.share.UnclaimedShares.size ( )
Returns
the number of keys currently tracked (not counting keys waiting in the overflow queue)

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