|
YAACC - UPNP Client and Server
|
The copy fallback with a watchdog. More...

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 () |
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.
| de.yaacc.share.WatchedCopy.WatchedCopy | ( | long | timeoutMillis, |
| int | maxStuckWorkers ) |
| timeoutMillis | the longest a copy may take, positive |
| maxStuckWorkers | abandoned workers allowed to stay alive, at least 1 |
| 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.
| budget | the most bytes the copy may take, evaluated after the slot was taken |
| usable | the free space on the volume, asked before every chunk |
| Failure | for every failure |
Referenced by de.yaacc.share.SharedFileOpener.copyAndHold().


| int de.yaacc.share.WatchedCopy.stuckWorkers | ( | ) |
