Implementation features
Start Netty, follow the user-configured listener to listen for the port, accept the link sent by the client
Implementation steps
1. Start Netty
2, through the Listenerconfigurationservice to obtain the user's listener configuration, the corresponding configuration is bound to Netty.
Class diagram
This UML familiar with Netty's friends should look very clear, down we post a few pieces of code, to see how hivemq is bound.
PublicListenablefuture<list<listenerstartresult>>startlisteners() {//For Netty registration shutdown, in order to enable the Netty main thread in the shutdown, can shut down the worker and boss This. Shutdownregistry.register (NewNettyshutdown ( This. Childeventloop, This. Parenteventloop, This. Hivemqconfigurationservice.internalconfiguration (). GetInt (Internals.event_loop_group_shutdown_timeout));//Record the future list of the results of the listener startup to facilitate printing the results of listener bindings in the Log/console. List<listenerstartfuture> startfutures =NewArraylist<> ();//If the user does not configure listener, a binding to 1883 port will be added by default TcpListenerAdddefaultlistenerwhenlistenersisempty ();//obtained from user Configuration to tcplisteners bound to NettyStartfutures.addall (Starttcplisteners ( This. Listenerconfigurationservice.gettcplisteners ()));//obtained from user Configuration to tlstcplisteners bound to NettyStartfutures.addall (Starttlstcplisteners ( This. Listenerconfigurationservice.gettlstcplisteners ()));//obtained from user Configuration to websocketlisteners bound to NettyStartfutures.addall (Startwebsocketlisteners ( This. Listenerconfigurationservice.getwebsocketlisteners ()));//obtained from user Configuration to tlswebsocketlisteners bound to NettyStartfutures.addall (Starttlswebsocketlisteners ( This. Listenerconfigurationservice.gettlswebsocketlisteners ()));//Convert a bunch of startup future into a future that makes the caller (Hivemqserver) easy to use. returnGetstartresult (Startfutures); }
By the above process can be known, the specific code processing process
1, by Hivemqserver, call Nettyserver start, start Netty.
2. Then call Startlisteners, bind the configured listeners to Netty
MQTT Exchange Group: 221405150
MQTT---hivemq source details (v) netty-Startup and listeners loading