You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2007/01/25 17:20:45 UTC

svn commit: r499827 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/kaha/ main/java/org/apache/activemq/kaha/impl/container/ main/java/org/apache/activemq/store/kahadaptor/ main/java/org/apache/activemq/store/rapid/ test...

Author: rajdavies
Date: Thu Jan 25 08:20:42 2007
New Revision: 499827

URL: http://svn.apache.org/viewvc?view=rev&rev=499827
Log:
remove the caching (as was causing memory leaks) in the ListContainer

Added:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MessageIdMarshaller.java   (with props)
Removed:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/CachedContainerListIterator.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/CachedListContainerImplTest.java
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/rapid/RapidPersistenceAdapter.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java?view=diff&rev=499827&r1=499826&r2=499827
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java Thu Jan 25 08:20:42 2007
@@ -99,21 +99,6 @@
     public boolean doRemove(int position);
 
     /**
-     * @return the maximumCacheSize
-     */
-    public int getMaximumCacheSize();
-
-    /**
-     * @param maximumCacheSize the maximumCacheSize to set
-     */
-    public void setMaximumCacheSize(int maximumCacheSize);
-
-    /**
-     * clear any cached values
-     */
-    public void clearCache();
-
-    /**
      * add an Object to the list but get a StoreEntry of its position
      * 
      * @param object

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java?view=diff&rev=499827&r1=499826&r2=499827
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java Thu Jan 25 08:20:42 2007
@@ -43,11 +43,7 @@
 
     private static final Log log=LogFactory.getLog(ListContainerImpl.class);
     protected Marshaller marshaller=Store.ObjectMarshaller;
-    protected LinkedList cacheList=new LinkedList();
-    protected int offset=0;
-    protected int maximumCacheSize=100;
-    protected IndexItem lastCached;
-    protected boolean cacheEnabled = true;
+   
 
     public ListContainerImpl(ContainerId id,IndexItem root,IndexManager indexManager,DataManager dataManager,
             String indexType) throws IOException{
@@ -91,7 +87,7 @@
         if(loaded){
             loaded=false;
             indexList.clear();
-            clearCache();
+            
         }
     }
 
@@ -406,7 +402,7 @@
         checkClosed();
         super.clear();
         doClear();
-        clearCache();
+        
     }
 
     /*
@@ -416,7 +412,12 @@
      */
     public synchronized Object get(int index){
         load();
-        return getCachedItem(index);
+        Object result = null;
+        IndexItem item=indexList.get(index);
+        if(item!=null){
+            result=getValue(item);
+        }
+        return result;
     }
 
     /*
@@ -589,7 +590,8 @@
      */
     public synchronized ListIterator listIterator(){
         load();
-        return new CachedContainerListIterator(this,0);
+        IndexItem start= indexList.getFirst();
+        return new ContainerListIterator(this,indexList,indexList.getRoot());
     }
 
     /*
@@ -599,7 +601,8 @@
      */
     public synchronized ListIterator listIterator(int index){
         load();
-        return new CachedContainerListIterator(this,index);
+        IndexItem start = (index-1) >0 ?indexList.get(index-1):indexList.getRoot();
+        return new ContainerListIterator(this,indexList,start);
     }
 
     /*
@@ -676,7 +679,7 @@
         load();
         boolean result=false;
         if(item!=null){
-            clearCache();
+           
             remove(item);
             result = true;
         }
@@ -864,156 +867,21 @@
     }
 
     protected synchronized void itemAdded(IndexItem item,int pos,Object value){
-        if(cacheEnabled){
-            int cachePosition=pos-offset;
-            // if pos is before the cache offset
-            // we need to clear the cache
-            if(pos<offset){
-                clearCache();
-            }
-            if(cacheList.isEmpty()){
-                offset=pos;
-                cacheList.add(value);
-                lastCached=item;
-            }else if(cachePosition==cacheList.size()&&cachePosition<maximumCacheSize){
-                cacheList.add(value);
-                lastCached=item;
-            }else if(cachePosition>=0&&cachePosition<=cacheList.size()){
-                cacheList.add(cachePosition,value);
-                if(cacheList.size()>maximumCacheSize){
-                    itemRemoved(cacheList.size()-1);
-                }
-            }
-        }
+        
     }
 
     protected synchronized void itemRemoved(int pos){
-        if(cacheEnabled){
-            int lastPosition=offset+cacheList.size()-1;
-            int cachePosition=pos-offset;
-            if(cachePosition>=0&&cachePosition<cacheList.size()){
-                if(cachePosition==lastPosition){
-                    if(lastCached!=null){
-                        lastCached=indexList.getPrevEntry(lastCached);
-                    }
-                }
-                cacheList.remove(pos);
-                if(cacheList.isEmpty()){
-                    clearCache();
-                }
-            }
-        }
+        
     }
 
     protected synchronized Object getCachedItem(int pos){
         Object result=null;
-        if(cacheEnabled) {
-        int cachePosition=pos-offset;
-        if(cachePosition>=0&&cachePosition<cacheList.size()){
-            result=cacheList.get(cachePosition);
-        }
-        if(result==null){
-            if(cachePosition==cacheList.size()&&lastCached!=null){
-                IndexItem item=indexList.getNextEntry(lastCached);
-                if(item!=null){
-                    result=getValue(item);
-                    cacheList.add(result);
-                    lastCached=item;
-                    if(cacheList.size()>maximumCacheSize){
-                        itemRemoved(0);
-                    }
-                }
-            }else{
-                IndexItem item=indexList.get(pos);
-                if(item!=null){
-                    result=getValue(item);
-                    if(result!=null){
-                        // outside the cache window - so clear
-                        if(!cacheList.isEmpty()){
-                            clearCache();
-                        }
-                        offset=pos;
-                        cacheList.add(result);
-                        lastCached=item;
-                    }
-                }
-            }
-        }
-        }else {
+        
             IndexItem item=indexList.get(pos);
             if(item!=null){
                 result=getValue(item);
             }
-        }
+       
         return result;
-    }
-
-    /**
-     * clear any cached values
-     */
-    public synchronized void clearCache(){
-        cacheList.clear();
-        offset=0;
-        lastCached=null;
-    }
-
-    /**
-     * @return the cacheList
-     */
-    public synchronized LinkedList getCacheList(){
-        return cacheList;
-    }
-
-    /**
-     * @param cacheList the cacheList to set
-     */
-    public synchronized void setCacheList(LinkedList cacheList){
-        this.cacheList=cacheList;
-    }
-
-    /**
-     * @return the lastCached
-     */
-    public synchronized StoreEntry getLastCached(){
-        return lastCached;
-    }
-
-    /**
-     * @param lastCached the lastCached to set
-     */
-    public synchronized void setLastCached(IndexItem lastCached){
-        this.lastCached=lastCached;
-    }
-
-    /**
-     * @return the maximumCacheSize
-     */
-    public synchronized int getMaximumCacheSize(){
-        return maximumCacheSize;
-    }
-
-    /**
-     * @param maximumCacheSize the maximumCacheSize to set
-     */
-    public synchronized void setMaximumCacheSize(int maximumCacheSize){
-        this.maximumCacheSize=maximumCacheSize;
-        cacheEnabled = maximumCacheSize >= 0;
-        if (!cacheEnabled) {
-            clearCache();
-        }
-    }
-
-    /**
-     * @return the offset
-     */
-    public synchronized int getOffset(){
-        return offset;
-    }
-
-    /**
-     * @param offset the offset to set
-     */
-    public synchronized void setOffset(int offset){
-        this.offset=offset;
-    }
+    }    
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java?view=diff&rev=499827&r1=499826&r2=499827
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java Thu Jan 25 08:20:42 2007
@@ -188,7 +188,6 @@
 	protected ListContainer getListContainer(Object id,String containerName) throws IOException{
         Store store=getStore();
         ListContainer container=store.getListContainer(id,containerName);
-        container.setMaximumCacheSize(0);
         container.setMarshaller(createMessageMarshaller());        
         container.load();
         return container;

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MessageIdMarshaller.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MessageIdMarshaller.java?view=auto&rev=499827
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MessageIdMarshaller.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MessageIdMarshaller.java Thu Jan 25 08:20:42 2007
@@ -0,0 +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
+ *
+ * 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.
+ */
+package org.apache.activemq.store.kahadaptor;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import org.apache.activemq.command.MessageId;
+import org.apache.activemq.kaha.Marshaller;
+
+
+/**
+ * Marshall an AtomicInteger
+ * @version $Revision: 1.10 $
+ */
+public class MessageIdMarshaller implements Marshaller<MessageId>{
+   
+
+    public void writePayload(MessageId mid,DataOutput dataOut) throws IOException{
+       dataOut.writeUTF(mid.toString());
+       
+    }
+
+    public MessageId readPayload(DataInput dataIn) throws IOException{
+        String str = dataIn.readUTF();
+        return new MessageId(str);
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MessageIdMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/rapid/RapidPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/rapid/RapidPersistenceAdapter.java?view=diff&rev=499827&r1=499826&r2=499827
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/rapid/RapidPersistenceAdapter.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/rapid/RapidPersistenceAdapter.java Thu Jan 25 08:20:42 2007
@@ -179,7 +179,6 @@
     protected ListContainer getListContainer(Object id,String containerName) throws IOException{
         Store store=getStore();
         ListContainer container=store.getListContainer(id,containerName);
-        container.setMaximumCacheSize(0);
         container.setMarshaller(new RapidMessageReferenceMarshaller());
         container.load();
         return container;