synchronized around memoryTable - prevent concurrent access whilst iterating

for recovery

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@378727 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-02-18 14:43:23 +00:00
parent 068c64639f
commit 7f384b620e
2 changed files with 26 additions and 19 deletions

View File

@ -72,6 +72,8 @@ public class MemoryMessageStore implements MessageStore {
}
public void recover(MessageRecoveryListener listener) throws Throwable {
// the message table is a synchronizedMap - so just have to synchronize here
synchronized(messageTable){
for(Iterator iter=messageTable.values().iterator();iter.hasNext();){
Object msg=(Object) iter.next();
if(msg.getClass()==String.class){
@ -81,6 +83,7 @@ public class MemoryMessageStore implements MessageStore {
}
}
}
}
public void start() throws IOException {
}

View File

@ -88,9 +88,12 @@ public class MemoryTopicMessageStore extends MemoryMessageStore implements Topic
subscriberDatabase.remove(key);
}
public void recoverSubscription(String clientId, String subscriptionName, MessageRecoveryListener listener) throws Throwable {
public void recoverSubscription(String clientId,String subscriptionName,MessageRecoveryListener listener)
throws Throwable{
MessageId lastAck=(MessageId) ackDatabase.get(new SubscriptionKey(clientId,subscriptionName));
boolean pastLastAck=lastAck==null;
// the message table is a synchronizedMap - so just have to synchronize here
synchronized(messageTable){
for(Iterator iter=messageTable.entrySet().iterator();iter.hasNext();){
Map.Entry entry=(Entry) iter.next();
if(pastLastAck){
@ -105,6 +108,7 @@ public class MemoryTopicMessageStore extends MemoryMessageStore implements Topic
}
}
}
}
public void delete() {
super.delete();