public byte [ ] generateGossipHello ( ) { if ( cachedHelloMessage != null ) { return cachedHelloMessage ; } try { FastBuildTree root = new FastBuildTree ( 4 ) ; root . putUnsafe ( "ver" , ServiceBroker . PROTOCOL_VERSION ) ; root . putUnsafe ( "sender" , nodeID ) ; if ( useHostname ) { root . putUnsafe ( "host" , getHostName ( ) ) ; } else { root . putUnsafe ( "host" , InetAddress . getLocalHost ( ) . getHostAddress ( ) ) ; } root . putUnsafe ( "port" , reader . getCurrentPort ( ) ) ; cachedHelloMessage = serialize ( PACKET_GOSSIP_HELLO_ID , root ) ; } catch ( Exception error ) { throw new MoleculerError ( "Unable to create HELLO message!" , error , "MoleculerError" , "unknown" , false , 500 , "UNABLE_TO_CREATE_HELLO" ) ; } return cachedHelloMessage ; }
Create Gossip HELLO packet . Hello message is invariable so we can cache it .