activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r503177 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/cursors/ main/java/org/apache/activemq/kaha/ main/java/org/apache/activemq/kaha/impl/ main/java/org/apache/activemq/kaha/impl/container/ main/java/o...
Date Sat, 03 Feb 2007 07:24:11 GMT
Author: rajdavies
Date: Fri Feb  2 23:24:10 2007
New Revision: 503177

URL: http://svn.apache.org/viewvc?view=rev&rev=503177
Log:
Tidy up the choice of Index types for the Map and List container

Removed:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/IndexTypes.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPageInfo.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/Loader.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/MapContainerTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
Fri Feb  2 23:24:10 2007
@@ -22,7 +22,6 @@
 import org.apache.activemq.broker.region.Destination;
 import org.apache.activemq.broker.region.MessageReference;
 import org.apache.activemq.command.Message;
-import org.apache.activemq.kaha.IndexTypes;
 import org.apache.activemq.kaha.ListContainer;
 import org.apache.activemq.kaha.Store;
 import org.apache.activemq.memory.UsageListener;
@@ -279,7 +278,7 @@
     protected ListContainer getDiskList(){
         if(diskList==null){
             try{
-                diskList=store.getListContainer(name,"TopicSubscription",IndexTypes.DISK_INDEX);
+                diskList=store.getListContainer(name,"TopicSubscription",Store.IndexType.PERSISTENT);
                 diskList.setMarshaller(new CommandMarshaller(new OpenWireFormat()));
             }catch(IOException e){
                 e.printStackTrace();

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java Fri Feb
 2 23:24:10 2007
@@ -25,8 +25,26 @@
  * @version $Revision: 1.2 $
  */
 public interface Store{
+    /**
+     * Defauly container name
+     */
+    public static final String DEFAULT_CONTAINER_NAME="kaha";
     
     /**
+     * Index Types
+     *
+     */
+    public static enum IndexType{
+        /**
+         * Map Index held in memory
+         */
+        VM,
+        /**
+         * Map index persistent
+         */
+        PERSISTENT
+    }
+    /**
      * Byte Marshaller
      */
     public final static Marshaller BytesMarshaller = new BytesMarshaller();
@@ -116,7 +134,7 @@
      * @return container for the associated id or null if it doesn't exist
      * @throws IOException
      */
-    public MapContainer getMapContainer(Object id,String containerName,String indexType)
throws IOException;
+    public MapContainer getMapContainer(Object id,String containerName,Store.IndexType indexType)
throws IOException;
 
     /**
      * delete a container from the default container
@@ -190,7 +208,7 @@
      * @return container for the associated id or null if it doesn't exist
      * @throws IOException
      */
-    public ListContainer getListContainer(Object id,String containerName,String indexType)
throws IOException;
+    public ListContainer getListContainer(Object id,String containerName,Store.IndexType
indexType) throws IOException;
 
     /**
      * delete a ListContainer from the default container
@@ -232,14 +250,14 @@
      * @see org.apache.activemq.kaha.IndexTypes
      * @return the default index type
      */
-    public String getIndexType();
+    public String getIndexTypeAsString();
     
     /**
      * Set the default index type
      * @param type
      * @see org.apache.activemq.kaha.IndexTypes
      */
-    public void setIndexType(String type);
+    public void setIndexTypeAsString(String type);
     
     /**
      * @return true if the store has been initialized

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
Fri Feb  2 23:24:10 2007
@@ -27,7 +27,6 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import org.apache.activemq.kaha.IndexTypes;
 import org.apache.activemq.kaha.ListContainer;
 import org.apache.activemq.kaha.MapContainer;
 import org.apache.activemq.kaha.RuntimeStoreException;
@@ -35,7 +34,6 @@
 import org.apache.activemq.kaha.StoreLocation;
 import org.apache.activemq.kaha.impl.async.AsyncDataManager;
 import org.apache.activemq.kaha.impl.async.DataManagerFacade;
-import org.apache.activemq.kaha.impl.container.BaseContainerImpl;
 import org.apache.activemq.kaha.impl.container.ContainerId;
 import org.apache.activemq.kaha.impl.container.ListContainerImpl;
 import org.apache.activemq.kaha.impl.container.MapContainerImpl;
@@ -56,7 +54,7 @@
 public class KahaStore implements Store{
 
     private static final String LOCK_FILE_NAME="store.lock";
-    private static final String DEFAULT_CONTAINER_NAME="kaha";
+    
     private final static String PROPERTY_PREFIX="org.apache.activemq.kaha.Store";
     private final static boolean brokenFileLock="true".equals(System.getProperty(PROPERTY_PREFIX+".broken","false"));
     private final static boolean disableLocking="true".equals(System.getProperty(PROPERTY_PREFIX+"DisableLocking",
@@ -78,7 +76,7 @@
     private boolean useAsyncDataManager=false;
     private long maxDataFileLength=1024*1024*32;
     private FileLock lock;
-    private String indexType=IndexTypes.DISK_INDEX;
+    private IndexType indexType=IndexType.PERSISTENT;
 
     public KahaStore(String name,String mode) throws IOException{
         this.mode=mode;
@@ -188,7 +186,7 @@
         return getMapContainer(id,containerName,indexType);
     }
 
-    public synchronized MapContainer getMapContainer(Object id,String containerName,String
indexType)
+    public synchronized MapContainer getMapContainer(Object id,String containerName,IndexType
indexType)
             throws IOException{
         initialize();
         ContainerId containerId=new ContainerId();
@@ -254,7 +252,7 @@
         return getListContainer(id,containerName,indexType);
     }
 
-    public synchronized ListContainer getListContainer(Object id,String containerName,String
indexType)
+    public synchronized ListContainer getListContainer(Object id,String containerName,IndexType
indexType)
             throws IOException{
         initialize();
         ContainerId containerId=new ContainerId();
@@ -388,8 +386,8 @@
      * @see org.apache.activemq.kaha.IndexTypes
      * @return the default index type
      */
-    public synchronized String getIndexType(){
-        return indexType;
+    public synchronized String getIndexTypeAsString(){
+        return indexType==IndexType.PERSISTENT ? "PERSISTENT":"VM";
     }
 
     /**
@@ -398,11 +396,12 @@
      * @param type
      * @see org.apache.activemq.kaha.IndexTypes
      */
-    public synchronized void setIndexType(String type){
-        if(type==null||(!type.equals(IndexTypes.DISK_INDEX)&&!type.equals(IndexTypes.IN_MEMORY_INDEX))){
-            throw new RuntimeException("Unknown IndexType: "+type);
+    public synchronized void setIndexTypeAsString(String type){
+        if(type.equalsIgnoreCase("VM")){
+            indexType=IndexType.VM;
+        }else{
+            indexType=IndexType.PERSISTENT;
         }
-        this.indexType=type;
     }
     
     public synchronized void initialize() throws IOException{

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java
Fri Feb  2 23:24:10 2007
@@ -21,8 +21,8 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import org.apache.activemq.kaha.IndexTypes;
 import org.apache.activemq.kaha.RuntimeStoreException;
+import org.apache.activemq.kaha.Store;
 import org.apache.activemq.kaha.StoreEntry;
 import org.apache.activemq.kaha.impl.DataManager;
 import org.apache.activemq.kaha.impl.data.Item;
@@ -50,18 +50,15 @@
     protected boolean loaded=false;
     protected boolean closed=false;
     protected boolean initialized=false;
-    protected String indexType;
+    protected Store.IndexType indexType;
 
     protected BaseContainerImpl(ContainerId id,IndexItem root,IndexManager indexManager,
-            DataManager dataManager,String indexType){
+            DataManager dataManager,Store.IndexType indexType){
         this.containerId=id;
         this.root=root;
         this.indexManager=indexManager;
         this.dataManager=dataManager;
         this.indexType = indexType;
-        if (indexType == null || (!indexType.equals(IndexTypes.DISK_INDEX) && !indexType.equals(IndexTypes.IN_MEMORY_INDEX)))
{
-            throw new RuntimeException("Unknown IndexType: " + indexType);
-        }
     }
 
     public ContainerId getContainerId(){
@@ -73,7 +70,7 @@
             if(!initialized){
                 initialized=true;
                 if(this.indexList==null){
-                    if(indexType.equals(IndexTypes.DISK_INDEX)){
+                    if(indexType.equals(Store.IndexType.PERSISTENT)){
                         this.indexList=new DiskIndexLinkedList(indexManager,root);
                     }else{
                         this.indexList=new VMIndexLinkedList(root);

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=503177&r1=503176&r2=503177
==============================================================================
--- 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  2 23:24:10 2007
@@ -46,7 +46,7 @@
    
 
     public ListContainerImpl(ContainerId id,IndexItem root,IndexManager indexManager,DataManager
dataManager,
-            String indexType) throws IOException{
+            Store.IndexType indexType) throws IOException{
         super(id,root,indexManager,dataManager,indexType);
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java
Fri Feb  2 23:24:10 2007
@@ -20,7 +20,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import org.apache.activemq.kaha.IndexTypes;
 import org.apache.activemq.kaha.MapContainer;
 import org.apache.activemq.kaha.Marshaller;
 import org.apache.activemq.kaha.RuntimeStoreException;
@@ -52,7 +51,7 @@
     protected File directory;
 
     public MapContainerImpl(File directory,ContainerId id,IndexItem root,IndexManager indexManager,DataManager
dataManager,
-            String indexType){
+            Store.IndexType indexType){
         super(id,root,indexManager,dataManager,indexType);
         this.directory = directory;
     }
@@ -60,7 +59,7 @@
     public synchronized void init() {
         super.init();
         if(index==null){
-            if(indexType.equals(IndexTypes.DISK_INDEX)){
+            if(indexType.equals(Store.IndexType.PERSISTENT)){
                 String name = containerId.getDataContainerName() + "_" + containerId.getKey();
                 try{
                     this.index=new HashIndex(directory, name , indexManager);

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java
Fri Feb  2 23:24:10 2007
@@ -174,7 +174,6 @@
         int offset=index%maximumEntries;
         page.addHashEntry(offset,entry);
         doOverFlow(index);
-        page.save();
     }
 
     private HashEntry removeHashEntry(int index) throws IOException{
@@ -182,7 +181,6 @@
         int offset=getRetrieveOffset(index);
         HashEntry result=page.removeHashEntry(offset);
         doUnderFlow(index);
-        page.save();
         return result;
     }
 
@@ -233,7 +231,7 @@
         int count=0;
         for(HashPageInfo page:hashPages){
             if((index+1)<=(count+page.size())){
-                //count=count==0?count:count+1;
+                // count=count==0?count:count+1;
                 result=index-count;
                 break;
             }
@@ -278,7 +276,6 @@
             HashEntry overflowed=info.removeHashEntry(info.size()-1);
             doOverFlow(pageNo+1,overflowed);
         }
-        info.save();
     }
 
     private void doUnderFlow(int index){
@@ -289,7 +286,7 @@
         HashPageInfo info=hashPages.get(pageNo);
     }
 
-    private void end(){
+    private void end() throws IOException{
         for(HashPageInfo info:hashPages){
             info.end();
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPageInfo.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPageInfo.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPageInfo.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPageInfo.java
Fri Feb  2 23:24:10 2007
@@ -27,6 +27,7 @@
     private long id;
     private int size;
     private HashPage page;
+    private boolean dirty=false;
 
     HashPageInfo(HashIndex index){
         this.hashIndex=index;
@@ -63,6 +64,7 @@
     void addHashEntry(int index,HashEntry entry) throws IOException{
         page.addHashEntry(index,entry);
         size++;
+        dirty=true;
     }
 
     HashEntry getHashEntry(int index) throws IOException{
@@ -73,11 +75,12 @@
         HashEntry result=page.removeHashEntry(index);
         if(result!=null){
             size--;
+            dirty=true;
         }
         return result;
     }
-    
-    void dump() {
+
+    void dump(){
         page.dump();
     }
 
@@ -87,19 +90,21 @@
         }
     }
 
-    void end() {
+    void end() throws IOException{
+        if(page!=null){
+            if(dirty){
+                hashIndex.writeFullPage(page);
+            }
+        }
         page=null;
+        dirty=false;
     }
-    
-    HashPage getPage() {
+
+    HashPage getPage(){
         return page;
     }
-    
-    void setPage(HashPage page) {
-        this.page=page;
-    }
 
-    void save() throws IOException{
-        hashIndex.writeFullPage(page);
+    void setPage(HashPage page){
+        this.page=page;
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
Fri Feb  2 23:24:10 2007
@@ -25,7 +25,6 @@
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
-import org.apache.activemq.kaha.IndexTypes;
 import org.apache.activemq.kaha.ListContainer;
 import org.apache.activemq.kaha.MapContainer;
 import org.apache.activemq.kaha.Marshaller;
@@ -58,7 +57,7 @@
     protected OpenWireFormat wireFormat=new OpenWireFormat();
     private long maxDataFileLength=32*1024*1024;
     protected int maximumDestinationCacheSize=10000;
-    private String indexType=IndexTypes.DISK_INDEX;
+   
     private File dir;
     private Store theStore;
 
@@ -215,20 +214,7 @@
         this.maxDataFileLength=maxDataFileLength;
     }
 
-    /**
-     * @return the indexType
-     */
-    public String getIndexType(){
-        return this.indexType;
-    }
-
-    /**
-     * @param indexType the indexTypes to set
-     */
-    public void setIndexType(String indexType){
-        this.indexType=indexType;
-    }
-
+  
     /**
      * @return the maximumDestinationCacheSize
      */
@@ -248,7 +234,6 @@
         if(theStore==null){
             theStore=StoreFactory.open(getStoreName(),"rw");
             theStore.setMaxDataFileLength(maxDataFileLength);
-            theStore.setIndexType(indexType);
         }
         return theStore;
     }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/Loader.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/Loader.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/Loader.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/Loader.java Fri Feb
 2 23:24:10 2007
@@ -53,7 +53,7 @@
             start.await();
             Marshaller keyMarshaller=new StringMarshaller();
             Marshaller valueMarshaller=new BytesMarshaller();
-            MapContainer container=store.getMapContainer(name);
+            MapContainer container=store.getMapContainer(name,Store.DEFAULT_CONTAINER_NAME,Store.IndexType.PERSISTENT);
            
             container.setKeyMarshaller(keyMarshaller);
             container.setValueMarshaller(valueMarshaller);

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/MapContainerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/MapContainerTest.java?view=diff&rev=503177&r1=503176&r2=503177
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/MapContainerTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/MapContainerTest.java
Fri Feb  2 23:24:10 2007
@@ -177,7 +177,7 @@
         super.setUp();
         name = System.getProperty("basedir", ".")+"/target/activemq-data/map-container.db";
         store = getStore();
-        container = store.getMapContainer("test","test",IndexTypes.DISK_INDEX);
+        container = store.getMapContainer("test","test",Store.IndexType.PERSISTENT);
         container.load();
         testMap = new HashMap();
         for (int i =0; i < COUNT; i++){



Mime
View raw message