网络模块关闭修改

back_recharge
zhangshanxue 2019-12-17 11:13:25 +08:00
parent 647391a628
commit 1fd6cf3102
6 changed files with 35 additions and 14 deletions

View File

@ -9,7 +9,14 @@ import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.concurrent.GlobalEventExecutor;
//
/**
* netty pipelineio
* TODO SimpleChannelInboundHandler
* Description: des
* change: 2019/11/21 14:51
*/
public class GameMessageHandler extends SimpleChannelInboundHandler<Object> {
public static ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
@ -39,6 +46,7 @@ public class GameMessageHandler extends SimpleChannelInboundHandler<Object> {
//protocols.offLine(this.session);
try {
NettyChannel channel = NettyChannel.getOrAddChannel(ctx.channel());
this.handler.disconnected(channel);
} finally {
NettyChannel.removeChannelIfDisconnected(ctx.channel());

View File

@ -5,7 +5,8 @@ import com.ljsd.jieling.netty.handler.ChannelHandler;
import com.ljsd.jieling.protocol.INetWorkHandler;
/**
* Description: channel
* Description:
* channel
* Author: zsx
* CreateDate: 2019/11/7 10:24
*/

View File

@ -14,7 +14,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Description: des
* Description:
* child chnnel
* handler
* gamesession

View File

@ -11,9 +11,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Description: channel session channel
* Description:
* channel session channel
*
*
*
* Author: zsx
* CreateDate: 2019/11/20 16:51
*/

View File

@ -114,18 +114,25 @@ public class NettyGameServer extends AbstractServer {
} catch (Throwable var) {
LOGGER.error("close channel exception" + var, getLocalAddress());
}
//关闭所有NettyChannel
//关闭所有NettyChannel 流程改为了
// workerGroup.shutdownGracefully().sync();
// ->> GameMessageHandler.channelInactive()
// ->> AbstractServer.disconnected(NettyChannel)
// ->> network.disconnected(gamesession)
// ->> gameSession.close()(role offline)
// ->> NettyChannel.close();
// ->> chanel.close();
try {
Collection<NettyChannel> channels = NettyChannel.getChannelMap().values();
if (channels.size() > 0) {
for (NettyChannel channel : channels) {
try {
channel.close();
} catch (Throwable var1) {
LOGGER.error("close NettyChannel exception" + var1, channel.getRemoteAddress());
}
}
}
// Collection<NettyChannel> channels = NettyChannel.getChannelMap().values();
// if (channels.size() > 0) {
// for (NettyChannel channel : channels) {
// try {
// channel.close();
// } catch (Throwable var1) {
// LOGGER.error("close NettyChannel exception" + var1, channel.getRemoteAddress());
// }
// }
// }
} catch (Throwable var2) {
LOGGER.error("close NettyChannel exception" + var2);
}

View File

@ -1,5 +1,8 @@
package com.ljsd.jieling.session;
/**
*
*/
public interface GameSession {
void open();