Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1015196 // ManualTailFile

JavaX fragment (include)

sclass ManualTailFile extends TailFile {
  long lastCheck;
  Lock lock = lock();
  
  // onData: Runnable or voidfunc(S)
  *(final File *file, int *interval, fO *onData) {}
  *(final File *file, fO *onData) { interval = 100; }
  
  // updates in this thread
  void check() {
    long l2 = 0;
    {
      lock lock;
      long now = sysNow();
      if (now < lastCheck+interval) ret;
      
      lastCheck = now;
      l2 = l(file);
      if (l2 < l) l = 0; // file shrunk (log rotated!) - start over from beginning of file
      if (l2 == l) hasIdled = true;
      else pcall {
        if (debug) print("New data in " + f2s(file) + ": " + n2(l2-l, "byte"));
      }
    }
    
    // call onData outside of locked part
    for (S s : loadTextFilePart_iterator(file, l, l2))
      pcallF(onData, s);
      
    l = l2;
  }
}

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: 468 / 1017
Version history: 6 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)