On Feb 12, 10:30 am, Hannes Wallnoefer <[EMAIL PROTECTED]> wrote: > On 12 Feb., 05:33, [EMAIL PROTECTED] wrote: > > > > > My question is: is it possible to (efficiently) serialize my session > > scope such that no values in the global scope are serialized with the > > session? This would work like ScriptableOutputStream except that it > > would always choose to stub values that are present in the global > > scope, instead of just when they have been added as excluded names. If > > I am not mistaken, this means that I need to be able to work backwards > > from an arbitrary Scriptable reference to a fully qualified name with > > respect to the global scope. Can this be done? Any suggestions are > > appreciated. > > Yes, this is possible. I think it's simpler to exclude the global > scope as a whole instead of each of its properties. In Helma, we have > an interface called SerializationProxy [1], and one class implementing > it is GlobalProxy which is a placeholder for the global scope. All you > have to do then is subclass ScriptableOutputStream and > ScriptableInputStream. In ScriptableOutputStream, override > replaceObject(Object obj) to replace your global scope with a proxy > object, and in ScriptableInputStream, override resolveObject(Object > obj) to replace the proxy object back to the current global scope. For > an example, look at the serialize()/deserialize() methods in our > RhinoEngine class [2]. > > [1]http://dev.helma.org/trac/helma/browser/helma/helma/trunk/src/helma/s... > [2]http://dev.helma.org/trac/helma/browser/helma/helma/trunk/src/helma/s... > > Of course, it is easiest to do this if you use a special class for the > global scope (such as ImporterTopLevel or a custom subclass), but I > think it shouldn't be striclty necessary. > > hannes
Hi Hannes, Thanks for your reply! In fact I'm already using a subclass of ImporterTopLevel (which provides package management and some other facilities) as my global scope, so it is easy to identify. I'm afraid however that I have been unable to accomplish what you've described. I've subclassed ScriptableOutputStream to replace my global scope with a proxy object, and yet this is not reducing the size of my serialized session at all. I've instrumented my ScriptableOutputStream to log all of the objects it is asked to replace, and from this log it seems clear that the objects in the global scope (compiled functions mostly) to which my session is maintaining references are still being offered for serialization even though their parent scope is stubbed with the proxy. In my subclassed replaceObject method, is there any way that I can identify that the object being offered for replacement has the global scope as its ultimate parent, and to serialize instead something that will allow me to recover the analogous reference in another (identical) global scope? Any help is sincerely appreciated. Thanks, Ben Reesman _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
