XMPP協議學習筆記四(Openfire服務器啓動過程) - nomousewch的專欄 - 博客頻道 - CSDN.NETjava
在上篇文章中咱們成功部署了openfire的源碼,這一篇咱們來初步瞭解一下openfire的項目結構。web
- 概述
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文件進行操做。apache
- Openfire啓動過程
系統啓動時調用org.jivesoftware.openfire.starter.ServerStarter類中的start()方法,加載org.jivesoftware.openfire.XMPPServer類,並調用這個類的start()方法進行一系列的初始化操做,下面是XMPPServer的Start()方法服務器
- public void start() {
- try {
- initialize();
- startDate = new Date();
- // Store server info
- xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate, getConnectionManager());
- // Create PluginManager now (but don't start it) so that modules may use it
- File pluginDir = new File(openfireHome, "plugins");
- pluginManager = new PluginManager(pluginDir);
- // If the server has already been setup then we can start all the server's modules
- if (!setupMode) {
- //這個方法是驗證數據庫鏈接是否正確
- verifyDataSource();
- //加載全部模塊
- // First load all the modules so that modules may access other modules while
- // being initialized
- loadModules();
- // Initize all the modules
- initModules();
- // Start all the modules
- startModules();
- }
- // Initialize statistics
- ServerTrafficCounter.initStatistics();
- // Load plugins (when in setup mode only the admin console will be loaded)
- pluginManager.start();
- // Log that the server has been started
- String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +
- " [" + JiveGlobals.formatDateTime(new Date()) + "]";
- Log.info(startupBanner);
- System.out.println(startupBanner);
- started = true;
- // Notify server listeners that the server has been started
- for (XMPPServerListener listener : listeners) {
- listener.serverStarted();
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- Log.error(e.getMessage(), e);
- System.out.println(LocaleUtils.getLocalizedString("startup.error"));
- shutdownServer();
- }
- }
public void start() { try { initialize(); startDate = new Date(); // Store server info xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate, getConnectionManager()); // Create PluginManager now (but don't start it) so that modules may use it File pluginDir = new File(openfireHome, "plugins"); pluginManager = new PluginManager(pluginDir); // If the server has already been setup then we can start all the server's modules if (!setupMode) { //這個方法是驗證數據庫鏈接是否正確 verifyDataSource(); //加載全部模塊 // First load all the modules so that modules may access other modules while // being initialized loadModules(); // Initize all the modules initModules(); // Start all the modules startModules(); } // Initialize statistics ServerTrafficCounter.initStatistics(); // Load plugins (when in setup mode only the admin console will be loaded) pluginManager.start(); // Log that the server has been started String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() + " [" + JiveGlobals.formatDateTime(new Date()) + "]"; Log.info(startupBanner); System.out.println(startupBanner); started = true; // Notify server listeners that the server has been started for (XMPPServerListener listener : listeners) { listener.serverStarted(); } } catch (Exception e) { e.printStackTrace(); Log.error(e.getMessage(), e); System.out.println(LocaleUtils.getLocalizedString("startup.error")); shutdownServer(); } }我的以爲,openfire服務器的啓動過程至關清晰,全部的模塊都實現了Module接口,而後在啓動時統一調用全部模塊的initial()方法和start()方法,簡單明瞭又便於擴展,在從此本身的項目中值得加以運用。app