tighten up on message reference counting

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@509563 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2007-02-20 13:59:41 +00:00
parent 8de60cf980
commit c46003fd3b
3 changed files with 103 additions and 98 deletions

View File

@ -42,7 +42,7 @@ class QueueStorePrefetch extends AbstractPendingMessageCursor implements
static private final Log log=LogFactory.getLog(QueueStorePrefetch.class);
private MessageStore store;
private final LinkedList batchList=new LinkedList();
private final LinkedList <Message>batchList=new LinkedList<Message>();
private Destination regionDestination;
private int size = 0;
@ -123,7 +123,7 @@ class QueueStorePrefetch extends AbstractPendingMessageCursor implements
}
public synchronized MessageReference next(){
Message result = (Message)batchList.removeFirst();
Message result = batchList.removeFirst();
result.setRegionDestination(regionDestination);
return result;
}
@ -137,7 +137,10 @@ class QueueStorePrefetch extends AbstractPendingMessageCursor implements
public void recoverMessage(Message message) throws Exception{
message.setRegionDestination(regionDestination);
// only increment if count is zero (could have been cached)
if(message.getReferenceCount()==0){
message.incrementReferenceCount();
}
batchList.addLast(message);
}
@ -153,6 +156,9 @@ class QueueStorePrefetch extends AbstractPendingMessageCursor implements
}
public void gc() {
for (Message msg:batchList) {
msg.decrementReferenceCount();
}
batchList.clear();
}

View File

@ -42,7 +42,7 @@ public class StoreDurableSubscriberCursor extends AbstractPendingMessageCursor{
private String clientId;
private String subscriberName;
private Map topics=new HashMap();
private LinkedList storePrefetches=new LinkedList();
private LinkedList <PendingMessageCursor>storePrefetches=new LinkedList<PendingMessageCursor>();
private boolean started;
private PendingMessageCursor nonPersistent;
private PendingMessageCursor currentCursor;
@ -61,22 +61,25 @@ public class StoreDurableSubscriberCursor extends AbstractPendingMessageCursor{
}
public synchronized void start() throws Exception{
if(!started){
started=true;
for(Iterator i=storePrefetches.iterator();i.hasNext();){
PendingMessageCursor tsp=(PendingMessageCursor)i.next();
for(PendingMessageCursor tsp: storePrefetches){
tsp.start();
pendingCount+=tsp.size();
}
}
}
public synchronized void stop() throws Exception{
if(started){
started=false;
for(Iterator i=storePrefetches.iterator();i.hasNext();){
PendingMessageCursor tsp=(PendingMessageCursor)i.next();
for(PendingMessageCursor tsp: storePrefetches){
tsp.stop();
}
pendingCount=0;
}
}
/**
* Add a destination
@ -140,7 +143,6 @@ public class StoreDurableSubscriberCursor extends AbstractPendingMessageCursor{
return false;
}
public synchronized void addMessageLast(MessageReference node) throws Exception{
if(node!=null){
Message msg=node.getMessage();
@ -183,7 +185,8 @@ public class StoreDurableSubscriberCursor extends AbstractPendingMessageCursor{
}
public synchronized MessageReference next(){
return currentCursor!=null?currentCursor.next():null;
MessageReference result = currentCursor!=null?currentCursor.next():null;
return result;
}
public synchronized void remove(){
@ -256,4 +259,8 @@ public class StoreDurableSubscriberCursor extends AbstractPendingMessageCursor{
}
return currentCursor;
}
public String toString(){
return "StoreDurableSubscriber("+clientId+":"+subscriberName+")";
}
}

View File

@ -1,26 +1,21 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.apache.activemq.broker.region.cursors;
import java.io.IOException;
import java.util.LinkedList;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.MessageReference;
import org.apache.activemq.broker.region.Topic;
@ -32,22 +27,18 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* perist pending messages pending message (messages awaiting disptach to a
* consumer) cursor
* perist pending messages pending message (messages awaiting disptach to a consumer) cursor
*
* @version $Revision$
*/
class TopicStorePrefetch extends AbstractPendingMessageCursor implements
MessageRecoveryListener {
class TopicStorePrefetch extends AbstractPendingMessageCursor implements MessageRecoveryListener{
static private final Log log=LogFactory.getLog(TopicStorePrefetch.class);
private TopicMessageStore store;
private final LinkedList batchList=new LinkedList();
private final LinkedList<Message> batchList=new LinkedList<Message>();
private String clientId;
private String subscriberName;
private Destination regionDestination;
boolean empty;
private MessageId firstMessageId;
private MessageId lastMessageId;
@ -114,16 +105,12 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
}
public synchronized MessageReference next(){
if( empty ) {
return null;
} else {
// We may need to fill in the batch...
Message result=null;
if(!empty){
if(batchList.isEmpty()){
try{
fillBatch();
}catch(Exception e){
}catch(final Exception e){
log.error("Failed to fill batch",e);
throw new RuntimeException(e);
}
@ -131,24 +118,25 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
return null;
}
}
Message result = (Message)batchList.removeFirst();
if(!batchList.isEmpty()){
result=batchList.removeFirst();
if(firstMessageId!=null){
// Skip messages until we get to the first message.
if(!result.getMessageId().equals(firstMessageId))
return null;
result=null;
firstMessageId=null;
}
}else{
if(lastMessageId!=null){
if(result.getMessageId().equals(lastMessageId)){
empty=true;
}
}
result.setRegionDestination(regionDestination);
return result;
}
}
}
return result;
}
public void reset(){
}
@ -159,12 +147,14 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
public void recoverMessage(Message message) throws Exception{
message.setRegionDestination(regionDestination);
// only increment if count is zero (could have been cached)
if(message.getReferenceCount()==0){
message.incrementReferenceCount();
}
batchList.addLast(message);
}
public void recoverMessageReference(MessageId messageReference)
throws Exception{
public void recoverMessageReference(MessageId messageReference) throws Exception{
// shouldn't get called
throw new RuntimeException("Not supported");
}
@ -175,11 +165,13 @@ class TopicStorePrefetch extends AbstractPendingMessageCursor implements
}
public void gc(){
for(Message msg:batchList){
msg.decrementReferenceCount();
}
batchList.clear();
}
public String toString(){
return "TopicStorePrefetch"+System.identityHashCode(this)+"("+clientId+","+subscriberName+")";
}
}