Openfire源码分析----消息处理流程
2014-12-24 16:03
441 查看
众所周知Openfire是基于mina编写的。因此直接找到ConnectionHandler,这个类继承IoHandlerAdapter。
熟悉mina的会知道接受消息并处理的方法为messageReceived。我们也只关心这个方法:
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
// Get the stanza handler for this session
StanzaHandler handler = (StanzaHandler) session.getAttribute(HANDLER);
// Get the parser to use to process stanza. For optimization there is going
// to be a parser for each running thread. Each Filter will be executed
// by the Executor placed as the first Filter. So we can have a parser associated
// to each Thread
int hashCode = Thread.currentThread().hashCode();
XMPPPacketReader parser = parsers.get(hashCode);
if (parser == null) {
parser = new XMPPPacketReader();
parsers.put(hashCode, parser);
}
// Update counter of read btyes
updateReadBytesCounter(session);
//System.out.println("RCVD: " + message);
// Let the stanza handler process the received stanza
try {
handler.process((String) message, parser);
} catch (Exception e) {
Log.error("Closing connection due to error while processing message: " + message, e);
Connection connection = (Connection) session.getAttribute(CONNECTION);
connection.close();
}
}
这个方法会调用StanzaHandler的process进行消息路由。
判断是否为权限包、消息包、状态包或者IQ包。对不同的包分发路由进行不同的处理。
熟悉mina的会知道接受消息并处理的方法为messageReceived。我们也只关心这个方法:
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
// Get the stanza handler for this session
StanzaHandler handler = (StanzaHandler) session.getAttribute(HANDLER);
// Get the parser to use to process stanza. For optimization there is going
// to be a parser for each running thread. Each Filter will be executed
// by the Executor placed as the first Filter. So we can have a parser associated
// to each Thread
int hashCode = Thread.currentThread().hashCode();
XMPPPacketReader parser = parsers.get(hashCode);
if (parser == null) {
parser = new XMPPPacketReader();
parsers.put(hashCode, parser);
}
// Update counter of read btyes
updateReadBytesCounter(session);
//System.out.println("RCVD: " + message);
// Let the stanza handler process the received stanza
try {
handler.process((String) message, parser);
} catch (Exception e) {
Log.error("Closing connection due to error while processing message: " + message, e);
Connection connection = (Connection) session.getAttribute(CONNECTION);
connection.close();
}
}
这个方法会调用StanzaHandler的process进行消息路由。
判断是否为权限包、消息包、状态包或者IQ包。对不同的包分发路由进行不同的处理。
相关文章推荐
- 第二人生的源码分析(三十七)消息处理的完整流程
- 蔡军生先生第二人生的源码分析(三十七)消息处理的完整流程
- 第二人生的源码分析(三十七)消息处理的完整流程
- 第二人生的源码分析(三十七)消息处理的完整流程
- 小伙伴们的ceph源码分析三——monitor消息处理流程
- Struts2源码粗略分析三:请求处理流程分析
- XMPP协议学习笔记五(Openfire消息处理流程)
- (转)TOMCAT源码分析(消息处理)
- TOMCAT源码分析(消息处理)
- TOMCAT源码分析(消息处理)
- apache(httpd-2.2.14) mod_ssl源码分析之二(mod_ssl处理流程分析)
- 蔡军生先生第二人生的源码分析(二十三)人物行走的键盘消息处理
- TOMCAT源码分析(消息处理)
- TOMCAT源码分析(消息处理)
- 第二人生的源码分析(二十四)人物向前走的键盘消息处理
- 第二人生的源码分析(二十四)人物向前走的键盘消息处理
- 第二人生的源码分析(二十三)人物行走的键盘消息处理
- 第二人生的源码分析(四十二)实现消息处理的线程类
- 第二人生的源码分析(四十二)实现消息处理的线程类
- TOMCAT源码分析(消息处理)