move listen addr to server bean
This commit is contained in:
@@ -8,6 +8,4 @@ public interface Config {
|
|||||||
int getMaxPlayers();
|
int getMaxPlayers();
|
||||||
String getDescriptionServer();
|
String getDescriptionServer();
|
||||||
byte[] getFaviconBase64();
|
byte[] getFaviconBase64();
|
||||||
String getHost();
|
|
||||||
int getPort();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring.xml");
|
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring.xml");
|
||||||
Config config = appContext.getBean("config", Config.class);
|
|
||||||
|
|
||||||
Server server = appContext.getBean("server", Server.class);
|
Server server = appContext.getBean("server", Server.class);
|
||||||
try {
|
try {
|
||||||
server.start(config.getHost(), config.getPort());
|
server.start();
|
||||||
} catch (StartServerException e) {
|
} catch (StartServerException e) {
|
||||||
log.error("Can't start server", e);
|
log.error("Can't start server", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ public class ConfigFromSpring implements Config {
|
|||||||
private byte[] faviconBase64;
|
private byte[] faviconBase64;
|
||||||
@Setter
|
@Setter
|
||||||
private int maxPlayers;
|
private int maxPlayers;
|
||||||
@Setter
|
|
||||||
private String host;
|
|
||||||
@Setter
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
public void setFaviconBase64(File faviconImageFile) {
|
public void setFaviconBase64(File faviconImageFile) {
|
||||||
log.debug("faviconImageFile: {}", faviconImageFile.getAbsolutePath());
|
log.debug("faviconImageFile: {}", faviconImageFile.getAbsolutePath());
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
package mc.core.network;
|
package mc.core.network;
|
||||||
|
|
||||||
public interface Server {
|
public interface Server {
|
||||||
void start(String host, int port) throws StartServerException;
|
void start() throws StartServerException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ import java.util.Map;
|
|||||||
public class NettyServer implements Server {
|
public class NettyServer implements Server {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
@Setter
|
||||||
|
private String host;
|
||||||
|
@Setter
|
||||||
|
private int port;
|
||||||
|
@Setter
|
||||||
|
private int workerGroupCount = 0;
|
||||||
private EventLoopGroup bossGroup, workerGroup;
|
private EventLoopGroup bossGroup, workerGroup;
|
||||||
|
|
||||||
private ChannelInitializer buildChannelInitializer() {
|
private ChannelInitializer buildChannelInitializer() {
|
||||||
@@ -52,13 +58,14 @@ public class NettyServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(String host, int port) throws StartServerException {
|
public void start() throws StartServerException {
|
||||||
log.info("Use protocol 1.2.5");
|
log.info("Use protocol 1.2.5");
|
||||||
bossGroup = new NioEventLoopGroup(1);
|
bossGroup = new NioEventLoopGroup(1);
|
||||||
workerGroup = new NioEventLoopGroup(); //TODO сделать изменяемым
|
workerGroup = new NioEventLoopGroup(workerGroupCount);
|
||||||
|
|
||||||
ServerBootstrap serverBootstrap = buildServerBootstrap();
|
ServerBootstrap serverBootstrap = buildServerBootstrap();
|
||||||
|
|
||||||
|
log.info("Start server: {}:{}", host, port);
|
||||||
try {
|
try {
|
||||||
serverBootstrap.bind(host, port).sync().channel().closeFuture().sync();
|
serverBootstrap.bind(host, port).sync().channel().closeFuture().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|||||||
@@ -9,15 +9,17 @@
|
|||||||
<property name="descriptionServer" value="MC Core"/>
|
<property name="descriptionServer" value="MC Core"/>
|
||||||
<property name="maxPlayers" value="100"/>
|
<property name="maxPlayers" value="100"/>
|
||||||
<property name="faviconBase64" value="icon.png"/>
|
<property name="faviconBase64" value="icon.png"/>
|
||||||
<property name="host" value="127.0.0.1"/>
|
|
||||||
<property name="port" value="25565"/>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Netty Server -->
|
<!-- 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.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.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="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>
|
</beans>
|
||||||
Reference in New Issue
Block a user