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)

1  
// Meta - a "minimal" approach to adding meta-level to Java objects
2  
//
3  
//   v2 - now much easier and more performant
4  
5  
// OK you can read the rants here: #1031838 so right now I will stick to
6  
// describing the changes.
7  
8  
sclass Meta_v2 implements IMeta_v2 {
9  
10  
  // So what's new in Meta v2?
11  
  
12  
  // We still have one field - but now it's definitely a map (a map
13  
  // can hold anything, so...)
14  
  // And we make this field, or rather, the object contained in it,
15  
  // "speak" for itself. It's just a map that you can use like any
16  
  // other one. It may shape-shift during its operation, meaning it
17  
  // can even change its base class to accomodate for special cases.
18  
  
19  
  // This, however, necessitates that the object can exchange itself
20  
  // for another one at any point. Thus the regular Map interface
21  
  // will not cut it. We design a variation of the Map interface called
22  
  // MutatingMap.
23  
  
24  
  MutatingMap meta = someNiceEmptyMutatingMapImplementationSingleton();
25  
  
26  
  // Field is still not transient.
27  
  // And this time it is no longer volatile either which is of no
28  
  // benefit in the new approach.
29  
  
30  
  // External mutexes and tempMetaMutex we don't need anymore.
31  
  
32  
  // So how do we synchronize? We just synchronize on the current meta
33  
  // map. We do our deeds with it and if it mutates in the process, we
34  
  // just put the mutation in the meta slot. And release the original
35  
  // map's monitor after that. Done. "You end clean" as the magicians
36  
  // say. Ahahaha.
37  
  
38  
  // So things should simplify from here, at least over version 1 of
39  
  // the Meta interface.
40  
  
41  
  // You can still replace the whole map, nut this time we enforce a
42  
  // proper type and we synchronize as per the statutes laid out above.
43  
  
44  
  public void _setMeta(MutatingMap meta) {
45  
    assertNotNull(meta);
46  
    synchronized(meta) {
47  
      this.meta = meta;
48  
    }
49  
  }
50  
  
51  
  public MutatingMap _getMeta() { ret meta; }
52  
  
53  
  // That was layer 1...
54  
  // ...and here is the convenience stuff - just use the meta field like a regular map.
55  
  
56  
  void metaSet aka metaPut(O key, O value) {
57  
    synchronized(...
58  
    metaMapPut(this, key, value); }
59  
  O metaGet(O key) { ret metaMapGet(this, key); }
60  
}

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: 93 / 118
Version history: 1 change(s)
Referenced in: [show references]