On Fri, 2002-02-01 at 10:36, Tod Harter wrote:
> I can tell you exactly why things need to be ordered that way. It might not 
> seem right on the surface of it, but the problem is that its expensive with 
> some protocols to establish the initial connection, so you don't want to be 
> doing that for each method call, you need a SCOPE in which the connection is 
> valid and a handle is held, so there needs to be a setup block of code BEFORE 
> any calls are made and then a tear down afterwards. In our case we have SOAP 
> doing object activation/deactivation and remote garbage collection, so once 
> the handle to an object goes out of local scope remote garbage collection is 
> triggered (via DESTROY). Database handles are an analogous situation. I 
> expect that the ESQL taglib needs to construct them in the STARTING part of 
> its tag sets, not later on (though one could devise ways to defer things).

Yeah, that's probably a big part of why I don't like ESQL. All of those
explicit connections and stuff.

I'm a big believer in using lazy initialization in these kinds of cases.
If I were to do this kind of thing, I would keep a cache of open
connections. When someone wants to connect to server X, I do a lookup
for a connection for server X. If it's not in the cache, I initiate one
and stick it in the cache.

Then it's just a matter of deciding when to do the cleanup. The main
possibilities are to use a post-request cleanup handler, to not clean up
post-request, but instead do a quick run through the cache when someone
asks for a connection and get rid of "old" connections, or to do no
cleanup and let the connections die when the Apache child dies.

I use the garbage-collecting approach for url->file lookup cache entries
(the "Sitemap", an internal module). For most database servers, I let
Apache kill the connections at die time, but for one of them (Sybase)
under certain circumstances I close the connection post-request.

The advantage of this approach isn't just architectural. It's also in
the interfaces. If you do this lazy-connection stuff, you don't need to
have explicit "connect to server X now please" commands in your XML.
Just reference it, and the necessary connections are automatically
built.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to