mirror of https://github.com/apache/activemq.git
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:
parent
7539c7e975
commit
a798c85535
|
@ -175,7 +175,7 @@ public class TopicSubscription extends AbstractSubscription {
|
||||||
// eviction strategy
|
// eviction strategy
|
||||||
// for a bad strategy lets just not evict
|
// for a bad strategy lets just not evict
|
||||||
if (messagesToEvict == 0) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package org.apache.activemq.broker.region.policy;
|
package org.apache.activemq.broker.region.policy;
|
||||||
|
|
||||||
import org.apache.activemq.broker.region.MessageReference;
|
import org.apache.activemq.broker.region.MessageReference;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -35,6 +37,8 @@ import java.util.LinkedList;
|
||||||
*/
|
*/
|
||||||
public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrategySupport {
|
public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrategySupport {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(UniquePropertyMessageEvictionStrategy.class);
|
||||||
|
|
||||||
protected String propertyName;
|
protected String propertyName;
|
||||||
|
|
||||||
public String getPropertyName() {
|
public String getPropertyName() {
|
||||||
|
@ -47,6 +51,7 @@ public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrate
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageReference[] evictMessages(LinkedList messages) throws IOException {
|
public MessageReference[] evictMessages(LinkedList messages) throws IOException {
|
||||||
|
MessageReference oldest = (MessageReference)messages.getFirst();
|
||||||
HashMap<Object, MessageReference> pivots = new HashMap<Object, MessageReference>();
|
HashMap<Object, MessageReference> pivots = new HashMap<Object, MessageReference>();
|
||||||
Iterator iter = messages.iterator();
|
Iterator iter = messages.iterator();
|
||||||
|
|
||||||
|
@ -69,12 +74,12 @@ public class UniquePropertyMessageEvictionStrategy extends MessageEvictionStrate
|
||||||
for (MessageReference ref : pivots.values()) {
|
for (MessageReference ref : pivots.values()) {
|
||||||
messages.remove(ref);
|
messages.remove(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messages.size() != 0) {
|
if (messages.size() != 0) {
|
||||||
return (MessageReference[])messages.toArray(new MessageReference[messages.size()]);
|
return (MessageReference[])messages.toArray(new MessageReference[messages.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new MessageReference[] {oldest};
|
||||||
return new MessageReference[] {(MessageReference) messages.removeFirst()};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue