Archived
0

move listen addr to server bean

This commit is contained in:
2018-04-15 09:59:54 +03:00
parent db97d7d446
commit ac167609cf
6 changed files with 17 additions and 16 deletions

View File

@@ -8,6 +8,4 @@ public interface Config {
int getMaxPlayers();
String getDescriptionServer();
byte[] getFaviconBase64();
String getHost();
int getPort();
}

View File

@@ -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);
}

View File

@@ -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());

View File

@@ -5,5 +5,5 @@
package mc.core.network;
public interface Server {
void start(String host, int port) throws StartServerException;
void start() throws StartServerException;
}

View File

@@ -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) {

View File

@@ -9,15 +9,17 @@
<property name="descriptionServer" value="MC Core"/>
<property name="maxPlayers" value="100"/>
<property name="faviconBase64" value="icon.png"/>
<property name="host" value="127.0.0.1"/>
<property name="port" value="25565"/>
</bean>
<!-- Netty Server -->
<!--<bean id="pipeline.log" class="io.netty.handler.logging.LoggingHandler" scope="prototype"/>-->
<bean id="pipeline.log" class="io.netty.handler.logging.LoggingHandler" scope="prototype"/>
<bean id="pipeline.decoder" class="mc.core.network.proto_125.netty.PacketDecoder" scope="prototype"/>
<bean id="pipeline.encoder" class="mc.core.network.proto_125.netty.PacketEncoder" scope="prototype"/>
<bean id="pipeline.handler" class="mc.core.network.proto_125.netty.PacketHandler" scope="prototype"/>
<bean id="server" class="mc.core.network.proto_125.netty.NettyServer"/>
<bean id="server" class="mc.core.network.proto_125.netty.NettyServer">
<property name="host" value="127.0.0.1"/>
<property name="port" value="25565"/>
<!--<property name="workerGroupCount" value="8"/>-->
</bean>
</beans>