org.jivesoftware.openfire.starter包中ServerStarter类为程序启动入口,会调用其中的start方法,启动所有的服务器模块。
最后会将org.jivesoftware.openfire.XMPPServer加载到jvm中。
XMPPServer是一个单例:
private static XMPPServer instance;
public static XMPPServer getInstance() {
return instance;
}
public XMPPServer() {
// We may only have one instance of the server running on the JVM
if (instance != null) {
throw new IllegalStateException("A server is already running");
}
instance = this;
start();
}
在XMPPServer中加载插件及所有的服务器模块。
其中RoutingTableImpl(路由表模块)、SessionManager(会话管理模块)、PacketDelivererImpl(包发送模块)、PacketRouterImpl
(包路由模块)、ConnectionManagerImpl(连接管理模块)为核心模块。
需要注意的是需要配置openfireHome的参数,如没有配置会报Could not locate home,抛出FileNotFoundException异常。
在eclipse中配置openfireHome:右键run configurations-->VM arguments添加-DopenfireHome=path 其中path为通过ant
编译的target\openfire的绝对路径。例如:-DopenfireHome=C:\Openfire\target\openfire