Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netty: stop reconnecting and shutdown

Tags:

java

netty

I plan to modify Netty UptimeClient (see here). The original version is designed to run endlessly: it reconnects to the host in case of disconnection. I'd like to add a 'terminate' method in UptimeClient.java. The method would disconnect or stop the reconnection process from an outside thread, shutdown Netty gracefully, and return.

Since the client channel can change because of the reconnection process, would it be safe to keep all channels returned by 'bootstrap.connect()' in a ChannelGroup, and call 'close' using the group before releasing Netty's resources?

How would you implement a 'terminate' method? (edit: using 3.7.0)

like image 564
Frank Ross Avatar asked Dec 02 '25 05:12

Frank Ross


1 Answers

In Nety 4.0, you can just call shutdownGracefully(...) on the EventLoopGroup that manages all your channels. Then all existing channels will be closed automatically and the reconnection attempt should be rejected. Please feel free to file an issue if this doesn't work.

If you are using Netty 3.x, unfortunately, there's no automatic mechanism for this. You have to ensure to close all channels, because the event loop will not terminate itself until it has a channel to manage. For more information, please refer to NioClientChannelFactory ('Life cycle of threads and graceful shutdown')

like image 109
trustin Avatar answered Dec 03 '25 17:12

trustin