package Ġorg . gob lin framework . transport . server . channel Ċ Ċ import Ġio . netty . bootstrap . Server Bootstrap Ċ import Ġio . netty . channel . Channel Initializer Ċ import Ġio . netty . channel . nio . Nio EventLoop Group Ċ import Ġio . netty . channel . socket . SocketChannel Ċ import Ġio . netty . channel . socket . nio . Nio Server SocketChannel Ċ import Ġio . netty . handler . logging . LogLevel Ċ import Ġio . netty . handler . logging . Logging Handler Ċ import Ġorg . gob lin framework . api . function . Disposable Ċ import Ġorg . gob lin framework . core . util . Network Utils Ċ import Ġorg . gob lin framework . transport . codec . Transport Message Decoder Ċ import Ġorg . gob lin framework . transport . codec . Transport Message Encoder Ċ import Ġorg . gob lin framework . transport . server . setting . Transport Server Setting Ċ import Ġjava . net . Inet SocketAddress Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ class ĠTransport Server Impl ( val Ġsetting : ĠTransport Server Setting ) Ġ: ĠDis posable Ġ{ ĊĊĠ Ġprivate Ġval Ġboss : ĠN io EventLoop Group ĊĠ Ġprivate Ġval Ġworker : ĠN io EventLoop Group ĊĠ Ġinternal Ġval Ġchannel Manager : ĠTransport Server Channel Manager ĊĠ Ġinternal Ġval Ġhost : ĠString ĊĠ Ġinternal Ġval Ġport : ĠInt ĊĊĠ Ġinit Ġ{ ĊĠĠĠ Ġval Ġsocket Address Ġ= ĠInet SocketAddress ( setting . host (), Ġsetting . port ()) ĊĊĠĠĠ Ġboss Ġ= ĠN io EventLoop Group ( setting . thread Pool Setting (). boss Threads ()) ĊĠĠĠ Ġworker Ġ= ĠN io EventLoop Group ( setting . thread Pool Setting (). worker Threads ()) ĊĊĠĠĠ Ġchannel Manager Ġ= ĠTransport Server Channel Manager ( this ) ĊĊĠĠĠ Ġval Ġbootstrap Ġ= ĠServer Bootstrap () ĊĠĠĠĠĠĠĠ Ġ. group ( boss , Ġworker ) ĊĠĠĠĠĠĠĠ Ġ. channel ( Nio Server SocketChannel :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. local Address ( socket Address ) ĊĠĠĠ Ġval Ġinitializer : ĠChannel Initializer < SocketChannel > Ġ= Ġobject Ġ: ĠChannel Initializer < SocketChannel >() Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġinit Channel ( ch : ĠSocket Channel ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpipeline Ġ= Ġch . pipeline () ĊĠĠĠĠĠĠĠ Ġif Ġ( setting . debug Mode ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġpipeline . add Last ( Logging Handler ( LogLevel . DEBUG )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġpipeline . add Last (" encoder ", ĠTransport Message Encoder . getInstance ()) ĊĠĠĠĠĠĠĠ Ġpipeline . add Last (" decoder ", ĠTransport Message Decoder . newInstance ()) ĊĠĠĠĠĠĠĠ Ġpipeline . add Last ( Transport Server Channel Handler ( channel Manager )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġbootstrap . child Handler ( initializer ) ĊĠĠĠ Ġval Ġchannel Ġ= Ġbootstrap . bind (). sync (). channel () ĊĠĠĠ Ġvar Ġh Ġ= Ġ( channel . local Address () Ġas ĠInet SocketAddress ). address . host Address ĊĠĠĠ Ġif Ġ( h Ġ== Ġ" 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 ") Ġ{ ĊĠĠĠĠĠ Ġh Ġ= ĠNetwork Utils . ALL _ HOST ĊĠĠĠ Ġ} ĊĠĠĠ Ġhost Ġ= Ġh ĊĠĠĠ Ġport Ġ= Ġ( channel . local Address () Ġas ĠInet SocketAddress ). port ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġdispose () Ġ{ ĊĠĠĠ Ġchannel Manager . terminate () ĊĠĠĠ Ġchannel Manager . await Termination ( 1 5 , ĠTimeUnit . SECONDS ) ĊĠĠĠ Ġchannel Manager . dispose () ĊĠĠĠ Ġboss . shutdown Grace fully (). await Un interrupt ibly () ĊĠĠĠ Ġworker . shutdown Grace fully (). await Un interrupt ibly () ĊĠ Ġ} Ċ }