camel-netty restrict connections

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

camel-netty restrict connections

kiranreddykasa
Hi

Is there any way we can restrict the number of clients that can connect the netty server ?
For eg  

client 1 --->netty server

client 2 ---->netty server

the second connection should not be allowed while the first connection is active.

Once the first connection is closed then second client can connect.
Regards

kiran Reddy
Reply | Threaded
Open this post in threaded view
|

Re: camel-netty restrict connections

Claus Ibsen-2
Hi

Have you checked the Netty documentation / forum?

And what do you mean by not allowed? Should the client be denied a
connection to the netty server,
or should the netty server, just "delay" until the 1st is done, and
then continue processing that?

You can possible set the worker pool to have only 1 thread.

On Wed, Dec 12, 2012 at 1:54 PM, kiranreddykasa <[hidden email]> wrote:

> Hi
>
> Is there any way we can restrict the number of clients that can connect the
> netty server ?
> For eg
>
> client 1 --->netty server
>
> client 2 ---->netty server
>
> the second connection should not be allowed while the first connection is
> active.
>
> Once the first connection is closed then second client can connect.
>
>
>
> -----
> Regards
>
> kiran Reddy
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-netty-restrict-connections-tp5723951.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: camel-netty restrict connections

Claus Ibsen-2
On Fri, Dec 14, 2012 at 2:37 PM, Claus Ibsen <[hidden email]> wrote:
> Hi
>
> Have you checked the Netty documentation / forum?
>

Norman from the Netty team said the ipfilter should be the way to do this
http://static.netty.io/3.5/api/org/jboss/netty/handler/ipfilter/package-summary.html

> And what do you mean by not allowed? Should the client be denied a
> connection to the netty server,
> or should the netty server, just "delay" until the 1st is done, and
> then continue processing that?
>
> You can possible set the worker pool to have only 1 thread.
>
> On Wed, Dec 12, 2012 at 1:54 PM, kiranreddykasa <[hidden email]> wrote:
>> Hi
>>
>> Is there any way we can restrict the number of clients that can connect the
>> netty server ?
>> For eg
>>
>> client 1 --->netty server
>>
>> client 2 ---->netty server
>>
>> the second connection should not be allowed while the first connection is
>> active.
>>
>> Once the first connection is closed then second client can connect.
>>
>>
>>
>> -----
>> Regards
>>
>> kiran Reddy
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/camel-netty-restrict-connections-tp5723951.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: [hidden email]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: camel-netty restrict connections

kiranreddykasa
Hi

What I meant is the second client should be denied by the server,

I achieved this by checking the no of opened connections in 'channelOpen' method in 'ServerChannelHandler' and whenever  a new connection opens I will just close that connection.

I even added a new property to the 'NettyConfiguration' to check whether the netty endpoint is of this single connection type or normal type.

Here is the following code

        @Override
        public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
                        throws Exception {
                if (LOG.isTraceEnabled()) {
                        LOG.trace("Channel open: {}", e.getChannel());
                }
                if (consumer.getConfiguration().isSingleConnection()) {
                        if (consumer.getAllChannels().size() > 1) {
                                System.out.println("closed");
                                e.getChannel().disconnect();
                                return;
                        }
                }
                // to keep track of open sockets
                consumer.getAllChannels().add(e.getChannel());
        }
Regards

kiran Reddy
Reply | Threaded
Open this post in threaded view
|

Re: camel-netty restrict connections

Sachin
Netty works on Boss-Worker thread concept, where for each sub sequent connection request netty assigns a Boss thread which internally creates a new worker thread for each request. By default no of worker thread are (2 *no of core in your machine) ,Post camel-netty 2.9.1 it's expose worker thread property to restrict or upgrade worker threads. I dont think you can restrict Boss thread and hey it's the concept of NIO server e.g Mina, Netty , these should not restrict your connections requests just delay it.

If you really require it you can maintain it by maintaing a hashMap of connections checking size before allowing it to pass it to Netty.
Reply | Threaded
Open this post in threaded view
|

Re: camel-netty restrict connections

kiranreddykasa
Hi


Yeah I required these kind of server.

I have done like as you said by maintaining the number of connection in a group.
By checking the size of the group it decides whether to open a new connection or deny it.
kindly check the code which i posted in the above post.
Regards

kiran Reddy
Reply | Threaded
Open this post in threaded view
|

Re: camel-netty restrict connections

Christian Mueller
Administrator
In reply to this post by kiranreddykasa
I think you chooses a suitable solution.

Best,
Christian

On Mon, Dec 17, 2012 at 7:51 AM, kiranreddykasa <[hidden email]>wrote:

> Hi
>
> What I meant is the second client should be denied by the server,
>
> I achieved this by checking the no of opened connections in 'channelOpen'
> method in 'ServerChannelHandler' and whenever  a new connection opens I
> will
> just close that connection.
>
> I even added a new property to the 'NettyConfiguration' to check whether
> the
> netty endpoint is of this single connection type or normal type.
>
> Here is the following code
>
>         @Override
>         public void channelOpen(ChannelHandlerContext ctx,
> ChannelStateEvent e)
>                         throws Exception {
>                 if (LOG.isTraceEnabled()) {
>                         LOG.trace("Channel open: {}", e.getChannel());
>                 }
>                 if (consumer.getConfiguration().isSingleConnection()) {
>                         if (consumer.getAllChannels().size() > 1) {
>                                 System.out.println("closed");
>                                 e.getChannel().disconnect();
>                                 return;
>                         }
>                 }
>                 // to keep track of open sockets
>                 consumer.getAllChannels().add(e.getChannel());
>         }
>
>
>
> -----
> Regards
>
> kiran Reddy
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/camel-netty-restrict-connections-tp5723951p5724195.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--