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

60
LINES

< > BotCompany Repo | #1032886 // Meta_v2 - successor of Meta? [dev.]

JavaX fragment (include)

// Meta - a "minimal" approach to adding meta-level to Java objects
//
//   v2 - now much easier and more performant

// OK you can read the rants here: #1031838 so right now I will stick to
// describing the changes.

sclass Meta_v2 implements IMeta_v2 {

  // So what's new in Meta v2?
  
  // We still have one field - but now it's definitely a map (a map
  // can hold anything, so...)
  // And we make this field, or rather, the object contained in it,
  // "speak" for itself. It's just a map that you can use like any
  // other one. It may shape-shift during its operation, meaning it
  // can even change its base class to accomodate for special cases.
  
  // This, however, necessitates that the object can exchange itself
  // for another one at any point. Thus the regular Map interface
  // will not cut it. We design a variation of the Map interface called
  // MutatingMap.
  
  MutatingMap meta = someNiceEmptyMutatingMapImplementationSingleton();
  
  // Field is still not transient.
  // And this time it is no longer volatile either which is of no
  // benefit in the new approach.
  
  // External mutexes and tempMetaMutex we don't need anymore.
  
  // So how do we synchronize? We just synchronize on the current meta
  // map. We do our deeds with it and if it mutates in the process, we
  // just put the mutation in the meta slot. And release the original
  // map's monitor after that. Done. "You end clean" as the magicians
  // say. Ahahaha.
  
  // So things should simplify from here, at least over version 1 of
  // the Meta interface.
  
  // You can still replace the whole map, nut this time we enforce a
  // proper type and we synchronize as per the statutes laid out above.
  
  public void _setMeta(MutatingMap meta) {
    assertNotNull(meta);
    synchronized(meta) {
      this.meta = meta;
    }
  }
  
  public MutatingMap _getMeta() { ret meta; }
  
  // That was layer 1...
  // ...and here is the convenience stuff - just use the meta field like a regular map.
  
  void metaSet aka metaPut(O key, O value) {
    synchronized(...
    metaMapPut(this, key, value); }
  O metaGet(O key) { ret metaMapGet(this, key); }
}

Author comment

Began life as a copy of #1031838

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032886
Snippet name: Meta_v2 - successor of Meta? [dev.]
Eternal ID of this version: #1032886/2
Text MD5: 9ddd00ec2930e6d38ed970cfd53fb000
Author: stefan
Category: javax / reasoning
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-07 15:06:49
Source code size: 2224 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 152 / 184
Version history: 1 change(s)
Referenced in: [show references]