Dear Eckhard,
Eckhard Lehmann schrieb:
One thing comes to mind since I play around with Tclhttpd and a persistency framework: Tclhttpd maintains sessions as safe slave interpreters. These interpreters must know about persistency objects in the server, so it is necessary that
- whenever a persistency object is created, a command alias for it
must be created in certain sessions (interpreters)
- whenever a session is created, certain persistency objects must be
"informed" (-> a command alias for them must be created in the new interpreter).
- whenever a session is destroyed, it's alias must be removed from all
persistency objects that contain it.
i would not recommend to use method combinators or filters for this kind of problem: This problem looks to me like an perfect example for metaclasses.
Meta-classes allow to create special kinds of classes. Sometimes you would like to have PersistentClasses, sometimes RemoteClasses, or LoggedClasses, etc. One can certainly use object or class mixins as well to mix the feature "persistency" into one or several classes. The mixin approach has advantages for finer-grained control, but i doubt that you will need it for e.g. session management.
So, for your problem, define a meta-class for classes with persistant objects and overwrite on the class level the methods "create" and "instdestroy". The same can be done with the Session class as well. I have not looked at the session model of TclHttpd, but from your specification, the class structure can look like the code below. The script produces the following output:
creating object p1 of class ::Person ... create an alias for p1 creating session s1 ... inform instances of ::Person creating object p1 of class ::Person ... create an alias for p1 creating object e1 of class ::Employee ... create an alias for e1 creating session s2 ... inform instances of ::Employee ::Person deleting session ::s2 deleting session ::s1 object ::e1 destroy ... delete alias for ::e1 object ::p1 destroy ... delete alias for ::p1
Hope, this helps. -gustaf neumann
############################################## package require XOTcl namespace import -force ::xotcl::*
Class PersistentClass -superclass Class PersistentClass instproc create {name args} { puts stderr "creating object $name of class [self]" puts stderr "... create an alias for $name" next } PersistentClass instproc instdestroy {name} { puts stderr "object $name destroy" puts stderr "... delete alias for $name" next }
Class Session Session proc create {name args} { puts stderr "creating session $name" puts stderr "... inform instances of [PersistentClass info instances]" next } Session proc instdestroy {name} { puts stderr "deleting session $name" next }
PersistentClass Person Person p1
Session s1
Person p1 PersistentClass Employee -superclass Person Employee e1
Session s2
s2 destroy s1 destroy