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

56
LINES

< > BotCompany Repo | #1020421 // Object References (e.g. Kept For Other Machines)

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

Libraryless. Compilation Failed (15525L/108K).

!7

sclass ORef {
  S globalID = aGlobalID();
  WeakReference ref;
  new Set<S> forMachines;
  long created = now(), lastAccessed;
}

module ObjectReferences > DynObjectTable<ORef> {
  transient Map<S, ORef> byGlobalID = synchroMap();
  transient Map<O, ORef> byObject = weakIdentityHashMap();
  
  start {
    dontPersist();
    itemToMap = func(ORef r) -> Map {
      O o = getWeakRef(r.ref);
      ret litorderedmap(
        "Global ID" := r.globalID,
        "Type" := o == null ? "gone" : className(o),
        "Last Accessed" := formatLocalDateWithSeconds(r.lastAccessed),
        "For Machines" := joinWithComma(r.forMachines));
    };
  }
  
  O _getReloadData() { ret data; }
  void _setReloadData(L data) { addAll(this.data, map(data, func(O o) -> ORef { shallowCloneToClass(ORef, o) })); }

  // API
  
  // returns global ID
  S addReferencedObject(O object, S forMachine) {
    ORef r;
    bool isNew;
    {
      lock lock;
      r = byObject.get(object);
      isNew = r == null;
      if (isNew) {
        r = new ORef;
        r.ref = weakRef(object);
        byGlobalID.put(r.globalID, r);
        byObject.put(object, r);
      }
      r.lastAccessed = now();
      r.forMachines.add(forMachine);
    }
    if (isNew) add(r);
    ret r.globalID;
  }
  
  O getReferencedObject(S globalID) {
    ORef r = byGlobalID.get(globalID);
    ret r == null ? null : r.ref!;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020421
Snippet name: Object References (e.g. Kept For Other Machines)
Eternal ID of this version: #1020421/14
Text MD5: 8d710bfa4f7cf879d5b640e23be29261
Transpilation MD5: e24cced520394fb353b0fe1f0076db01
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-21 15:42:30
Source code size: 1444 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 297 / 847
Version history: 13 change(s)
Referenced in: [show references]