public class ServerCoreHandler
extends java.lang.Object
本类是MobileIMSDK的服务端网络调度算法核心所在,其性能将决定整个 即时通讯架构的数据交换性能、负载能力、吞吐效率等。
LogicProcessor,
BridgeProcessor,
OnlineProcessor| 限定符和类型 | 字段和说明 |
|---|---|
protected BridgeProcessor |
bridgeProcessor
跨机器通信中间件服务提供者.
|
protected LogicProcessor |
logicProcessor
IM消息逻辑处理器(真正的算法实现都在此类中处理).
|
protected ServerEventListener |
serverEventListener
服务端事件回调实现
|
protected MessageQoSEventListenerS2C |
serverMessageQoSEventListener
QoS机制下的S2C模式中,由服务端主动发起消息的QoS事件回调实现
|
| 构造器和说明 |
|---|
ServerCoreHandler()
构造方法。
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected BridgeProcessor |
createBridgeProcessor()
新建跨机器通信消息中间件服务提供者。
|
protected LogicProcessor |
createLogicProcessor()
创建MobileIMSDK框架核心层的数据交互处理逻辑封装对象。
|
void |
exceptionCaught(io.netty.channel.Channel session,
java.lang.Throwable cause)
异常回调方法。
|
BridgeProcessor |
getBridgeProcessor()
获得本类对应的BridgeProcessor对象引用。
|
ServerEventListener |
getServerEventListener() |
MessageQoSEventListenerS2C |
getServerMessageQoSEventListener() |
void |
lazyStartupBridgeProcessor()
单独的方法启动跨服务器通信桥接处理器,防止出现交叉引用而发生不可预知的错误。
|
void |
messageReceived(io.netty.channel.Channel session,
Protocal pFromClient)
框架中收到客户端消息的回调方法。
|
void |
sessionClosed(io.netty.channel.Channel session)
框架中,当用户的会话被关闭时将调本本方法。
|
void |
sessionCreated(io.netty.channel.Channel session)
当与客户的会话建立时本方法回调用。
|
protected ServerEventListener serverEventListener
protected MessageQoSEventListenerS2C serverMessageQoSEventListener
protected LogicProcessor logicProcessor
protected BridgeProcessor bridgeProcessor
protected LogicProcessor createLogicProcessor()
子类可继承本方法实现自已的逻辑,但在您没有完全掌握MobileIMSDK算法前不建议这样做。
LogicProcessorprotected BridgeProcessor createBridgeProcessor()
子类可继承本方法实现自已的逻辑,但在您没有完全掌握MobileIMSDK算法前不建议这样做。
BridgeProcessorpublic void lazyStartupBridgeProcessor()
本方法的目前在 ServerLauncher.startup()中被调用,从而启动与Web的消息互通桥接器。
本方法只在 ServerLauncher.bridgeEnabled == true时才会真实启动桥接处理器。
public void exceptionCaught(io.netty.channel.Channel session,
java.lang.Throwable cause)
throws java.lang.Exception
本类中将在异常发生时,立即close当前会话。
本方法将被 MBTCPClientInboundHandler.exceptionCaught(
io.netty.channel.ChannelHandlerContext, Throwable)调用,以便接受Netty中客户端
“会话”处理过程中发生的异常。
session - 发生异常的会话cause - 异常内容java.lang.Exceptionio.netty.channel.Channel#close(boolean),
MBTCPClientInboundHandler.exceptionCaught(io.netty.channel.ChannelHandlerContext, Throwable)public void messageReceived(io.netty.channel.Channel session,
Protocal pFromClient)
throws java.lang.Exception
本类将在此方法中实现完整的即时通讯数据交互和处理策略, 本方法是整个MobileIMSDK服务端的核心所在。
本方法将被 MBTCPClientInboundHandler.channelRead0(
io.netty.channel.ChannelHandlerContext, ByteBuf)调用,以便接受Netty中客户端
发送的数据。
session - 收到消息对应的会话引用pFromClient - 读取到的数据内容(已被转换成Protocal对象)java.lang.Exception - 当有错误发生时将抛出异常LogicProcessor,
MBTCPClientInboundHandler.channelRead0(io.netty.channel.ChannelHandlerContext, ByteBuf)public void sessionClosed(io.netty.channel.Channel session)
throws java.lang.Exception
本方法中会将此用户从在线列表及相关队列中移除,将通过回调通知上层代码(由 上层代码接力实现自定义的其它业务处理)。
会话被关闭的可能性有3种:
本方法将被 MBTCPClientInboundHandler.channelInactive(
io.netty.channel.ChannelHandlerContext)调用,以便接受Netty中客户端“会话”断开通知。
session - 被关闭的会话Channel引用java.lang.Exception - 任何错误发生时将抛出本异常OnlineProcessor.removeUser(String),
ServerEventListener.onUserLogout(String, Channel, int),
MBTCPClientInboundHandler.channelInactive(io.netty.channel.ChannelHandlerContext)public void sessionCreated(io.netty.channel.Channel session)
throws java.lang.Exception
默认情况下,本方法什么也没做。
本方法将被 MBTCPClientInboundHandler.channelActive(
io.netty.channel.ChannelHandlerContext)调用,以便接受Netty中客户端“会话”建立通知。
session - 建立的Netty"会话"对象引用java.lang.ExceptionMBTCPClientInboundHandler.channelActive(io.netty.channel.ChannelHandlerContext)public ServerEventListener getServerEventListener()
public MessageQoSEventListenerS2C getServerMessageQoSEventListener()
public BridgeProcessor getBridgeProcessor()
BridgeProcessor