网络模块关闭修改
parent
647391a628
commit
1fd6cf3102
|
@ -9,7 +9,14 @@ import io.netty.handler.timeout.IdleState;
|
|||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* netty pipeline职责链中的一个普通io事件拦截器
|
||||
* 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());
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Description: 网络模块统一处理接口
|
||||
* 说有的child chnnel回调到此服务端处理类中 、
|
||||
* 部分功能根据业务传进来handler 回调给业务
|
||||
* 部分功能传递给gamesession再回调给业务
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.ljsd.jieling.session;
|
||||
|
||||
/**
|
||||
* 业务实现链接保持 网络模块抽象
|
||||
*/
|
||||
public interface GameSession {
|
||||
|
||||
void open();
|
||||
|
|
Loading…
Reference in New Issue