Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Netty handler unique for each connection?

Tags:

java

netty

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?

like image 287
wns349 Avatar asked Feb 14 '13 06:02

wns349


People also ask

Is Netty single threaded?

In this article we're focused on debugging and extending code using Netty so we won't look at them too closely. This is a container for EventLoop objects. Each EventLoop object is exclusively associated with a single Thread. Each Channel is associated with a single EventLoop throughout its lifetime.

What is the use of Netty handler?

Netty allows you to write your own network protocol tailored to your specific requirements, optimizing the traffic flow for your specific situation, without the unnecessary overhead of something like HTTP or FTP.

What is Netty connection?

Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket server.

How does Netty server work?

Netty uses an event-driven application paradigm, so the pipeline of the data processing is a chain of events going through handlers. Events and handlers can be related to the inbound and outbound data flow. Inbound events can be the following: Channel activation and deactivation.


1 Answers

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.

like image 125
Nicholas Avatar answered Oct 07 '22 22:10

Nicholas