Channels, Pipelines, and database connections
Norman Maurer
norman.maurer at googlemail.com
Thu Oct 13 01:59:40 EDT 2011
Hi there,
comments inline...
2011/10/13 Matt DeLuco <list_usr at spacebox.net>:
> Hello,
>
> I'm just getting started with my own netty server, though I've read through
> a lot of the docs and examples. I have some questions about the basics.
>
> Is a Channel and associated ChannelPipeline created for every connection
> made to the server?
Yes.
Is a ChannelPipelineFactory created for each
> connection, or just once when I pass an instance to
> ServerBootstrap.setPipelineFactory()?
The ChannelPipelineFactory is just created once and create the
ChannelPipeline which then will be used with the connection (Channel)
>
> I'll be using netty to serve sql queries over http and using BoneCP to do
> RDBMS connection pooling. As it stands I've got a custom
> ChannelPipelineFactory to which I pass an ExecutionHandler and a BoneCP
> connection pool. Each time getPipeline() is called I add the
> ExecutionHandler to the pipeline and I get a connection from the database
> connection pool which I intend to pass to a custom ChannelHandler. The
> connection is assigned from the pool to a variable in getPipeline(), the
> variable then passed to a ChannelHandler.
A few comments:
* Be sure you add the "same" instance of the ExecutionHandler to each
pipeline. Its written to be used as singleton.
* I think hand over a db connection to every ChannelHandler is not
really what you want todo. As this would mean you would need to have
one db connection per channel (network connection). This is kind of
against the purpose of
a connection pool ;) Just pass the ConnectionPool to your custom
ChannelHandler ( I think you want to subclass
SimpleUpstreamChannelHandler and overwrite the messageReceived(...)
method) and retrieve a connection from it when needed, after doing the
work put it back.
>
> With my current approach I can't figure out where I would close the database
> connection to return it to the pool.
See my comments above...
>
> Would it make more sense to subclass Channel or ChannelPipeline to contain a
> reference to a database connection? I could then have a ChannelFuture or
> some such close the database connection when the Channel closes?
See my comments above...
>
> Thanks.
>
> -- Matt
Bye,
Norman
More information about the netty-users
mailing list