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

46
LINES

< > BotCompany Repo | #1028641 // WebBotTester

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (6589L) is out of date.

sclass WebBotTester implements AutoCloseable {
  S botURL; // without the "/incremental"
  S cookie = "test_" + aGlobalID();
  int n; // number of messages grabbed
  Thread grabThread;
  volatile bool closed;
  LS allHtml = syncList();
  new L<WebChatBotMsg> msgs;
  double readTimeout = 120.0, sendTimeout = 20.0;
  double waitForMessagesTimeout = 20.0;
  SS params = new LinkedHashMap;

  *(S botID) { botURL = "https://botcompany.de/" + psI(botID) + "/raw"; }
  
  public void close {
    set closed;
    cancelAndInterruptThread(grabThread);
  }
  
  selfType start() {
    if (grabThread == null)
      grabThread = startThread(r _grabLoop);
    this;
  }
  
  void _grabLoop {
    while (!closed) {
      S html = loadPageWithTimeout(botURL + "/incremental" + hquery(mapPlus(params, +cookie, a := n)), readTimeout);
      allHtml.add(html);
      printWithIndent("> ", html);
      msgs.addAll(webBotTester_extractMsgs(html));
      S comment = first(getHTMLComments(html));
      int n = parseFirstIntOrMinus1(comment);
      if (n >= 0) this.n = n;
      sleepSeconds(1);
    }
  }
  
  void sendMsg(S message) {
    print(doPostWithTimeout(mapPlus(params, +cookie, +message), botURL + "/msg", toMS_int(sendTimeout)));
  }
  
  void waitForMessages(int n) {
    waitUntil(50, waitForMessagesTimeout, () -> l(msgs) >= n);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028641
Snippet name: WebBotTester
Eternal ID of this version: #1028641/18
Text MD5: 9005533c32e504eb10be71be09b3e6a4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-02 18:21:25
Source code size: 1379 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 269 / 630
Version history: 17 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)