Channels, Pipelines, and database connections

Norman Maurer norman.maurer at googlemail.com
Thu Oct 13 13:51:56 EDT 2011


Yes I think thats better.. As otherwise you need to have an 1:1
relation between db connections and client connections. Which will not
work out on big scale.

Bye,
Norman

2011/10/13 Matt DeLuco <list_usr at spacebox.net>:
> Norman, thanks for the reply.
>
> I had considered passing the pool to the ChannelHandler, but
> reconsidered when I thought I might be passing it to multiple
> ChannelHandlers, having to open and close a pooled connection multiple
> times.
>
> The connections are pooled, but I thought I might be better off just
> getting one connection from the pool and passing it between
> ChannelHandlers, returning the connection to the pool only when all
> DB-related ChannelHandlers are done with it (or when the connection
> closes.)
>
> Do you still think I'm better off just passing the pool to
> ChannelHandlers and potentially opening/closing db connections
> multiple times per client connection to the netty server?
>
> MD
>
>
> On Thu, Oct 13, 2011 at 1:59 AM, Norman Maurer
> <norman.maurer at googlemail.com> wrote:
>> 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
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



More information about the netty-users mailing list