Netty3 litre netty4 lost sight, netty3netty4

Source: Internet
Author: User

Netty3 litre netty4 lost sight, netty3netty4

The old project is from netty3. I originally wanted to change it to netty5, but netty5 actually only supports jdk1.7. It is strange that neither jdk1.6 nor jdk1.8 works .. to be compatible with jdk1.6 and netty4, the difference is not big. The last netty4.

I read some experiences of netty3-litre netty4 in advance and started to work on it. after the change, run the command and find that only one of the two clients is working normally. The other client directly blocks the connection when establishing the connection:

channel = this.lastWriteFuture.awaitUninterruptibly().channel();

The connection establishment phase is directly congested, and I was a little dizzy at that time. What about deadlocks? The first impression is that there are countless threads in this project. I have no idea how to handle it all over again. Just write a simple demo client to connect to it. Everything is normal and there is no problem with the server.

There is no difference between the client code that can normally establish a connection with it (in fact, if the mind is fast, it should be able to locate the problem, the problem lasted for more than a day, so I had to use the most stupid method to eliminate it. I accumulated the demo code to the real code 1.1 points in the project, and found out where it was .. after n long time, I finally confirmed that there was a problem with the handler part of the client .. the handler inherits one layer, and the parent and child classes read it again and again, and nothing special is found. no way to continue using the most stupid method. Comment out a piece of code in a piece of code to see which part of the impact .. in this way, I found the problematic code segment after a long time. I didn't think there was any problem yet. I clicked it and looked at the documentation to find out the problem. I felt that the problem was wasted in the past two days ..

// Netty3 Method
@ Override public void channelConnected (ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {xxxx ;}

// Netty4 method I changed to @ Override public void connect (ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise future) throws Exception {xxxx ;}

This was replaced directly as a method... when a new rewrite method is generated, because the name is very similar, you can click Generate directly, and then write the implementation in the original channelConnected method into this method. in fact, if it throws an exception or an error, you should be able to immediately find the error .. however, you can see the following explanation by clicking the connect method:

CILS ChannelHandlerContext. connect (SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
// This method can be used to perform custom operations when the program is passed in multiple ChannelOutBoundHandler in the pipeline.

Then I wrote this method into another one, and I didn't call the connect (ctx, remoteAddress, localAddress, future) method, which caused this method function to be useless and cannot be passed in the pipeline. this is because there is no exception or error. When the connection arrives here, there is no return value. However, the end of the connection is still waiting for the connection to be established indefinitely...

    @Override    public void channelActive(ChannelHandlerContext ctx) throws Exception {        xxxx;    }

After the code is changed to the above normal code, the function returns to normal, and the connection can be established normally...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.