1 | sclass ManualTailFile extends TailFile { |
2 | long lastCheck; |
3 | Lock lock = lock(); |
4 | |
5 | // onData: Runnable or voidfunc(S) |
6 | *(final File *file, int *interval, fO *onData) {} |
7 | *(final File *file, fO *onData) { interval = 100; } |
8 | |
9 | // updates in this thread |
10 | void check() { |
11 | long l2 = 0; |
12 | { |
13 | lock lock; |
14 | long now = sysNow(); |
15 | if (now < lastCheck+interval) ret; |
16 | |
17 | lastCheck = now; |
18 | l2 = l(file); |
19 | if (l2 < l) l = 0; // file shrunk (log rotated!) - start over from beginning of file |
20 | if (l2 == l) hasIdled = true; |
21 | else pcall { |
22 | if (debug) print("New data in " + f2s(file) + ": " + n2(l2-l, "byte")); |
23 | } |
24 | } |
25 | |
26 | // call onData outside of locked part |
27 | for (S s : loadTextFilePart_iterator(file, l, l2)) |
28 | pcallF(onData, s); |
29 | |
30 | l = l2; |
31 | } |
32 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1015196 |
Snippet name: | ManualTailFile |
Eternal ID of this version: | #1015196/7 |
Text MD5: | 5fa77d0ff654800ef626d6f995f13ab6 |
Author: | stefan |
Category: | javax / i.o. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-10-28 14:04:09 |
Source code size: | 855 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 469 / 1018 |
Version history: | 6 change(s) |
Referenced in: | [show references] |