XMPP协议学习笔记四(Openfire服务器启动过程)

 

XMPP协议学习笔记四(Openfire服务器启动过程)

在上篇文章中我们成功部署了openfire的源码,这一篇我们来初步了解一下openfire的项目结构。
  • 概述

    Openfire最主要的功能是实现XMPP服务器,简单来说,openfire为我们提供一个固定的地址,我们只需要向openfire服务器发送标准的XMPP信息(即XML文件流),那么openfire服务器应当给予我们回应,这里的openfire服务器也可以看做一个容器,我们在聊天时,需要在这个服务器上注册一个会话,在会话存在的时间,我们可以实现即时聊天的一些常用功能,比如建立自己的组,添加好友,聊天,以及传送文件等等,同时,openfire服务器也需要实现自己的管理界面,这样openfire服务器也扮演一个web容器的角色。

 

    XMPP协议是基于TCP/IP协议进行传输的,在openfire中,应用了apache的mina框架作为NIO框架,简单的来说,openfire服务器用mina框架建立一个简单的服务器,可以接收和发送基本的IO流,然后在此基础上把接收到的IO流解析为XML文件,然后在根据XMPP协议对XML文件进行操作。

  • Openfire启动过程

    系统启动时调用org.jivesoftware.openfire.starter.ServerStarter类中的start()方法,加载org.jivesoftware.openfire.XMPPServer类,并调用这个类的start()方法进行一系列的初始化操作,下面是XMPPServer的Start()方法

[java]  view plain copy
  1. public void start() {  
  2.         try {  
  3.             initialize();  
  4.   
  5.             startDate = new Date();  
  6.             // Store server info  
  7.             xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate, getConnectionManager());  
  8.   
  9.             // Create PluginManager now (but don't start it) so that modules may use it  
  10.             File pluginDir = new File(openfireHome, "plugins");  
  11.             pluginManager = new PluginManager(pluginDir);  
  12.   
  13.             // If the server has already been setup then we can start all the server's modules  
  14.             if (!setupMode) {  
  15.                 //这个方法是验证数据库连接是否正确  
  16.                 verifyDataSource();  
  17.                 //加载所有模块  
  18.                 // First load all the modules so that modules may access other modules while  
  19.                 // being initialized  
  20.                 loadModules();  
  21.                 // Initize all the modules  
  22.                 initModules();  
  23.                 // Start all the modules  
  24.                 startModules();  
  25.             }  
  26.             // Initialize statistics  
  27.             ServerTrafficCounter.initStatistics();  
  28.   
  29.             // Load plugins (when in setup mode only the admin console will be loaded)  
  30.             pluginManager.start();  
  31.   
  32.             // Log that the server has been started  
  33.             String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +  
  34.                     " [" + JiveGlobals.formatDateTime(new Date()) + "]";  
  35.             Log.info(startupBanner);  
  36.             System.out.println(startupBanner);  
  37.   
  38.             started = true;  
  39.               
  40.             // Notify server listeners that the server has been started  
  41.             for (XMPPServerListener listener : listeners) {  
  42.                 listener.serverStarted();  
  43.             }  
  44.         }  
  45.         catch (Exception e) {  
  46.             e.printStackTrace();  
  47.             Log.error(e.getMessage(), e);  
  48.             System.out.println(LocaleUtils.getLocalizedString("startup.error"));  
  49.             shutdownServer();  
  50.         }  
  51.     }  
    个人觉得,openfire服务器的启动过程相当清晰,所有的模块都实现了Module接口,然后在启动时统一调用所有模块的initial()方法和start()方法,简单明了又便于扩展,在今后自己的项目中值得加以运用。

在上篇文章中我们成功部署了openfire的源码,这一篇我们来初步了解一下openfire的项目结构。
  • 概述

    Openfire最主要的功能是实现XMPP服务器,简单来说,openfire为我们提供一个固定的地址,我们只需要向openfire服务器发送标准的XMPP信息(即XML文件流),那么openfire服务器应当给予我们回应,这里的openfire服务器也可以看做一个容器,我们在聊天时,需要在这个服务器上注册一个会话,在会话存在的时间,我们可以实现即时聊天的一些常用功能,比如建立自己的组,添加好友,聊天,以及传送文件等等,同时,openfire服务器也需要实现自己的管理界面,这样openfire服务器也扮演一个web容器的角色。

 

    XMPP协议是基于TCP/IP协议进行传输的,在openfire中,应用了apache的mina框架作为NIO框架,简单的来说,openfire服务器用mina框架建立一个简单的服务器,可以接收和发送基本的IO流,然后在此基础上把接收到的IO流解析为XML文件,然后在根据XMPP协议对XML文件进行操作。

  • Openfire启动过程

    系统启动时调用org.jivesoftware.openfire.starter.ServerStarter类中的start()方法,加载org.jivesoftware.openfire.XMPPServer类,并调用这个类的start()方法进行一系列的初始化操作,下面是XMPPServer的Start()方法

[java]  view plain copy
  1. public void start() {  
  2.         try {  
  3.             initialize();  
  4.   
  5.             startDate = new Date();  
  6.             // Store server info  
  7.             xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate, getConnectionManager());  
  8.   
  9.             // Create PluginManager now (but don't start it) so that modules may use it  
  10.             File pluginDir = new File(openfireHome, "plugins");  
  11.             pluginManager = new PluginManager(pluginDir);  
  12.   
  13.             // If the server has already been setup then we can start all the server's modules  
  14.             if (!setupMode) {  
  15.                 //这个方法是验证数据库连接是否正确  
  16.                 verifyDataSource();  
  17.                 //加载所有模块  
  18.                 // First load all the modules so that modules may access other modules while  
  19.                 // being initialized  
  20.                 loadModules();  
  21.                 // Initize all the modules  
  22.                 initModules();  
  23.                 // Start all the modules  
  24.                 startModules();  
  25.             }  
  26.             // Initialize statistics  
  27.             ServerTrafficCounter.initStatistics();  
  28.   
  29.             // Load plugins (when in setup mode only the admin console will be loaded)  
  30.             pluginManager.start();  
  31.   
  32.             // Log that the server has been started  
  33.             String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +  
  34.                     " [" + JiveGlobals.formatDateTime(new Date()) + "]";  
  35.             Log.info(startupBanner);  
  36.             System.out.println(startupBanner);  
  37.   
  38.             started = true;  
  39.               
  40.             // Notify server listeners that the server has been started  
  41.             for (XMPPServerListener listener : listeners) {  
  42.                 listener.serverStarted();  
  43.             }  
  44.         }  
  45.         catch (Exception e) {  
  46.             e.printStackTrace();  
  47.             Log.error(e.getMessage(), e);  
  48.             System.out.println(LocaleUtils.getLocalizedString("startup.error"));  
  49.             shutdownServer();  
  50.         }  
  51.     }  
    个人觉得,openfire服务器的启动过程相当清晰,所有的模块都实现了Module接口,然后在启动时统一调用所有模块的initial()方法和start()方法,简单明了又便于扩展,在今后自己的项目中值得加以运用。

猜你喜欢

转载自blog.csdn.net/lmpt90/article/details/41378381