activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r508721 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container: ContainerListIterator.java ContainerValueCollectionIterator.java ListContainerImpl.java
Date Sat, 17 Feb 2007 07:30:09 GMT
Author: rajdavies
Date: Fri Feb 16 23:30:08 2007
New Revision: 508721

URL: http://svn.apache.org/viewvc?view=rev&rev=508721
Log:
for getValue() ensure the StoreEntry is up to date

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerListIterator.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollectionIterator.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerListIterator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerListIterator.java?view=diff&rev=508721&r1=508720&r2=508721
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerListIterator.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerListIterator.java
Fri Feb 16 23:30:08 2007
@@ -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 @@
      * @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 @@
      * @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 @@
      * @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 @@
      * @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;
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollectionIterator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollectionIterator.java?view=diff&rev=508721&r1=508720&r2=508721
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollectionIterator.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollectionIterator.java
Fri Feb 16 23:30:08 2007
@@ -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 @@
         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 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);
+            }
         }
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java?view=diff&rev=508721&r1=508720&r2=508721
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
Fri Feb 16 23:30:08 2007
@@ -663,9 +663,10 @@
      * @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 @@
         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 @@
     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;
-    }    
 }



Mime
View raw message