Moved EventLoopGroup shutdown to Application#dispose

This commit is contained in:
Collin Smith 2020-06-24 21:48:36 -07:00
parent 3dc8136462
commit 398f034755
4 changed files with 32 additions and 15 deletions

View File

@ -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...");

View File

@ -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...");

View File

@ -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<SocketChannel>() {
@ -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...");

View File

@ -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...");