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
* 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.kaha.impl.container;
import java.util.ListIterator;
import org.apache.activemq.kaha.StoreEntry;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/**
* @version $Revision: 1.2 $
*/
* @version $Revision: 1.2 $
*/
public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator{
protected ContainerListIterator(ListContainerImpl container,IndexLinkedList list,IndexItem start){
super(container,list,start);
super(container,list,start);
}
/*
* (non-Javadoc)
*
* @see java.util.ListIterator#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()
*/
public Object previous(){
nextItem = list.getPrevEntry(nextItem);
return nextItem != null ? container.getValue(nextItem) : null;
synchronized(container){
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()
*/
public int nextIndex(){
int result = -1;
if (nextItem != null){
StoreEntry next = list.getNextEntry(nextItem);
if (next != null){
result = container.getInternalList().indexOf(next);
int result=-1;
if(nextItem!=null){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
StoreEntry next=list.getNextEntry(nextItem);
if(next!=null){
result=container.getInternalList().indexOf(next);
}
}
}
return result;
}
@ -78,26 +78,26 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#previousIndex()
*/
public int previousIndex(){
int result = -1;
if (nextItem != null){
StoreEntry prev = list.getPrevEntry(nextItem);
if (prev != null){
result = container.getInternalList().indexOf(prev);
int result=-1;
if(nextItem!=null){
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
StoreEntry prev=list.getPrevEntry(nextItem);
if(prev!=null){
result=container.getInternalList().indexOf(prev);
}
}
}
return result;
}
/*
* (non-Javadoc)
*
* @see java.util.ListIterator#set(E)
*/
public void set(Object o){
IndexItem item=((ListContainerImpl) container).internalSet(previousIndex()+1,o);
IndexItem item=((ListContainerImpl)container).internalSet(previousIndex()+1,o);
nextItem=item;
}
@ -107,7 +107,7 @@ public class ContainerListIterator extends ContainerValueCollectionIterator impl
* @see java.util.ListIterator#add(E)
*/
public void add(Object o){
IndexItem item=((ListContainerImpl) container).internalAdd(previousIndex()+1,o);
IndexItem item=((ListContainerImpl)container).internalAdd(previousIndex()+1,o);
nextItem=item;
}
}

View File

@ -1,32 +1,30 @@
/**
*
* 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.kaha.impl.container;
import java.util.Iterator;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/**
* Values collection iterator for the MapContainer
*
* @version $Revision: 1.2 $
*/
public class ContainerValueCollectionIterator implements Iterator{
protected BaseContainerImpl container;
protected IndexLinkedList list;
protected IndexItem nextItem;
@ -36,7 +34,7 @@ public class ContainerValueCollectionIterator implements Iterator{
this.container=container;
this.list=list;
this.currentItem=start;
this.nextItem=list.getNextEntry(start);
this.nextItem=list.getNextEntry((IndexItem)list.refreshEntry(start));
}
public boolean hasNext(){
@ -44,15 +42,21 @@ public class ContainerValueCollectionIterator implements Iterator{
}
public Object next(){
currentItem=nextItem;
Object result=container.getValue(nextItem);
nextItem=list.getNextEntry(nextItem);
return result;
synchronized(container){
nextItem=(IndexItem)list.refreshEntry(nextItem);
currentItem=nextItem;
Object result=container.getValue(nextItem);
nextItem=list.getNextEntry(nextItem);
return result;
}
}
public void remove(){
if(currentItem!=null){
container.remove(currentItem);
synchronized(container){
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
* @return the Object at that entry
*/
public synchronized Object get(StoreEntry entry){
public synchronized Object get(final StoreEntry entry){
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;
if(item!=null){
try{
// ensure it's up to date
StoreEntry itemToUse=indexList.getEntry(item);
StoreLocation data=itemToUse.getValueDataItem();
StoreLocation data=item.getValueDataItem();
result=dataManager.readItem(marshaller,data);
}catch(IOException 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 Object getCachedItem(int pos){
Object result=null;
IndexItem item=indexList.get(pos);
if(item!=null){
result=getValue(item);
}
return result;
}
}