[VW] Implementing pooled database connections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[VW] Implementing pooled database connections

Martin J. Laubach-2
  I'm implementing pooled database connection for seaside sessions.
Here's my first cut at it:

  (PoolSession is a subclass of WASession, but that's not important
for the moment).


PoolSession>>initialize
        pool := SharedQueue new.

PoolSession>>addToPool: anObject
        pool nextPut: anObject

PoolSession>>withPooledDo: aBlock
        | poolEntry |
       
        [poolEntry := pool next.
        aBlock value: poolEntry]
                        ensure: [pool nextPut: poolEntry]



  Is that enough to ensure after use the connection gets put back
in the pool or do I need some additional exception catching or
process arbitration or whatever?

  I probably want to validate the pooled connection before giving it
out so dead database connections get discarded/replaced, but that's
for later.

        mjl

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: [VW] Implementing pooled database connections

Lukas Renggli
>         [poolEntry := pool next.
>         aBlock value: poolEntry]
>                         ensure: [pool nextPut: poolEntry]
>
>   Is that enough to ensure after use the connection gets put back
> in the pool or do I need some additional exception catching or
> process arbitration or whatever?

This should work well, however take care that you don't do a #call:
within aBlock, ensure blocks don't work well together with
continuations.

> I probably want to validate the pooled connection before giving it
> out so dead database connections get discarded/replaced, but that's
> for later.

For production you certainly need something like this.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside