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).

!7

cmodule FrontendUnloader > DynPrintLogAndEnabled {
  switchable double timeout = 60.0; // in seconds after last activity
  switchable double checkInterval = 10.0;
  switchable bool actuallyUnload;
  switchable bool verbose;
  transient bool firstCheck = true;
  transient volatile bool unloading;

  start {
    dm_registerAs_direct chatBotFrontendUnloader();
    dm_doEvery(1.0, checkInterval, r check);
  }
  
  void check enter {
    if (!enabled || dm_isBooting()) ret;
    // stayLoaded -> module ID. also has a null key!
    new MultiMap<Bool, S> mm;
    for (O mod : vmBus_queryAll chatBotFrontend()) {
      Bool b = cast dm_call(mod, 'shouldStayLoaded, timeout);
      mm.put(b, dm_moduleID(mod));
    }
    if (empty(mm)) ret;
    int nPlus = l(mm.get(true));
    int nMinus = l(mm.get(false));
    int nIndifferent = l(mm.get(null));
    
    if (verbose)
      printWithTime("Results for timeout " + timeout + "s: " + nPlus + " should stay loaded, "
        + nMinus + " can be unloaded, " + nIndifferent + " indifferent");
      
    if (actuallyUnload)
      if (firstCheck)
        firstCheck = false;
      else
        unloadModules(mm.get(false));
  }
  
  void unloadModules(LS modules) {
    if (empty(modules)) ret;
    temp dm_tempSetField(unloading := true);
    print("Unloading " + nModules(modules));
    for (S mod : modules) {
      print("  Unloading " + dm_moduleIDAndName(mod));
      dm_pcall(mod, 'deleteYourself);
    }
  }
  
  afterVisualize {
    addComponentInFront(buttons, dm_checkBox actuallyUnload());
  }
  
  // API
  
  bool isUnloading() { ret unloading; }
}

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: 168 / 50912
Version history: 13 change(s)
Referenced in: [show references]