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

The copy fallback with a watchdog. More...

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

Classes

class  Failure
 The copy failed; getReason() says why.
 
interface  FileCreator
 Creates the empty target file (before the worker starts, so the caller owns its deletion). More...
 
interface  Holder
 Holds the finished copy (reopens it as a seekable source). More...
 
interface  Input
 What is copied. More...
 
enum  Reason
 Why a copy did not happen. More...
 

Public Member Functions

 WatchedCopy (long timeoutMillis, int maxStuckWorkers)
 
PositionalSource copy (Input input, FileCreator creator, LongSupplier budget, LongSupplier usable, Holder holder) throws Failure
 Copies input into a new file and returns a source that holds it and deletes it when closed.
 
int stuckWorkers ()
 

Detailed Description

The copy fallback with a watchdog.

Plain Java.

BudgetedCopier asks for cancellation only BETWEEN reads, so a provider whose pipe never produces a byte would block the read for ever, on the thread that waits for the copy and while holding the copy slot (and, behind it, the intake gate). Here the copy runs on its own daemon worker (AbandonableCall) and the caller waits at most timeoutMillis. At the deadline the caller, from its own thread, closes the Input (closing a descriptor wakes a blocked libcore read) and the worker's output stream (so a stuck worker does not keep the partial file's blocks allocated after the delete), deletes the partial file, gives the copy slot back and reports Reason#TIMED_OUT, even if the worker stays stuck: it is abandoned. A worker that wakes up later finds out, stops, and cannot leave anything behind: the file was deleted and is only ever opened for writing without creating it, and a held copy it still produces is closed (which deletes the file) instead of being handed out.

One copy at a time (BUSY otherwise); at most maxStuckWorkers abandoned workers at once, beyond that a copy is turned away as busy.

Constructor & Destructor Documentation

◆ WatchedCopy()

de.yaacc.share.WatchedCopy.WatchedCopy ( long timeoutMillis,
int maxStuckWorkers )
Parameters
timeoutMillisthe longest a copy may take, positive
maxStuckWorkersabandoned workers allowed to stay alive, at least 1

Member Function Documentation

◆ copy()

PositionalSource de.yaacc.share.WatchedCopy.copy ( Input input,
FileCreator creator,
LongSupplier budget,
LongSupplier usable,
Holder holder ) throws Failure

Copies input into a new file and returns a source that holds it and deletes it when closed.

Closes input and deletes the file in every failure case.

Parameters
budgetthe most bytes the copy may take, evaluated after the slot was taken
usablethe free space on the volume, asked before every chunk
Exceptions
Failurefor every failure

Referenced by de.yaacc.share.SharedFileOpener.copyAndHold().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stuckWorkers()

int de.yaacc.share.WatchedCopy.stuckWorkers ( )
Returns
abandoned copy workers that are still alive (for tests and diagnostics)
Here is the call graph for this function:

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