将 LiveClient 中的 ConnectionClose 监听器变为内部类以防止外部直接调用

This commit is contained in:
czp 2018-02-09 09:32:25 +08:00
parent 7f2947ad8a
commit 803290932d

View File

@ -39,6 +39,10 @@ public class LiveClient implements Closeable {
private EventLoopGroup eventLoopGroup;
private Channel channel;
private void initEventBus() {
eventBus.register(new ConnectionCloseListener());
}
public LiveClient(BilibiliServiceProvider bilibiliServiceProvider, long showRoomId) {
this.bilibiliServiceProvider = bilibiliServiceProvider;
this.showRoomId = showRoomId;
@ -53,10 +57,6 @@ public class LiveClient implements Closeable {
initEventBus();
}
private void initEventBus() {
eventBus.register(this);
}
public synchronized LiveClient connect() throws IOException {
if (channel != null && channel.isActive()) {
LOGGER.warn("Already connected to server, connect method can not be invoked twice");
@ -130,9 +130,11 @@ public class LiveClient implements Closeable {
}
}
@Subscribe
public void onConnectionClose(ConnectionCloseEvent connectionCloseEvent) {
eventLoopGroup.shutdownGracefully();
private class ConnectionCloseListener {
@Subscribe
public void onConnectionClose(ConnectionCloseEvent connectionCloseEvent) {
eventLoopGroup.shutdownGracefully();
}
}
public EventBus getEventBus() {