diff --git a/src/main/java/mc/core/Config.java b/src/main/java/mc/core/Config.java index 247c2e0..9e67fdc 100644 --- a/src/main/java/mc/core/Config.java +++ b/src/main/java/mc/core/Config.java @@ -8,6 +8,4 @@ public interface Config { int getMaxPlayers(); String getDescriptionServer(); byte[] getFaviconBase64(); - String getHost(); - int getPort(); } diff --git a/src/main/java/mc/core/Main.java b/src/main/java/mc/core/Main.java index b1d58d5..bedc0b6 100644 --- a/src/main/java/mc/core/Main.java +++ b/src/main/java/mc/core/Main.java @@ -14,11 +14,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { ApplicationContext appContext = new ClassPathXmlApplicationContext("spring.xml"); - Config config = appContext.getBean("config", Config.class); - Server server = appContext.getBean("server", Server.class); try { - server.start(config.getHost(), config.getPort()); + server.start(); } catch (StartServerException e) { log.error("Can't start server", e); } diff --git a/src/main/java/mc/core/embedded/ConfigFromSpring.java b/src/main/java/mc/core/embedded/ConfigFromSpring.java index 215f77a..86680f8 100644 --- a/src/main/java/mc/core/embedded/ConfigFromSpring.java +++ b/src/main/java/mc/core/embedded/ConfigFromSpring.java @@ -22,10 +22,6 @@ public class ConfigFromSpring implements Config { private byte[] faviconBase64; @Setter private int maxPlayers; - @Setter - private String host; - @Setter - private int port; public void setFaviconBase64(File faviconImageFile) { log.debug("faviconImageFile: {}", faviconImageFile.getAbsolutePath()); diff --git a/src/main/java/mc/core/network/Server.java b/src/main/java/mc/core/network/Server.java index c02aae9..210a6b4 100644 --- a/src/main/java/mc/core/network/Server.java +++ b/src/main/java/mc/core/network/Server.java @@ -5,5 +5,5 @@ package mc.core.network; public interface Server { - void start(String host, int port) throws StartServerException; + void start() throws StartServerException; } diff --git a/src/main/java/mc/core/network/proto_125/netty/NettyServer.java b/src/main/java/mc/core/network/proto_125/netty/NettyServer.java index 852f7c5..d7bb55c 100644 --- a/src/main/java/mc/core/network/proto_125/netty/NettyServer.java +++ b/src/main/java/mc/core/network/proto_125/netty/NettyServer.java @@ -29,6 +29,12 @@ import java.util.Map; public class NettyServer implements Server { @Autowired private ApplicationContext applicationContext; + @Setter + private String host; + @Setter + private int port; + @Setter + private int workerGroupCount = 0; private EventLoopGroup bossGroup, workerGroup; private ChannelInitializer buildChannelInitializer() { @@ -52,13 +58,14 @@ public class NettyServer implements Server { } @Override - public void start(String host, int port) throws StartServerException { + public void start() throws StartServerException { log.info("Use protocol 1.2.5"); bossGroup = new NioEventLoopGroup(1); - workerGroup = new NioEventLoopGroup(); //TODO сделать изменяемым + workerGroup = new NioEventLoopGroup(workerGroupCount); ServerBootstrap serverBootstrap = buildServerBootstrap(); + log.info("Start server: {}:{}", host, port); try { serverBootstrap.bind(host, port).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { diff --git a/src/main/resources/spring.xml b/src/main/resources/spring.xml index 0d9cd11..70e4422 100644 --- a/src/main/resources/spring.xml +++ b/src/main/resources/spring.xml @@ -9,15 +9,17 @@ - - - + - + + + + + \ No newline at end of file