openfire 中的连接有几种,可以自己实现接口ConnectionProvider,修改openfire.xml中的connectionProvider的属性为自己实现的类。
<connectionProvider>
<className>org.jivesoftware.database.DefaultConnectionProvider</className>
</connectionProvider>
<database>
<defaultProvider>
<driver>com.mysql.jdbc.Driver</driver>
<serverURL>jdbc:mysql://localhost:3306/openfire?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull</serverURL>
<username>root</username>
<password>admin</password>
<testSQL>select 1</testSQL>
<testBeforeUse>false</testBeforeUse>
<testAfterUse>false</testAfterUse>
<minConnections>5</minConnections>
<maxConnections>25</maxConnections>
<connectionTimeout>1.0</connectionTimeout>
</defaultProvider>
</database>
openfire实现了3个相关的接口,JNDIDataSourceProvider,EmbeddedConnectionProvider,DefaultConnectionProvider(默认的连接管理器),下面将分别解析这三个类。
1. DefaultConnectionProvider:是openfire提供的默认连接管理器,使用了org.logicalcobwebs.proxool.ProxoolDriver提供的连接池,
其中ConnectionProvider的start方法如下,主要设置连接池的相关参数
public void start() {
proxoolURL = "proxool.openfire:"+getDriver()+":"+getServerURL();
settings = new Properties();
settings.setProperty("proxool.maximum-activetime", Integer.toString(activeTimeout));
settings.setProperty("proxool.maximum-connection-count", Integer.toString(getMaxConnections()));
settings.setProperty("proxool.minimum-connection-count", Integer.toString(getMinConnections()));
settings.setProperty("proxool.maximum-connection-lifetime", Integer.toString((int)(86400000 * getConnectionTimeout())));
settings.setProperty("proxool.test-before-use", testBeforeUse.toString());
settings.setProperty("proxool.test-after-use", testAfterUse.toString());
settings.setProperty("proxool.house-keeping-test-sql", testSQL);
settings.setProperty("user", getUsername());
settings.setProperty("password", (getPassword() != null ? getPassword() : ""));
}
2.EmbeddedConnectionProvider(嵌入式连接管理器),主要是用于openfire中采用的hsqldb.
public Connection getConnection() throws SQLException {
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
return DriverManager.getConnection(proxoolURL, settings);
}
catch (ClassNotFoundException e) {
throw new SQLException("EmbeddedConnectionProvider: Unable to find driver: "+e);
}
}
,此也采用org.logicalcobwebs.proxool.ProxoolDriver代理连接池。
hsqldb,的存放地址为openfire目录下的embedded-db中。
File databaseDir = new File(JiveGlobals.getHomeDirectory(), File.separator + "embedded-db");
// If the database doesn't exist, create it.
if (!databaseDir.exists()) {
databaseDir.mkdirs();
}
try {
serverURL = "jdbc:hsqldb:" + databaseDir.getCanonicalPath() + File.separator + "openfire";
}
catch (IOException ioe) {
Log.error("EmbeddedConnectionProvider: Error starting connection pool: ", ioe);
}
Hsqldb是一个开放源代码的JAVA数据库,其具有标准的SQL语法和JAVA接口,它可以自由使用和分发,非常简洁和快速的。具有Server模式,进程内模式(In-Process)和内存模式(Memory-Only)三种。运行Hsqldb需要hsqldb.jar包, 它包含了一些组件和程序。每个程序需要不同的命令来运行。
更多关于Hsqldb请查看其它相关资料,在openfire中使用的标准的sql。
3.JNDIDataSourceProvider
openfire提供的JNDI连接器。
public void start() {
if (dataSourceName == null || dataSourceName.equals("")) {
Log.error("No name specified for DataSource. JNDI lookup will fail", new Throwable());
return;
}
try {
Properties contextProperties = new Properties();
for (String key: jndiPropertyKeys) {
String value = JiveGlobals.getXMLProperty(key);
if (value != null) {
contextProperties.setProperty(key, value);
}
}
Context context;
if (contextProperties.size() > 0) {
context = new InitialContext(contextProperties);
}
else {
context = new InitialContext();
}
dataSource = (DataSource)context.lookup(dataSourceName);
}
catch (Exception e) {
Log.error("Could not lookup DataSource at '" + dataSourceName + "'", e);
}
}
其主要属性有:
private static final String[] jndiPropertyKeys = {
Context.APPLET,
Context.AUTHORITATIVE,
Context.BATCHSIZE,
Context.DNS_URL,
Context.INITIAL_CONTEXT_FACTORY,
Context.LANGUAGE,
Context.OBJECT_FACTORIES,
Context.PROVIDER_URL,
Context.REFERRAL,
Context.SECURITY_AUTHENTICATION,
Context.SECURITY_CREDENTIALS,
Context.SECURITY_PRINCIPAL,
Context.SECURITY_PROTOCOL,
Context.STATE_FACTORIES,
Context.URL_PKG_PREFIXES
};
具体可查看JNDI相关。
4.实现自己的连机器(ConnectionProvider),
public interface ConnectionProvider {
public boolean isPooled();
public Connection getConnection() throws SQLException;
public void start();
public void restart();
public void destroy();
}
需要写以上相关方法,可以用通用的连接池,c3p0,阿帕奇的dbcp等。
对于openfire比较遗憾的是,没有相关事务的管理,关于sql的处理在各个模块都有,耦合性较大。
此篇文章就到此,稍后会有更多关于openfire的个人解读。
联系方式(qq):851392159
相关推荐
openfire自带数据库的字典,详细展示数据库的每个表的结构,并备注了每个字段的含义,对开发者有很好的帮助。
实现openfire与用户数据库集成 实现用户认证、用户查询
数据库字典,想了解的朋友。这个真的不错。openfire再次开发必备资料。
详细列出了即时通信服务端openfire数据库的表结构,包括表名字段名,字段属性,主外键等等
openfire数据库模式指南,列出了其所有数据库表结构及说明
openfire 脚本文件
如何安装配置Openfire for苹果
本是为了给项目组成员开发使用而纯个人翻译的openfire数据库架构,添加了一些网上搜到的Openfire的资料进行字段解释
介绍了openfire的数据库结构及工作流程以及插件开发。
-bash-4.1$ cd /usr/local/openfire/bin -bash-4.1$ ./openfire stop 2.找到openfire配置文件 [root@openfire.clvn.com.cn ~]# cd /usr/local/openfire/conf/ [root@openfire.clvn.com.cn conf]# ls ...
openfire 3_9_1,welcome download, for free
openfire_src_3_8_2.zip openfire服务器源码
openfire_3_9_3.tar.zip 很不错的移动移动及时通讯工具
openfire聊天记录插件,含有mysql脚本,安装插件前现根据提供的mysql脚本建个表(其他数据库可根据mysql的样式自己建,很简单)
openfire_3_9_3.zip,解压后,复制openfire目录到C:\Program Files\目录下;一定要在C:\Program Files\目录 下的;这样openfire就安装完成了。
openfire_3_9_3.tar.gz 源码安装openfire openfire 二次开发
max 下的openfire_3_9_3.dmg http://blog.csdn.net/pengcheng_liu/article/details/26249979配套使用的资源
Openfire在使用MySQL数据库后的中文乱码问题解决.docx
第二章 安装OPENFIRE3.6.4 3 2.1 配置机器的域名 3 2.2 安装OPENFIRE 3 2.2.1 安装 3 2.2.2 运行数据库脚本 4 2.2.3 数据库驱动jar包 6 2.2.4 openfire初始化配置 6 2.3 设置用户 12 第三章 安装SPARK客户端 13 第四...
openfire导入eclipse所有缺少的jar包都在这里了