惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
Spread Privacy
Spread Privacy
Cloudbric
Cloudbric
V
Vulnerabilities – Threatpost
博客园 - 叶小钗
I
Intezer
S
Secure Thoughts
Jina AI
Jina AI
T
Tenable Blog
博客园 - 【当耐特】
WordPress大学
WordPress大学
W
WeLiveSecurity
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Google DeepMind News
Google DeepMind News
Schneier on Security
Schneier on Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
Martin Fowler
Martin Fowler
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
IT之家
IT之家
小众软件
小众软件
P
Privacy & Cybersecurity Law Blog
V
Visual Studio Blog
S
Securelist
M
MIT News - Artificial intelligence
H
Help Net Security
Scott Helme
Scott Helme
N
News and Events Feed by Topic
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园_首页
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
T
Tailwind CSS Blog
A
About on SuperTechFans
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
H
Heimdal Security Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale

博客园 - 追梦华仔

Openfire服务器MySQL优化 放开Linux内核对用户进程可打开文件数和TCP连接的限制 SSL 握手协议 非对称密码学(Asymmetric Cryptography)- 转载 Visual Studio 2008下载 Visual Studio 2008 提示“无法识别工具版本4.0” Openfire S2S 经验分享 注册Jmail组件的三种方法 读取excel文件的时候 出错提示:外部表不是预期的格式 - 追梦华仔 - 博客园 System.Runtime.InteropServices.COMException: 服务器出现意外情况 Excel表格导入出错,提示“拒绝访问”的错误,ExcelObj = new Excel.Application(); 在 ASP.NET 中执行 URL 重写 XP下如何解决“ASP.NET 未被授权访问所请求的资源”的问题 - 追梦华仔 - 博客园 无法在web服务器上启动调试 您不具备调试此应用程序的权限 - 追梦华仔 - 博客园 Server Application Error ---Http 500错误解决方法 用Lucene实现在检索结果中再检索 [转载]Ruby on Rails:开源技术将深入企业 Lucene.Net中按时间范围查询,结果没有查到数据 Lucene.Net.Search.Highlight.FragmentQueue 中的派生方法 LessThan 不能减少访问
改造MUC实现Openfire群
追梦华仔 · 2011-12-31 · via 博客园 - 追梦华仔

我的Openfire群实现思路:

1、群和群成员,要保存到表中。

2、拉取群列表和群成员列表,均从DB中查询返回。

3、抛弃老外的“进房间,要发Presence ”。只要此人一上线,就模似一个Presence进行joinRoom,进入他的各群房间。

     多了解LocalMUCRoom 类中:public LocalMUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest, LocalMUCUser user, Presence presence)

    我的模似代码如下:

View Code

 1 /**
 2      * 模似用户进群(含呢称、含Precense、初始化角色LocalMUCRole)
 3      * @param roomId
 4      * @param packet
 5      * @return
 6      */
 7     public MUCRole getRolesByRoomId(long roomId, Packet packet)
 8     {
 9         MUCRole role = null;
10         try {
11             // Get or create the room  获取该群
12             MUCRoom room = server.getChatRoom(roomId, packet.getFrom());
13             
14             //从数据库中查询他的姓名作为昵称(得自己实现)
15             String nickname = new MUCRoomServiceDao().getUserNickname(packet.getFrom().getNode());
16             if(nickname == null)
17             {
18                 if(packet.getFrom().getResource() != null)
19                 {
20                     nickname = packet.getFrom().getResource();
21                 }
22                 else 
23                 {
24                     nickname = packet.getFrom().getNode();
25                 }
26             }
27             
28             HistoryRequest historyRequest = null;
29             String password = null;
30             
31             //构建成员进入群的Presence
32             Presence presence = new Presence();
33             presence.setTo(room.getJID().toBareJID() + "/" + nickname);    
34             presence.setFrom(packet.getFrom());
35             PacketExtension extension = new PacketExtension("x", http://jabber.org/protocol/muc);
36             presence.addExtension(extension);
37             
38             // The user joins the room 用户进入群
39             role = room.joinRoom(nickname,
40                     password,
41                     historyRequest,
42                     this,
43                     presence);
44             
45             // If the client that created the room is non-MUC compliant then
46             // unlock the room thus creating an "instant" room
47             //if (mucInfo == null && room.isLocked() && !room.isManuallyLocked()) {
48             if (room.isLocked() && !room.isManuallyLocked()) {
49                 room.unlock(role);
50                 //server.chatRoomAdded((LocalMUCRoom)room);
51             }
52             
53             addRole(roomId, (LocalMUCRole)role);//添加“用户在某个群中的角色”
54             
55         }
56         catch (UnauthorizedException e) {
57             sendErrorPacket(packet, PacketError.Condition.not_authorized);
58         }
59         catch (ServiceUnavailableException e) {
60             sendErrorPacket(packet, PacketError.Condition.service_unavailable);
61         }
62         catch (UserAlreadyExistsException e) {
63             sendErrorPacket(packet, PacketError.Condition.conflict);
64         }
65         catch (RoomLockedException e) {
66             sendErrorPacket(packet, PacketError.Condition.recipient_unavailable);
67         }
68         catch (ForbiddenException e) {
69             sendErrorPacket(packet, PacketError.Condition.forbidden);
70         }
71         catch (RegistrationRequiredException e) {
72             sendErrorPacket(packet, PacketError.Condition.registration_required);
73         }
74         catch (ConflictException e) {
75             sendErrorPacket(packet, PacketError.Condition.conflict);
76         }
77         catch (NotAcceptableException e) {
78             sendErrorPacket(packet, PacketError.Condition.not_acceptable);
79         }
80         catch (NotAllowedException e) {
81             sendErrorPacket(packet, PacketError.Condition.not_allowed);
82         }        
83         return role;
84     }

 4、抛弃老外的“以昵称为Key 缓存群成员”。改为以帐号为Key。

     多了解 LocalMUCRoom 类中:private Map<String,MUCRole> occupants = new ConcurrentHashMap<String, MUCRole>();

     在joinRoom办法中:    

View Code

1 //以JID作为缓存的key
2         JID userJid = user.getAddress();
3         if (userJid != null) {
4             occupants.put(userJid.toBareJID(), joinRole);
5         }

 5、详细了解 LocalMUCRoom、LocalMUCUser、LocalMUCRole这三个类,各类中的数据成员、方法。