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

57
LINES

< > BotCompany Repo | #1027681 // Chat Bot Frontends Auto-Unloader

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6039L/29K).

1  
!7
2  
3  
cmodule FrontendUnloader > DynPrintLogAndEnabled {
4  
  switchable double timeout = 60.0; // in seconds after last activity
5  
  switchable double checkInterval = 10.0;
6  
  switchable bool actuallyUnload;
7  
  switchable bool verbose;
8  
  transient bool firstCheck = true;
9  
  transient volatile bool unloading;
10  
11  
  start {
12  
    dm_registerAs_direct chatBotFrontendUnloader();
13  
    dm_doEvery(1.0, checkInterval, r check);
14  
  }
15  
  
16  
  void check enter {
17  
    if (!enabled || dm_isBooting()) ret;
18  
    // stayLoaded -> module ID. also has a null key!
19  
    new MultiMap<Bool, S> mm;
20  
    for (O mod : vmBus_queryAll chatBotFrontend()) {
21  
      Bool b = cast dm_call(mod, 'shouldStayLoaded, timeout);
22  
      mm.put(b, dm_moduleID(mod));
23  
    }
24  
    if (empty(mm)) ret;
25  
    int nPlus = l(mm.get(true));
26  
    int nMinus = l(mm.get(false));
27  
    int nIndifferent = l(mm.get(null));
28  
    
29  
    if (verbose)
30  
      printWithTime("Results for timeout " + timeout + "s: " + nPlus + " should stay loaded, "
31  
        + nMinus + " can be unloaded, " + nIndifferent + " indifferent");
32  
      
33  
    if (actuallyUnload)
34  
      if (firstCheck)
35  
        firstCheck = false;
36  
      else
37  
        unloadModules(mm.get(false));
38  
  }
39  
  
40  
  void unloadModules(LS modules) {
41  
    if (empty(modules)) ret;
42  
    temp dm_tempSetField(unloading := true);
43  
    print("Unloading " + nModules(modules));
44  
    for (S mod : modules) {
45  
      print("  Unloading " + dm_moduleIDAndName(mod));
46  
      dm_pcall(mod, 'deleteYourself);
47  
    }
48  
  }
49  
  
50  
  afterVisualize {
51  
    addComponentInFront(buttons, dm_checkBox actuallyUnload());
52  
  }
53  
  
54  
  // API
55  
  
56  
  bool isUnloading() { ret unloading; }
57  
}

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: #1027681
Snippet name: Chat Bot Frontends Auto-Unloader
Eternal ID of this version: #1027681/14
Text MD5: 4962af64ac3230d732dae5db0628351a
Transpilation MD5: f1e360168c06283f34e1f672cfeeb599
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-05 16:43:43
Source code size: 1664 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 174 / 50921
Version history: 13 change(s)
Referenced in: [show references]