Commit f6c94975 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Flush queued conversation log entries when the service is shutting down.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@427 b35dd754-fafc-0310-a699-88a17e54d16e
parent 904f18f1
...@@ -725,7 +725,7 @@ public class MUCPersistenceManager { ...@@ -725,7 +725,7 @@ public class MUCPersistenceManager {
return true; return true;
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error("Error saving conversation log entry", sqle);
return false; return false;
} }
finally { finally {
......
...@@ -242,6 +242,20 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -242,6 +242,20 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
} }
} }
/**
* Logs all the remaining conversation log entries to the database. Use this method to force
* saving all the conversation log entries before the service becomes unavailable.
*/
private void logAllConversation() {
ConversationLogEntry entry = null;
while (!logQueue.isEmpty()) {
entry = logQueue.poll();
if (entry != null) {
MUCPersistenceManager.saveConversationLogEntry(entry);
}
}
}
public MUCRoom getChatRoom(String roomName, XMPPAddress userjid) throws UnauthorizedException { public MUCRoom getChatRoom(String roomName, XMPPAddress userjid) throws UnauthorizedException {
MUCRoom room = null; MUCRoom room = null;
synchronized (rooms) { synchronized (rooms) {
...@@ -550,6 +564,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -550,6 +564,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
public void stop() { public void stop() {
super.stop(); super.stop();
timer.cancel(); timer.cancel();
logAllConversation();
if (registerHandler != null) { if (registerHandler != null) {
registerHandler.removeDelegate(getServiceName()); registerHandler.removeDelegate(getServiceName());
} }
...@@ -802,6 +817,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -802,6 +817,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
MUCRole role; MUCRole role;
Element item; Element item;
for (Iterator<MUCRole> members = room.getOccupants(); members.hasNext();) { for (Iterator<MUCRole> members = room.getOccupants(); members.hasNext();) {
// TODO Should we filter occupants that are invisible (presence is not broadcasted)?
role = members.next(); role = members.next();
item = DocumentHelper.createElement("item"); item = DocumentHelper.createElement("item");
item.addAttribute("jid", role.getRoleAddress().toStringPrep()); item.addAttribute("jid", role.getRoleAddress().toStringPrep());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment