// 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); } }