sclass GazelleContextCache_v2 extends F0<GazelleEvalContext> { transient Lock lock = lock(); transient GazelleEvalContext cachedCtx; DynModule module; bool debug = true; F0<L<T3<S>>> grabRules = func -> L<T3<S>> { //dm_gazelle_allRulesWithComment(gazelle_requiredComment()) gazelle_allRuleTriples() }; S mechListPrefix; bool alwaysFullRefresh; // safer // TODO: add or remove if condition changes on rule *() {} *(DynModule *module) {} GazelleContextCache_v2 fill() { loadRules(callF(grabRules)); this; } void loadRules(L<T3S> rules) { lock lock; cachedCtx = dm_gazelle_stdEvalContext(rules); cachedCtx.mechListPrefix = unnull(mechListPrefix); gazelle_addHelpers(cachedCtx); } GazelleEvalContext get() { lock lock; ret gazelle_cloneCtx(cachedCtx); } void ruleChanged(S ruleID) { if (ruleID == null) ret; dm_q(module, r { lock lock; if (alwaysFullRefresh) ret with fill(); if (cachedCtx == null) ret; print("GazelleContextCache_v2: processing rule update " + ruleID); RuleEngine2 engine = cachedCtx.engine; RuleEngine2.Rule rule = engine.getRule(ruleID); if (rule == null) print("GazelleContextCache_v2: rule not found, assuming it's new"); else engine.rules.remove(rule); PairS p = dm_textAndCommentForRule(ruleID); if (p == null) ret with print("GazelleContextCache_v2: no text found for rule"); engine.addRules2(ll(t3(p.a, p.b, ruleID))); rule = cachedCtx.engine.getRule(ruleID); if (rule == null) ret with print("GazelleContextCache_v2: rule not properly added"); gazelle_addHelpers(nu(GazelleEvalContext, engine := gazelle_dummyEngineWithRule(rule))); gazelle_updateStatsForRule(cachedCtx, ruleID); print("GazelleContextCache_v2: rule update complete"); }); } // works only when module != null AutoCloseable listenToMessages() { ret combineAutoCloseables( vmBus_onMessage('gazellePleaseClearRuleCaches, r { dm_q(module, r fill) }), vmBus_onMessage('gazelleRuleFeedbackChanged, vf<S> ruleChanged), vmBus_onMessage('gazelleRuleChanged, voidfunc(O ruleObj) { ruleChanged(getString globalID(ruleObj)) }), vmBus_onMessage('gazelleRuleDeleted, voidfunc(O rule) { S ruleID = getString globalID(rule); dm_q(module, r { lock lock; if (cachedCtx == null) ret; cachedCtx.engine.deleteRule(ruleID); print("GazelleContextCache_v2: rule " + ruleID + " deleted"); }) })); } void alwaysFullRefresh() { set alwaysFullRefresh; fill(); } }
Began life as a copy of #1021911
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney
No comments. add comment
Snippet ID: | #1022074 |
Snippet name: | GazelleContextCache_v2 - keeps loaded rules & updates them individually |
Eternal ID of this version: | #1022074/27 |
Text MD5: | c1d0206c9ffe3d59a4dc565426f24081 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-03-23 04:47:11 |
Source code size: | 2753 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 350 / 855 |
Version history: | 26 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |