Commit 03aebddd authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed concurrency issues. JM-470

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@3121 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6beb4cf9
...@@ -18,6 +18,7 @@ import org.xmpp.packet.Message; ...@@ -18,6 +18,7 @@ import org.xmpp.packet.Message;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.concurrent.ConcurrentLinkedQueue;
/** /**
* <p>Multi-User Chat rooms may cache history of the conversations in the room in order to * <p>Multi-User Chat rooms may cache history of the conversations in the room in order to
...@@ -39,7 +40,7 @@ public class HistoryStrategy { ...@@ -39,7 +40,7 @@ public class HistoryStrategy {
/** /**
* List containing the history of messages. * List containing the history of messages.
*/ */
private LinkedList history = new LinkedList(); private ConcurrentLinkedQueue<Message> history = new ConcurrentLinkedQueue<Message>();
/** /**
* Default max number. * Default max number.
*/ */
...@@ -159,7 +160,7 @@ public class HistoryStrategy { ...@@ -159,7 +160,7 @@ public class HistoryStrategy {
} }
} }
else if (strategyType == Type.all) { else if (strategyType == Type.all) {
history.addLast(packet); history.add(packet);
} }
else if (strategyType == Type.number) { else if (strategyType == Type.number) {
if (history.size() >= strategyMaxNumber) { if (history.size() >= strategyMaxNumber) {
...@@ -169,14 +170,14 @@ public class HistoryStrategy { ...@@ -169,14 +170,14 @@ public class HistoryStrategy {
// last room subject // last room subject
// message because we want to preserve the room subject if // message because we want to preserve the room subject if
// possible. // possible.
ListIterator historyIter = history.listIterator(); Iterator historyIter = history.iterator();
while (historyIter.hasNext() && history.size() > strategyMaxNumber) { while (historyIter.hasNext() && history.size() > strategyMaxNumber) {
if (historyIter.next() != roomSubject) { if (historyIter.next() != roomSubject) {
historyIter.remove(); historyIter.remove();
} }
} }
} }
history.addLast(packet); history.add(packet);
} }
} }
...@@ -185,8 +186,8 @@ public class HistoryStrategy { ...@@ -185,8 +186,8 @@ public class HistoryStrategy {
* *
* @return An iterator of Message objects to be sent to the new room member. * @return An iterator of Message objects to be sent to the new room member.
*/ */
public Iterator getMessageHistory(){ public Iterator<Message> getMessageHistory(){
LinkedList list = (LinkedList) history.clone(); LinkedList<Message> list = new LinkedList<Message>(history);
return list.iterator(); return list.iterator();
} }
...@@ -197,8 +198,8 @@ public class HistoryStrategy { ...@@ -197,8 +198,8 @@ public class HistoryStrategy {
* *
* @return A list iterator of Message objects positioned at the end of the list. * @return A list iterator of Message objects positioned at the end of the list.
*/ */
public ListIterator getReverseMessageHistory(){ public ListIterator<Message> getReverseMessageHistory(){
LinkedList list = (LinkedList) history.clone(); LinkedList<Message> list = new LinkedList<Message>(history);
return list.listIterator(list.size()); return list.listIterator(list.size());
} }
......
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