diff --git a/server/netty/src/com/riiablo/net/reliable/TestClient.java b/server/netty/src/com/riiablo/net/reliable/TestClient.java index e02ebec7..1d8edbb3 100644 --- a/server/netty/src/com/riiablo/net/reliable/TestClient.java +++ b/server/netty/src/com/riiablo/net/reliable/TestClient.java @@ -38,12 +38,13 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { } private Endpoint endpoint; + private EventLoopGroup group; @Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); - EventLoopGroup group = new NioEventLoopGroup(); + group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap() .group(group) @@ -64,8 +65,6 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); Gdx.app.exit(); - } finally { - group.shutdownGracefully(); } } @@ -87,6 +86,11 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { endpoint.update(Gdx.graphics.getDeltaTime()); } + @Override + public void dispose() { + if (!group.isShuttingDown()) group.shutdownGracefully(); + } + @Override public void processPacket(ByteBuf bb) { Gdx.app.debug(TAG, "Processing packet..."); diff --git a/server/netty/src/com/riiablo/net/reliable/TestServer.java b/server/netty/src/com/riiablo/net/reliable/TestServer.java index 77ae5944..38040178 100644 --- a/server/netty/src/com/riiablo/net/reliable/TestServer.java +++ b/server/netty/src/com/riiablo/net/reliable/TestServer.java @@ -38,12 +38,13 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor { } private Endpoint endpoint; + private EventLoopGroup group; @Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); - EventLoopGroup group = new NioEventLoopGroup(); + group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap() .group(group) @@ -65,8 +66,6 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor { } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); Gdx.app.exit(); - } finally { - group.shutdownGracefully(); } } @@ -75,6 +74,11 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor { endpoint.update(Gdx.graphics.getDeltaTime()); } + @Override + public void dispose() { + if (!group.isShuttingDown()) group.shutdownGracefully(); + } + @Override public void processPacket(ByteBuf bb) { Gdx.app.debug(TAG, "Processing packet..."); diff --git a/server/netty/src/com/riiablo/net/tcp/TestClient.java b/server/netty/src/com/riiablo/net/tcp/TestClient.java index 7a5c2800..898b6081 100644 --- a/server/netty/src/com/riiablo/net/tcp/TestClient.java +++ b/server/netty/src/com/riiablo/net/tcp/TestClient.java @@ -39,15 +39,16 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { } private Endpoint endpoint; + private EventLoopGroup group; @Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap() - .group(workerGroup) + .group(group) .channel(NioSocketChannel.class) .option(ChannelOption.SO_KEEPALIVE, true) .handler(new ChannelInitializer() { @@ -66,8 +67,6 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); Gdx.app.exit(); - } finally { - workerGroup.shutdownGracefully(); } } @@ -89,6 +88,11 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { endpoint.update(Gdx.graphics.getDeltaTime()); } + @Override + public void dispose() { + if (!group.isShuttingDown()) group.shutdownGracefully(); + } + @Override public void processPacket(ByteBuf bb) { Gdx.app.debug(TAG, "Processing packet..."); diff --git a/server/netty/src/com/riiablo/net/tcp/TestServer.java b/server/netty/src/com/riiablo/net/tcp/TestServer.java index 62df357f..104cdb61 100644 --- a/server/netty/src/com/riiablo/net/tcp/TestServer.java +++ b/server/netty/src/com/riiablo/net/tcp/TestServer.java @@ -34,13 +34,15 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor { } private Endpoint endpoint; + private EventLoopGroup bossGroup; + private EventLoopGroup workerGroup; @Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); - EventLoopGroup bossGroup = new NioEventLoopGroup(); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + bossGroup = new NioEventLoopGroup(); + workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap() .group(bossGroup, workerGroup) @@ -63,9 +65,6 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor { } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); Gdx.app.exit(); - } finally { - workerGroup.shutdownGracefully(); - bossGroup.shutdownGracefully(); } } @@ -74,6 +73,12 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor { endpoint.update(Gdx.graphics.getDeltaTime()); } + @Override + public void dispose() { + if (!workerGroup.isShuttingDown()) workerGroup.shutdownGracefully(); + if (!bossGroup.isShuttingDown()) bossGroup.shutdownGracefully(); + } + @Override public void processPacket(ByteBuf bb) { Gdx.app.debug(TAG, "Processing packet...");