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,47 +1,43 @@
/** /**
* *
* 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;
/** /**
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */
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(){
return list.getPrevEntry(nextItem) != null; synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
return list.getPrevEntry(nextItem)!=null;
}
} }
/* /*
@ -50,8 +46,11 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#previous() * @see java.util.ListIterator#previous()
*/ */
public Object previous(){ public Object previous(){
nextItem = list.getPrevEntry(nextItem); synchronized(container){
return nextItem != null ? container.getValue(nextItem) : null; nextItem=(IndexItem)list.refreshEntry(nextItem);
nextItem=list.getPrevEntry(nextItem);
return nextItem!=null?container.getValue(nextItem):null;
}
} }
/* /*
@ -60,15 +59,16 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#nextIndex() * @see java.util.ListIterator#nextIndex()
*/ */
public int nextIndex(){ public int nextIndex(){
int result = -1; int result=-1;
if (nextItem != null){ if(nextItem!=null){
StoreEntry next = list.getNextEntry(nextItem); synchronized(container){
if (next != null){ nextItem=(IndexItem)list.refreshEntry(nextItem);
result = container.getInternalList().indexOf(next); StoreEntry next=list.getNextEntry(nextItem);
if(next!=null){
result=container.getInternalList().indexOf(next);
}
} }
} }
return result; return result;
} }
@ -78,26 +78,26 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#previousIndex() * @see java.util.ListIterator#previousIndex()
*/ */
public int previousIndex(){ public int previousIndex(){
int result = -1; int result=-1;
if (nextItem != null){ if(nextItem!=null){
StoreEntry prev = list.getPrevEntry(nextItem); synchronized(container){
if (prev != null){ nextItem=(IndexItem)list.refreshEntry(nextItem);
result = container.getInternalList().indexOf(prev); StoreEntry prev=list.getPrevEntry(nextItem);
if(prev!=null){
result=container.getInternalList().indexOf(prev);
}
} }
} }
return result; return result;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see java.util.ListIterator#set(E) * @see java.util.ListIterator#set(E)
*/ */
public void set(Object o){ public void set(Object o){
IndexItem item=((ListContainerImpl) container).internalSet(previousIndex()+1,o); IndexItem item=((ListContainerImpl)container).internalSet(previousIndex()+1,o);
nextItem=item; nextItem=item;
} }
@ -107,7 +107,7 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#add(E) * @see java.util.ListIterator#add(E)
*/ */
public void add(Object o){ public void add(Object o){
IndexItem item=((ListContainerImpl) container).internalAdd(previousIndex()+1,o); IndexItem item=((ListContainerImpl)container).internalAdd(previousIndex()+1,o);
nextItem=item; nextItem=item;
} }
} }

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(){
currentItem=nextItem; synchronized(container){
Object result=container.getValue(nextItem); nextItem=(IndexItem)list.refreshEntry(nextItem);
nextItem=list.getNextEntry(nextItem); currentItem=nextItem;
return result; Object result=container.getValue(nextItem);
nextItem=list.getNextEntry(nextItem);
return result;
}
} }
public void remove(){ public void remove(){
if(currentItem!=null){ synchronized(container){
container.remove(currentItem); if(currentItem!=null){
currentItem=(IndexItem)list.refreshEntry(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;
}
} }