openfire中提供了生产序列的管理器(SequenceManager),其构造函数如下:
public SequenceManager(int seqType, int size) {
managers.put(seqType, this);
this.type = seqType;
this.blockSize = size;
currentID = 0l;
maxID = 0l;
}
seqType,为序列类型,默认有3种类型:
public static final int ROSTER = 18;
public static final int OFFLINE = 19;
public static final int MUC_ROOM = 23;
size:序列的增加值。例如a=a+2;
private void getNextBlock(int count) {
if (count == 0) {
Log.error("Failed at last attempt to obtain an ID, aborting...");
return;
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean abortTransaction = false;
boolean success = false;
try {
con = DbConnectionManager.getTransactionConnection();
// Get the current ID from the database.
pstmt = con.prepareStatement(LOAD_ID);
pstmt.setInt(1, type);
rs = pstmt.executeQuery();
long currentID = 1;
if (rs.next()) {
currentID = rs.getLong(1);
}
else {
createNewID(con, type);
}
DbConnectionManager.fastcloseStmt(rs, pstmt);
// Increment the id to define our block.
long newID = currentID + blockSize;
// The WHERE clause includes the last value of the id. This ensures
// that an update will occur only if nobody else has performed an
// update first.
pstmt = con.prepareStatement(UPDATE_ID);
pstmt.setLong(1, newID);
pstmt.setInt(2, type);
pstmt.setLong(3, currentID);
// Check to see if the row was affected. If not, some other process
// already changed the original id that we read. Therefore, this
// round failed and we'll have to try again.
success = pstmt.executeUpdate() == 1;
if (success) {
this.currentID = currentID;
this.maxID = newID;
}
}
catch (SQLException e) {
Log.error(e.getMessage(), e);
abortTransaction = true;
}
finally {
DbConnectionManager.closeStatement(rs, pstmt);
DbConnectionManager.closeTransactionConnection(con, abortTransaction);
}
if (!success) {
Log.error("WARNING: failed to obtain next ID block due to " +
"thread contention. Trying again...");
// Call this method again, but sleep briefly to try to avoid thread contention.
try {
Thread.sleep(75);
}
catch (InterruptedException ie) {
// Ignore.
}
getNextBlock(count - 1);
}
}
此方法为:更具类型到数据库中ofid查询ID,获取表中的id,然后id加一个变量,然后将新的id更新到数据库中。
private void createNewID(Connection con, int type) throws SQLException {
Log.warn("Autocreating jiveID row for type '" + type + "'");
// create new ID row
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(CREATE_ID);
pstmt.setInt(1, type);
pstmt.execute();
}
finally {
DbConnectionManager.closeStatement(pstmt);
}
}
在表中创建一条序列的记录。
此篇文章就到此,稍后会有更多关于openfire的个人解读。
联系方式(qq):851392159
相关推荐
实现openfire与用户数据库集成 实现用户认证、用户查询
openfire自带数据库的字典,详细展示数据库的每个表的结构,并备注了每个字段的含义,对开发者有很好的帮助。
数据库字典,想了解的朋友。这个真的不错。openfire再次开发必备资料。
详细列出了即时通信服务端openfire数据库的表结构,包括表名字段名,字段属性,主外键等等
openfire数据库模式指南,列出了其所有数据库表结构及说明
openfire 脚本文件
如何安装配置Openfire for苹果
openfire_4_1_4.tar.gz
本是为了给项目组成员开发使用而纯个人翻译的openfire数据库架构,添加了一些网上搜到的Openfire的资料进行字段解释
windows环境下的openfire服务器,用于消息推送
介绍了openfire的数据库结构及工作流程以及插件开发。
openfire服务端自带jre
-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_4_1_0.服务器版本,无法免资源分数上传。百度网盘链接:http://pan.baidu.com/s/1jIh76ku 密码:zruk
openfire_4_1_5最新版
openfire聊天记录插件,含有mysql脚本,安装插件前现根据提供的mysql脚本建个表(其他数据库可根据mysql的样式自己建,很简单)
openfire_4_1_3服务器版最新版本的mac安装包
没有jre的open fire,Openfire (formerly Wildfire) is a cross-platform real-time collaboration server based on the XMPP (Jabber) protocol. Read about the name change
是开源的、基于可拓展通讯和表示协议(XMPP)、采用Java编程语言开发的实时协作服务器。 Openfire安装和使用都非常简单,并利用Web进行管理。单台服务器可支持上万并发用户。
openfire_4_1_3编译缺少包