RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.service.NetworkService Class Reference

The bootstrap that will prepare the game and net. More...

Public Member Functions

void start (int port) throws Exception

Static Private Attributes

static final Logger logger = LogManager.getLogger(NetworkService.class)

Detailed Description

The bootstrap that will prepare the game and net.

Author
Seven

Definition at line 27 of file NetworkService.java.

Member Function Documentation

◆ start()

void com.runehive.game.service.NetworkService.start ( int port) throws Exception

Definition at line 31 of file NetworkService.java.

31 {
32 logger.info("Starting network service on port: " + port);
33
34 ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
35 final EventLoopGroup bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1);
36 final EventLoopGroup workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
37
38 try {
39 ServerBootstrap b = new ServerBootstrap();
40 b.group(bossGroup, workerGroup)
41 .channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
42 .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
43 .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
44 .childOption(ChannelOption.TCP_NODELAY, true)
45 .childOption(ChannelOption.AUTO_READ, true)
46 .childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(2 << 16, 2 << 18))
47 .childOption(ChannelOption.SO_SNDBUF, 65536)
48 .childOption(ChannelOption.SO_RCVBUF, 65536)
49 .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30_000)
50 .childOption(ChannelOption.IP_TOS, Config.IP_TOS)
51 .childHandler(new ServerPipelineInitializer());
52
53 ChannelFuture f = b.bind(port).syncUninterruptibly();
54
55 RuneHive.serverStarted.set(true);
56
57 logger.info(String.format("Server built successfully (took %d seconds).", RuneHive.UPTIME.elapsedTime(TimeUnit.SECONDS)));
58 RuneHive.UPTIME.reset();
59 f.channel().closeFuture().sync();
60 } catch (Exception ex) {
61 logger.error("error starting network service.", ex);
62 } finally {
63 bossGroup.shutdownGracefully();
64 workerGroup.shutdownGracefully();
65 }
66 }

References com.runehive.util.Stopwatch.elapsedTime(), com.runehive.Config.IP_TOS, logger, com.runehive.util.Stopwatch.reset(), com.runehive.RuneHive.serverStarted, and com.runehive.RuneHive.UPTIME.

Here is the call graph for this function:

Member Data Documentation

◆ logger

final Logger com.runehive.game.service.NetworkService.logger = LogManager.getLogger(NetworkService.class)
staticprivate

Definition at line 29 of file NetworkService.java.

Referenced by start().


The documentation for this class was generated from the following file: