https://issues.apache.org/jira/browse/AMQ-3379 - unique property eviction strategy - remove oldest if there's no duplicates

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1141033 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2011-06-29 10:11:25 +00:00
parent 7539c7e975
commit a798c85535
2 changed files with 8 additions and 3 deletions

View File

@ -175,7 +175,7 @@ public class TopicSubscription extends AbstractSubscription {
// eviction strategy
// for a bad strategy lets just not evict
if (messagesToEvict == 0) {
LOG.warn("No messages to evict returned from eviction strategy: " + messageEvictionStrategy);
LOG.warn("No messages to evict returned for " + destination + " from eviction strategy: " + messageEvictionStrategy + " out of " + list.size() + " candidates");
break;
}
}

View File

@ -17,6 +17,8 @@
package org.apache.activemq.broker.region.policy;
import org.apache.activemq.broker.region.MessageReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
@ -35,6 +37,8 @@ import java.util.LinkedList;
*/
public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrategySupport {
private static final Logger LOG = LoggerFactory.getLogger(UniquePropertyMessageEvictionStrategy.class);
protected String propertyName;
public String getPropertyName() {
@ -47,6 +51,7 @@ public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrate
@Override
public MessageReference[] evictMessages(LinkedList messages) throws IOException {
MessageReference oldest = (MessageReference)messages.getFirst();
HashMap<Object, MessageReference> pivots = new HashMap<Object, MessageReference>();
Iterator iter = messages.iterator();
@ -69,12 +74,12 @@ public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrate
for (MessageReference ref : pivots.values()) {
messages.remove(ref);
}
if (messages.size() != 0) {
return (MessageReference[])messages.toArray(new MessageReference[messages.size()]);
}
}
return new MessageReference[] {(MessageReference) messages.removeFirst()};
return new MessageReference[] {oldest};
}
}