Openfire代码阅读之二--插件
系列一
whuige(whuige@gmail.com)
插件的概念
插件是一种遵循一定规范的应用程序接口编写出来的程序。在Openfire项目中,采用了插件的机制,它促使你可以在不改变核心代码的基础上,增加多种你需要的功能;同时,它可以减少你部署和测试的工作量,对于后期的程序维护也有很大的好处:当你需要对某一个插件进行升级时, 只需要动态的unload这个插件,然后patch,上传到服务器中即可。你甚至可以不需要停止服务就可以完成对插件的升级。
Openfire插件
Openfire 对插件的目录结构进行了指定,需要按照它的目录结构对插件进行打包,便于Openfire对插件进行管理,插件的目录结构如下:
myplugin/
|- plugin.xml <- Plugin definition file
|- readme.html <- Optional readme file for plugin, which will be displayed to end users
|- changelog.html <- Optional changelog file for plugin, which will be displayed to end users
|- logo_small.gif <- Optional small (16x16) icon associated with the plugin (can also be a .png file)
|- logo_large.gif <- Optional large (32x32) icon associated with the plugin (can also be a .png file)
|- classes/ <- Resources your plugin needs (i.e., a properties file)
|- database/ <- Optional database schema files that your plugin needs
|- i18n/ <- Optional i18n files to allow for internationalization of plugins.
|- lib/ <- Libraries (JAR files) your plugin needs
|- web <- Resources for Admin Console integration, if any
|- WEB-INF/
|- web.xml <- Generated web.xml containing compiled JSP entries
|- web-custom.xml <- Optional user-defined web.xml for custom servlets
|- images/
在整个目录结构中,plugin.xml对插件进行了定义,PluginManager也是根据这个文件对插件进行管理,包括版本的判断,资源的加载,插件实例化,注册插件的servlet,数据库的管理,将插件的web菜单页面加载到portal(我认为openfire core提供了一种portal的概念,虽然不是严格意义上的)中。
plugin.xml的定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<!-- Main plugin class -->
<class>org.example.ExamplePlugin</class>
<!-- Plugin meta-data -->
<name>Example Plugin</name>
<description>This is an example plugin.</description>
<author>Jive Software</author>
<version>1.0</version>
<date>07/01/2006</date>
<url>http://www.igniterealtime.org/projects/openfire/plugins.jsp</url>
<minServerVersion>3.0.0</minServerVersion>
<licenseType>gpl</licenseType>
<!-- Admin console entries -->
<adminconsole>
<!-- More on this below -->
</adminconsole>
</plugin>
其中字段的解释:
-
- class: 插件的入口类,在此类中,必须实现Plugin这个interface。
- name: 插件的名字
- description: 插件的描述。 会出现在插件的管理页面中。
- author: 插件的作者,同description
- version: 插件版本, 同上
- date: 插件的开发日期,同上
- miniServerVersion: 插件需要Openfire平台的最低版本号,在插件装载过程中,平台判断插件的版本号是否匹配,如果不匹配,则不加载。
- adminconsole: 这个标签指定了插件在Openfire平台中的web入口菜单,openfire会根据这个文件来动态的生成多级入口菜单,这个在后续会继续解释。
在开发好插件并调试完成后,将插件打包成为jar或者zip,上传到openfire管理平台中,openfire会自动加载你的插件。
好了,截止目前为止,基本上是翻译openfire的插件开发指南,别说翻译简单,可也是个体力活,很消耗卡路里,有点累了,后续blog中我会分析内部代码的实现。
参考页面:http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/plugin-dev-guide.html
格式貌似很乱, 完整的pdf格式下载