Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
53ec74d9
Commit
53ec74d9
authored
Jan 14, 2016
by
wuchang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add LocalMUCRoomManager to encapsule the simple management for LocalMUCRoom
parent
b366b1d7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
28 deletions
+70
-28
LocalMUCRoomManager.java
...rg/jivesoftware/openfire/muc/spi/LocalMUCRoomManager.java
+49
-0
MultiUserChatServiceImpl.java
...vesoftware/openfire/muc/spi/MultiUserChatServiceImpl.java
+21
-28
No files found.
src/java/org/jivesoftware/openfire/muc/spi/LocalMUCRoomManager.java
0 → 100644
View file @
53ec74d9
package
org
.
jivesoftware
.
openfire
.
muc
.
spi
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.jivesoftware.openfire.event.GroupEventDispatcher
;
import
org.jivesoftware.openfire.muc.MUCRoom
;
/**
* this class supports the simple LocalMUCRoom management including remove,add and query.
* @author wuchang
* @email 583424568@qq.com
* 2016-1-14
*/
public
class
LocalMUCRoomManager
{
private
Map
<
String
,
LocalMUCRoom
>
rooms
=
new
ConcurrentHashMap
<>();
public
int
getNumberChatRooms
(){
return
rooms
.
size
();
}
public
void
addRoom
(
String
roomname
,
LocalMUCRoom
room
){
rooms
.
put
(
roomname
,
room
);
}
public
Collection
<
LocalMUCRoom
>
getRooms
(){
return
rooms
.
values
();
}
public
LocalMUCRoom
getRoom
(
String
roomname
){
return
rooms
.
get
(
roomname
);
}
public
MUCRoom
removeRoom
(
String
roomname
){
//memory leak will happen if we forget remove it from GroupEventDispatcher
if
(
rooms
.
containsKey
(
roomname
))
GroupEventDispatcher
.
removeListener
((
LocalMUCRoom
)
rooms
.
get
(
roomname
));
return
rooms
.
remove
(
roomname
);
}
public
void
cleanupRooms
(
Date
cleanUpDate
)
{
for
(
MUCRoom
room
:
getRooms
())
{
if
(
room
.
getEmptyDate
()
!=
null
&&
room
.
getEmptyDate
().
before
(
cleanUpDate
))
{
removeRoom
(
room
.
getName
());
}
}
}
}
src/java/org/jivesoftware/openfire/muc/spi/MultiUserChatServiceImpl.java
View file @
53ec74d9
...
...
@@ -135,9 +135,9 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
private
String
chatDescription
=
null
;
/**
*
chatrooms managed by this manager, table: key room name (String); value ChatRoom
*
LocalMUCRoom chat manager which supports simple chatroom management
*/
private
Map
<
String
,
LocalMUCRoom
>
rooms
=
new
ConcurrentHashMap
<>
();
private
LocalMUCRoomManager
localMUCRoomManager
=
new
LocalMUCRoomManager
();
/**
* Chat users managed by this manager. This includes only users connected to this JVM.
...
...
@@ -510,7 +510,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
return
;
}
try
{
cleanupRooms
(
);
localMUCRoomManager
.
cleanupRooms
(
getCleanupDate
()
);
}
catch
(
Throwable
e
)
{
Log
.
error
(
LocaleUtils
.
getLocalizedString
(
"admin.error"
),
e
);
...
...
@@ -518,13 +518,6 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
}
}
private
void
cleanupRooms
()
{
for
(
MUCRoom
room
:
rooms
.
values
())
{
if
(
room
.
getEmptyDate
()
!=
null
&&
room
.
getEmptyDate
().
before
(
getCleanupDate
()))
{
removeChatRoom
(
room
.
getName
());
}
}
}
@Override
public
MUCRoom
getChatRoom
(
String
roomName
,
JID
userjid
)
throws
NotAllowedException
{
...
...
@@ -532,7 +525,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
boolean
loaded
=
false
;
boolean
created
=
false
;
synchronized
(
roomName
.
intern
())
{
room
=
rooms
.
get
(
roomName
);
room
=
localMUCRoomManager
.
getRoom
(
roomName
);
if
(
room
==
null
)
{
room
=
new
LocalMUCRoom
(
this
,
roomName
,
router
);
// If the room is persistent load the configuration values from the DB
...
...
@@ -576,7 +569,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
created
=
true
;
}
}
rooms
.
put
(
roomName
,
room
);
localMUCRoomManager
.
addRoom
(
roomName
,
room
);
}
}
if
(
created
)
{
...
...
@@ -598,11 +591,11 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
@Override
public
MUCRoom
getChatRoom
(
String
roomName
)
{
boolean
loaded
=
false
;
LocalMUCRoom
room
=
rooms
.
get
(
roomName
);
LocalMUCRoom
room
=
localMUCRoomManager
.
getRoom
(
roomName
);
if
(
room
==
null
)
{
// Check if the room exists in the databclase and was not present in memory
synchronized
(
roomName
.
intern
())
{
room
=
rooms
.
get
(
roomName
);
room
=
localMUCRoomManager
.
getRoom
(
roomName
);
if
(
room
==
null
)
{
room
=
new
LocalMUCRoom
(
this
,
roomName
,
router
);
// If the room is persistent load the configuration values from the DB
...
...
@@ -612,7 +605,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
// room may be an old room that was not present in memory)
MUCPersistenceManager
.
loadFromDB
(
room
);
loaded
=
true
;
rooms
.
put
(
roomName
,
room
);
localMUCRoomManager
.
addRoom
(
roomName
,
room
);
}
catch
(
IllegalArgumentException
e
)
{
// The room does not exist so do nothing
...
...
@@ -630,17 +623,17 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
@Override
public
void
refreshChatRoom
(
String
roomName
)
{
rooms
.
remove
(
roomName
);
localMUCRoomManager
.
removeRoom
(
roomName
);
getChatRoom
(
roomName
);
}
public
LocalMUCRoom
getLocalChatRoom
(
String
roomName
)
{
return
rooms
.
get
(
roomName
);
return
localMUCRoomManager
.
getRoom
(
roomName
);
}
@Override
public
List
<
MUCRoom
>
getChatRooms
()
{
return
new
ArrayList
<
MUCRoom
>(
rooms
.
value
s
());
return
new
ArrayList
<
MUCRoom
>(
localMUCRoomManager
.
getRoom
s
());
}
@Override
...
...
@@ -672,11 +665,11 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
*/
@Override
public
void
chatRoomAdded
(
LocalMUCRoom
room
)
{
rooms
.
put
(
room
.
getName
(),
room
)
;
localMUCRoomManager
.
addRoom
(
room
.
getName
(),
room
)
;
}
private
void
removeChatRoom
(
String
roomName
,
boolean
notify
)
{
MUCRoom
room
=
rooms
.
remove
(
roomName
);
MUCRoom
room
=
localMUCRoomManager
.
removeRoom
(
roomName
);
Log
.
info
(
"removing chat room:"
+
roomName
+
"|"
+
room
.
getClass
().
getName
());
if
(
room
instanceof
LocalMUCRoom
)
GroupEventDispatcher
.
removeListener
((
LocalMUCRoom
)
room
);
...
...
@@ -740,7 +733,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if
(
user
==
null
)
{
if
(
roomName
!=
null
)
{
// Check if the JID belong to a user hosted in another cluster node
LocalMUCRoom
localMUCRoom
=
rooms
.
get
(
roomName
);
LocalMUCRoom
localMUCRoom
=
localMUCRoomManager
.
getRoom
(
roomName
);
if
(
localMUCRoom
!=
null
)
{
MUCRole
occupant
=
localMUCRoom
.
getOccupantByFullJID
(
userjid
);
if
(
occupant
!=
null
&&
!
occupant
.
isLocal
())
{
...
...
@@ -758,7 +751,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
@Override
public
Collection
<
MUCRole
>
getMUCRoles
(
JID
user
)
{
List
<
MUCRole
>
userRoles
=
new
ArrayList
<>();
for
(
LocalMUCRoom
room
:
rooms
.
value
s
())
{
for
(
LocalMUCRoom
room
:
localMUCRoomManager
.
getRoom
s
())
{
MUCRole
role
=
room
.
getOccupantByFullJID
(
user
);
if
(
role
!=
null
)
{
userRoles
.
add
(
role
);
...
...
@@ -1153,7 +1146,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
Log
.
info
(
LocaleUtils
.
getLocalizedString
(
"startup.starting.muc"
,
params
));
// Load all the persistent rooms to memory
for
(
LocalMUCRoom
room
:
MUCPersistenceManager
.
loadRoomsFromDB
(
this
,
this
.
getCleanupDate
(),
router
))
{
rooms
.
put
(
room
.
getName
().
toLowerCase
(),
room
);
localMUCRoomManager
.
addRoom
(
room
.
getName
().
toLowerCase
(),
room
);
}
}
...
...
@@ -1205,7 +1198,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
*/
@Override
public
int
getNumberChatRooms
()
{
return
rooms
.
size
();
return
localMUCRoomManager
.
getNumberChatRooms
();
}
/**
...
...
@@ -1244,7 +1237,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
@Override
public
int
getNumberRoomOccupants
()
{
int
total
=
0
;
for
(
MUCRoom
room
:
rooms
.
value
s
())
{
for
(
MUCRoom
room
:
localMUCRoomManager
.
getRoom
s
())
{
total
=
total
+
room
.
getOccupantsCount
();
}
return
total
;
...
...
@@ -1562,7 +1555,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if
(
name
==
null
&&
node
==
null
)
{
// Answer all the public rooms as items
for
(
MUCRoom
room
:
rooms
.
value
s
())
for
(
MUCRoom
room
:
localMUCRoomManager
.
getRoom
s
())
{
if
(
canDiscoverRoom
(
room
,
senderJID
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment