wns349
wns349

Reputation: 1306

Is Netty handler unique for each connection?

I've been looking over at the proxy server example from Netty website:

The example source code handler has a volatile variable

private volatile Channel outboundChannel;

which takes care of the channel that connects to another server for proxy.

This got me to wonder if this is the correct and safe way to implement for multiple connections for proxy.

I would like to allow multiple connections(inbound) to connect to different outbounds, while making sure that every inbound connection is uniquely linked to the outbound channel.

According to my knowledge, Netty generates a new pipeline for each connection. Does this mean a newly generated handler by pipeline factory is uniquely dedicated to the new connection(channel)?

p.s. If I have 1,000 active connections to my Netty server, does this mean there are 1,000 different pipelines?

Upvotes: 7

Views: 10293

Answers (1)

Nicholas
Nicholas

Reputation: 16056

There is one pipeline created per connection, but the pipeline may contain both shared and exclusive handlers. Some handlers do not keep state and a single instance can be inserted into multiple [all] pipelines. Netty provided handlers that can be shared are annotated with ChannelHandler.Sharable. See the section titled Shared and Exclusive Channel Handlers in this tutorial.

Upvotes: 14

Related Questions