for getValue() ensure the StoreEntry is up to date

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@508721 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2007-02-17 07:30:08 +00:00
parent 6ac27998aa
commit 0384cabd9d
3 changed files with 72 additions and 80 deletions

View File

@ -1,24 +1,20 @@
/** /**
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* contributor license agreements. See the NOTICE file distributed with * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* this work for additional information regarding copyright ownership. * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* The ASF licenses this file to You under the Apache License, Version 2.0 * License. You may obtain a copy of the License at
* (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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* distributed under the License is distributed on an "AS IS" BASIS, * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * specific language governing permissions and limitations under the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.apache.activemq.kaha.impl.container; package org.apache.activemq.kaha.impl.container;
import java.util.ListIterator; import java.util.ListIterator;
import org.apache.activemq.kaha.StoreEntry; import org.apache.activemq.kaha.StoreEntry;
import org.apache.activemq.kaha.impl.index.IndexItem; import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList; import org.apache.activemq.kaha.impl.index.IndexLinkedList;
@ -28,21 +24,21 @@ import org.apache.activemq.kaha.impl.index.IndexLinkedList;
*/ */
public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator{ public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator{
protected ContainerListIterator(ListContainerImpl container,IndexLinkedList list,IndexItem start){ protected ContainerListIterator(ListContainerImpl container,IndexLinkedList list,IndexItem start){
super(container,list,start); super(container,list,start);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see java.util.ListIterator#hasPrevious() * @see java.util.ListIterator#hasPrevious()
*/ */
public boolean hasPrevious(){ public boolean hasPrevious(){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
return list.getPrevEntry(nextItem)!=null; return list.getPrevEntry(nextItem)!=null;
} }
}
/* /*
* (non-Javadoc) * (non-Javadoc)
@ -50,9 +46,12 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#previous() * @see java.util.ListIterator#previous()
*/ */
public Object previous(){ public Object previous(){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
nextItem=list.getPrevEntry(nextItem); nextItem=list.getPrevEntry(nextItem);
return nextItem!=null?container.getValue(nextItem):null; return nextItem!=null?container.getValue(nextItem):null;
} }
}
/* /*
* (non-Javadoc) * (non-Javadoc)
@ -62,13 +61,14 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
public int nextIndex(){ public int nextIndex(){
int result=-1; int result=-1;
if(nextItem!=null){ if(nextItem!=null){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
StoreEntry next=list.getNextEntry(nextItem); StoreEntry next=list.getNextEntry(nextItem);
if(next!=null){ if(next!=null){
result=container.getInternalList().indexOf(next); result=container.getInternalList().indexOf(next);
} }
} }
}
return result; return result;
} }
@ -80,17 +80,17 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
public int previousIndex(){ public int previousIndex(){
int result=-1; int result=-1;
if(nextItem!=null){ if(nextItem!=null){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
StoreEntry prev=list.getPrevEntry(nextItem); StoreEntry prev=list.getPrevEntry(nextItem);
if(prev!=null){ if(prev!=null){
result=container.getInternalList().indexOf(prev); result=container.getInternalList().indexOf(prev);
} }
} }
}
return result; return result;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View File

@ -1,32 +1,30 @@
/** /**
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* contributor license agreements. See the NOTICE file distributed with * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* this work for additional information regarding copyright ownership. * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* The ASF licenses this file to You under the Apache License, Version 2.0 * License. You may obtain a copy of the License at
* (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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* distributed under the License is distributed on an "AS IS" BASIS, * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * specific language governing permissions and limitations under the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.apache.activemq.kaha.impl.container; package org.apache.activemq.kaha.impl.container;
import java.util.Iterator; import java.util.Iterator;
import org.apache.activemq.kaha.impl.index.IndexItem; import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList; import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/** /**
* Values collection iterator for the MapContainer * Values collection iterator for the MapContainer
* *
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */
public class ContainerValueCollectionIterator implements Iterator{ public class ContainerValueCollectionIterator implements Iterator{
protected BaseContainerImpl container; protected BaseContainerImpl container;
protected IndexLinkedList list; protected IndexLinkedList list;
protected IndexItem nextItem; protected IndexItem nextItem;
@ -36,7 +34,7 @@ public class ContainerValueCollectionIterator implements Iterator{
this.container=container; this.container=container;
this.list=list; this.list=list;
this.currentItem=start; this.currentItem=start;
this.nextItem=list.getNextEntry(start); this.nextItem=list.getNextEntry((IndexItem)list.refreshEntry(start));
} }
public boolean hasNext(){ public boolean hasNext(){
@ -44,15 +42,21 @@ public class ContainerValueCollectionIterator implements Iterator{
} }
public Object next(){ public Object next(){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
currentItem=nextItem; currentItem=nextItem;
Object result=container.getValue(nextItem); Object result=container.getValue(nextItem);
nextItem=list.getNextEntry(nextItem); nextItem=list.getNextEntry(nextItem);
return result; return result;
} }
}
public void remove(){ public void remove(){
synchronized(container){
if(currentItem!=null){ if(currentItem!=null){
currentItem=(IndexItem)list.refreshEntry(currentItem);
container.remove(currentItem); container.remove(currentItem);
} }
} }
} }
}

View File

@ -663,9 +663,10 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine
* @param entry * @param entry
* @return the Object at that entry * @return the Object at that entry
*/ */
public synchronized Object get(StoreEntry entry){ public synchronized Object get(final StoreEntry entry){
load(); load();
return getValue(entry); StoreEntry entryToUse = refresh(entry);
return getValue(entryToUse);
} }
/** /**
@ -835,9 +836,7 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine
Object result=null; Object result=null;
if(item!=null){ if(item!=null){
try{ try{
// ensure it's up to date StoreLocation data=item.getValueDataItem();
StoreEntry itemToUse=indexList.getEntry(item);
StoreLocation data=itemToUse.getValueDataItem();
result=dataManager.readItem(marshaller,data); result=dataManager.readItem(marshaller,data);
}catch(IOException e){ }catch(IOException e){
log.error("Failed to get value for "+item,e); log.error("Failed to get value for "+item,e);
@ -873,15 +872,4 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine
protected synchronized void itemRemoved(int pos){ protected synchronized void itemRemoved(int pos){
} }
protected synchronized Object getCachedItem(int pos){
Object result=null;
IndexItem item=indexList.get(pos);
if(item!=null){
result=getValue(item);
}
return result;
}
} }