mirror of https://github.com/apache/activemq.git
Fix for CursorDurableTest.
The TopicStorePrefetch was iterating items that were in the subscription but not added to the pending list. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@491346 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a682e2fb2
commit
7695676339
|
@ -406,6 +406,8 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
|
||||||
pending.reset();
|
pending.reset();
|
||||||
while(pending.hasNext()&&!isFull()&&count<numberToDispatch){
|
while(pending.hasNext()&&!isFull()&&count<numberToDispatch){
|
||||||
MessageReference node=pending.next();
|
MessageReference node=pending.next();
|
||||||
|
if ( node == null )
|
||||||
|
break;
|
||||||
|
|
||||||
if(canDispatch(node)){
|
if(canDispatch(node)){
|
||||||
pending.remove();
|
pending.remove();
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.activemq.broker.region.cursors;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import javax.jms.JMSException;
|
|
||||||
import org.apache.activemq.broker.region.Destination;
|
import org.apache.activemq.broker.region.Destination;
|
||||||
import org.apache.activemq.broker.region.MessageReference;
|
import org.apache.activemq.broker.region.MessageReference;
|
||||||
import org.apache.activemq.broker.region.Topic;
|
import org.apache.activemq.broker.region.Topic;
|
||||||
|
@ -48,6 +48,10 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
|
||||||
private String subscriberName;
|
private String subscriberName;
|
||||||
private Destination regionDestination;
|
private Destination regionDestination;
|
||||||
|
|
||||||
|
boolean empty=true;
|
||||||
|
private MessageId firstMessageId;
|
||||||
|
private MessageId lastMessageId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param topic
|
* @param topic
|
||||||
* @param clientId
|
* @param clientId
|
||||||
|
@ -73,7 +77,7 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
|
||||||
* @return true if there are no pending messages
|
* @return true if there are no pending messages
|
||||||
*/
|
*/
|
||||||
public boolean isEmpty(){
|
public boolean isEmpty(){
|
||||||
return batchList.isEmpty();
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int size(){
|
public synchronized int size(){
|
||||||
|
@ -87,27 +91,55 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
|
||||||
|
|
||||||
public synchronized void addMessageLast(MessageReference node) throws Exception{
|
public synchronized void addMessageLast(MessageReference node) throws Exception{
|
||||||
if(node!=null){
|
if(node!=null){
|
||||||
|
if( empty ) {
|
||||||
|
firstMessageId = node.getMessageId();
|
||||||
|
empty=false;
|
||||||
|
}
|
||||||
|
lastMessageId = node.getMessageId();
|
||||||
node.decrementReferenceCount();
|
node.decrementReferenceCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean hasNext() {
|
public synchronized boolean hasNext() {
|
||||||
if(isEmpty()){
|
return !isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized MessageReference next(){
|
||||||
|
|
||||||
|
if( empty ) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// We may need to fill in the batch...
|
||||||
|
if(batchList.isEmpty()){
|
||||||
try{
|
try{
|
||||||
fillBatch();
|
fillBatch();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
log.error("Failed to fill batch",e);
|
log.error("Failed to fill batch",e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
if( batchList.isEmpty()) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return !isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized MessageReference next(){
|
|
||||||
Message result = (Message)batchList.removeFirst();
|
Message result = (Message)batchList.removeFirst();
|
||||||
|
|
||||||
|
if( firstMessageId != null ) {
|
||||||
|
// Skip messages until we get to the first message.
|
||||||
|
if( !result.getMessageId().equals(firstMessageId) )
|
||||||
|
return null;
|
||||||
|
firstMessageId = null;
|
||||||
|
}
|
||||||
|
if( lastMessageId != null ) {
|
||||||
|
if( result.getMessageId().equals(lastMessageId) ) {
|
||||||
|
empty=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
result.setRegionDestination(regionDestination);
|
result.setRegionDestination(regionDestination);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void reset(){
|
public void reset(){
|
||||||
}
|
}
|
||||||
|
@ -130,13 +162,7 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
protected void fillBatch() throws Exception{
|
protected void fillBatch() throws Exception{
|
||||||
store.recoverNextMessages(clientId,subscriberName,
|
store.recoverNextMessages(clientId,subscriberName,maxBatchSize,this);
|
||||||
maxBatchSize,this);
|
|
||||||
// this will add more messages to the batch list
|
|
||||||
if(!batchList.isEmpty()){
|
|
||||||
Message message=(Message)batchList.getLast();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gc() {
|
public void gc() {
|
||||||
|
|
Loading…
Reference in New Issue