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 2006/03/21 18:22:06 UTC

svn commit: r387586 [1/3] - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/kaha/ main/java/org/apache/activemq/kaha/impl/ main/java/org/apache/activemq/store/kahadaptor/ test/java/org/apache/activemq/kaha/

Author: rajdavies
Date: Tue Mar 21 09:21:33 2006
New Revision: 387586

URL: http://svn.apache.org/viewcvs?rev=387586&view=rev
Log:
dumping first cut of kaha in SVN

Added:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/BytesMarshaller.java
    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/MapContainer.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Marshaller.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ObjectMarshaller.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/RuntimeStoreException.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StringMarshaller.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/BadMagicException.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerCollectionSupport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySet.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySetIterator.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySet.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySetIterator.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerListIterator.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerMapEntry.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollection.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollectionIterator.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceManager.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceTree.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/Item.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ListContainerImpl.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/LocatableItem.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/MapContainerImpl.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/RootContainer.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/StoreByteArrayInputStream.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/StoreByteArrayOutputStream.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/StoreImpl.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/StoreReader.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/StoreWriter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/package.html   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/
      - copied from r385999, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/memory/
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/AtomicIntegerMarshaller.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/CommandMarshaller.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaMessageStore.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistentAdaptor.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicMessageStore.java   (with props)
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MemoryMessageStore.java
      - copied unchanged from r387583, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MemoryPersistenceAdapter.java
      - copied unchanged from r387583, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryPersistenceAdapter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MemoryTopicMessageStore.java
      - copied unchanged from r387583, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicMessageStore.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/MemoryTransactionStore.java
      - copied unchanged from r387583, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTransactionStore.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/package.html
      - copied, changed from r387583, incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/memory/package.html
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/ListContainerTest.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/LoadTest.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/Loader.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/MapContainerTest.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/BytesMarshaller.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/BytesMarshaller.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/BytesMarshaller.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/BytesMarshaller.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,51 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+/**
+ * Implementation of a Marshaller for byte arrays
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class BytesMarshaller implements Marshaller{
+    /**
+     * Write the payload of this entry to the RawContainer
+     * 
+     * @param object
+     * @param dataOut
+     * @throws IOException
+     */
+    public void writePayload(Object object,DataOutputStream dataOut) throws IOException{
+        byte[] data=(byte[]) object;
+        dataOut.writeInt(data.length);
+        dataOut.write(data);
+    }
+
+    /**
+     * Read the entry from the RawContainer
+     * 
+     * @param dataIn
+     * @return unmarshalled object
+     * @throws IOException
+     */
+    public Object readPayload(DataInputStream dataIn) throws IOException{
+        int size=dataIn.readInt();
+        byte[] data=new byte[size];
+        dataIn.readFully(data);
+        return data;
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ListContainer.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,104 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha;
+
+import java.util.List;
+import java.util.NoSuchElementException;
+/**
+ *Represents a container of persistent objects in the store
+ *Acts as a map, but values can be retrieved in insertion order
+ * 
+ * @version $Revision: 1.2 $
+ */
+public interface ListContainer extends List{
+    /**
+     * The container is created or retrieved in 
+     * an unloaded state.
+     * load populates the container will all the indexes used etc
+     * and should be called before any operations on the container
+     */
+    public void load();
+    
+    /**
+     * unload indexes from the container
+     *
+     */
+    public void unload();
+    
+    /**
+     * @return true if the indexes are loaded
+     */
+    public boolean isLoaded();
+    
+    
+    /**
+     * For homogenous containers can set a custom marshaller for loading values
+     * The default uses Object serialization
+     * @param marshaller 
+     */
+    public void setMarshaller(Marshaller marshaller);
+    /**
+     * @return the id the MapContainer was create with
+     */
+    public Object getId();
+
+    /**
+     * @return the number of values in the container
+     */
+    public int size();
+    
+    /**
+     * Inserts the given element at the beginning of this list.
+     *
+     * @param o the element to be inserted at the beginning of this list.
+     */
+    public void addFirst(Object o);
+
+    /**
+     * Appends the given element to the end of this list.  (Identical in
+     * function to the <tt>add</tt> method; included only for consistency.)
+     *
+     * @param o the element to be inserted at the end of this list.
+     */
+    public void addLast(Object o);
+    
+    /**
+     * Removes and returns the first element from this list.
+     *
+     * @return the first element from this list.
+     * @throws    NoSuchElementException if this list is empty.
+     */
+    public Object removeFirst();
+
+    /**
+     * Removes and returns the last element from this list.
+     *
+     * @return the last element from this list.
+     * @throws    NoSuchElementException if this list is empty.
+     */
+    public Object removeLast();
+    
+    
+    /**
+     * remove an objecr from the list without retrieving the old value from the store
+     * @param position
+     * @return true if successful
+     */
+    public boolean doRemove(int position);
+    
+    
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/MapContainer.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/MapContainer.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/MapContainer.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/MapContainer.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,144 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *Represents a container of persistent objects in the store
+ *Acts as a map, but values can be retrieved in insertion order
+ * 
+ * @version $Revision: 1.2 $
+ */
+public interface MapContainer  extends   Map{
+    
+    
+    /**
+     * The container is created or retrieved in 
+     * an unloaded state.
+     * load populates the container will all the indexes used etc
+     * and should be called before any operations on the container
+     */
+    public void load();
+    
+    /**
+     * unload indexes from the container
+     *
+     */
+    public void unload();
+    
+    /**
+     * @return true if the indexes are loaded
+     */
+    public boolean isLoaded();
+    
+    /**
+     * For homogenous containers can set a custom marshaller for loading keys
+     * The default uses Object serialization
+     * @param keyMarshaller
+     */
+    public void setKeyMarshaller(Marshaller keyMarshaller);
+    
+    /**
+     * For homogenous containers can set a custom marshaller for loading values
+     * The default uses Object serialization
+     * @param valueMarshaller 
+   
+     */
+    public void setValueMarshaller(Marshaller valueMarshaller);
+    /**
+     * @return the id the MapContainer was create with
+     */
+    public Object getId();
+
+    /**
+     * @return the number of values in the container
+     */
+    public int size();
+
+    /**
+     * @return true if there are no values stored in the container
+     */
+    public boolean isEmpty();
+
+    /**
+     * @param key 
+     * @return true if the container contains the key
+     */
+    public boolean containsKey(Object key);
+
+    /**
+     * Get the value associated with the key
+     * @param key 
+     * @return the value associated with the key from the store
+     */
+    public Object get(Object key);
+
+    
+    /**
+     * @param o 
+     * @return true if the MapContainer contains the value o
+     */
+    public boolean containsValue(Object o);
+
+    /**
+     * Add add entries in the supplied Map
+     * @param map
+     */
+    public void putAll(Map map);
+
+    /**
+     * @return a Set of all the keys
+     */
+    public Set keySet();
+
+    /**
+     * @return a collection of all the values - the values will be lazily pulled out of the
+     * store if iterated etc.
+     */
+    public Collection values();
+
+    /**
+     * @return a Set of all the Map.Entry instances - the values will be lazily pulled out of the
+     * store if iterated etc.
+     */
+    public Set entrySet();
+
+   
+    /**
+     * Add an entry
+     * @param key
+     * @param value
+     * @return the old value for the key
+     */
+    public Object put(Object key,Object value);
+
+
+    /**
+     * remove an entry associated with the key
+     * @param key 
+     * @return the old value assocaited with the key or null
+     */
+    public Object remove(Object key);
+
+    /**
+     * empty the container
+     */
+    public void clear();
+}
\ No newline at end of file

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Marshaller.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Marshaller.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Marshaller.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Marshaller.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,49 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+/**
+ *Marshaller for marshalling in/out objects to a RawContainer
+ * 
+ * @version $Revision: 1.2 $
+ */
+public interface Marshaller {
+    
+       
+    /**
+     * Write the payload of this entry to the RawContainer
+     * @param object 
+     * @param dataOut
+     * @throws IOException
+     */
+    public void writePayload(Object object, DataOutputStream dataOut) throws IOException;
+    
+    
+    /**
+     * Read the entry from the RawContainer
+     * @param dataIn 
+     * @return unmarshalled object
+     * @throws IOException
+     */
+    public Object readPayload(DataInputStream dataIn) throws IOException;
+
+   
+}
\ No newline at end of file

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ObjectMarshaller.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ObjectMarshaller.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ObjectMarshaller.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/ObjectMarshaller.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,65 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+/**
+ * Implementation of a Marshaller for Objects
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class ObjectMarshaller implements Marshaller{
+    /**
+     * Write the payload of this entry to the RawContainer
+     * 
+     * @param object
+     * @param dataOut
+     * @throws IOException
+     */
+    public void writePayload(Object object,DataOutputStream dataOut) throws IOException{
+        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+        ObjectOutputStream objectOut=new ObjectOutputStream(bytesOut);
+        objectOut.writeObject(object);
+        objectOut.close();
+        byte[] data = bytesOut.toByteArray();
+        dataOut.writeInt(data.length);
+        dataOut.write(data);
+    }
+
+    /**
+     * Read the entry from the RawContainer
+     * 
+     * @param dataIn
+     * @return unmarshalled object
+     * @throws IOException
+     */
+    public Object readPayload(DataInputStream dataIn) throws IOException{
+        int size = dataIn.readInt();
+        byte[] data = new byte[size];
+        dataIn.readFully(data);
+        ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
+        ObjectInputStream objectIn=new ObjectInputStream(bytesIn);
+        try{
+            return objectIn.readObject();
+        }catch(ClassNotFoundException e){
+            throw new IOException(e.getMessage());
+        }
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/RuntimeStoreException.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/RuntimeStoreException.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/RuntimeStoreException.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/RuntimeStoreException.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,59 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha;
+
+
+/**
+*Runtime exception for the Store
+* 
+* @version $Revision: 1.2 $
+*/
+
+public class RuntimeStoreException extends RuntimeException{
+    
+   
+    private static final long serialVersionUID=8807084681372365173L;
+
+    /**
+     * Constructor
+     */
+    public RuntimeStoreException(){
+        super();
+    }
+
+    /**
+     * Constructor
+     * @param message
+     */
+    public RuntimeStoreException(String message){
+        super(message);
+    }
+
+    /**
+     * Constructor
+     * @param message
+     * @param cause
+     */
+    public RuntimeStoreException(String message,Throwable cause){
+        super(message,cause);
+    }
+
+    /**
+     * Constructor
+     * @param cause
+     */
+    public RuntimeStoreException(Throwable cause){
+        super(cause);
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/Store.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,97 @@
+package org.apache.activemq.kaha;
+
+import java.io.IOException;
+import java.util.Set;
+
+/**
+* A Store is holds persistent containers
+* 
+* @version $Revision: 1.2 $
+*/
+public interface Store{
+    
+    /**
+     * close the store
+     * @throws IOException
+     */
+    public void close() throws IOException;
+    
+    
+    /**
+     * Force all writes to disk
+     * @throws IOException
+     */
+    public void force() throws IOException;
+    
+    /**
+     * empty all the contents of the store
+     * @throws IOException
+     */
+    public void clear() throws IOException;
+    
+    
+    /**
+     * delete the store
+     * @return true if the delete was successful
+     * @throws IOException
+     */
+    public boolean delete() throws IOException;
+
+    /**
+     * Checks if a MapContainer exists
+     * @param id
+     * @return new MapContainer
+     */
+    public boolean doesMapContainerExist(Object id);
+
+    /**
+     * Get a MapContainer with the given id - the MapContainer is created if needed
+     * @param id
+     * @return container for the associated id or null if it doesn't exist
+     * @throws IOException 
+     */
+    public MapContainer getMapContainer(Object id) throws IOException;
+
+    /**
+     * delete a container
+     * @param id
+     * @throws IOException
+     */
+    public void deleteMapContainer(Object id) throws IOException;
+
+    /**
+     * Get a Set of call MapContainer Ids
+     * @return the set of ids
+     */
+    public Set getMapContainerIds();
+    
+    /**
+     * Checks if a ListContainer exists
+     * @param id
+     * @return new MapContainer
+     */
+    public boolean doesListContainerExist(Object id);
+
+   /**
+    * Get a ListContainer with the given id and creates it if it doesn't exist
+    * @param id
+    * @return container for the associated id or null if it doesn't exist
+ * @throws IOException 
+    */
+   public ListContainer getListContainer(Object id) throws IOException;
+
+   /**
+    * delete a ListContainer
+    * @param id
+    * @throws IOException
+    */
+   public void deleteListContainer(Object id) throws IOException;
+
+   /**
+    * Get a Set of call ListContainer Ids
+    * @return the set of ids
+    */
+   public Set getListContainerIds();
+    
+    
+}
\ No newline at end of file

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,47 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.activemq.kaha.impl.StoreImpl;
+/**
+ * Factory for creating stores
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class StoreFactory{
+   
+
+    /**
+     * open or create a Store
+     * @param name
+     * @param mode
+     * @return the opened/created store
+     * @throws IOException
+     */
+    public static Store open(String name,String mode) throws IOException{
+        return new StoreImpl(name,mode);
+    }
+    
+    /**
+     * Delete a database
+     * @param name of the database
+     * @return true if successful
+     */
+    public static boolean delete(String name){
+        File file = new File(name);
+        return file.delete();
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StringMarshaller.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StringMarshaller.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StringMarshaller.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StringMarshaller.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,46 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+/**
+ * Implementation of a Marshaller for Strings
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class StringMarshaller implements Marshaller{
+    /**
+     * Write the payload of this entry to the RawContainer
+     * 
+     * @param object
+     * @param dataOut
+     * @throws IOException
+     */
+    public void writePayload(Object object,DataOutputStream dataOut) throws IOException{
+        dataOut.writeUTF(object.toString());
+    }
+
+    /**
+     * Read the entry from the RawContainer
+     * 
+     * @param dataIn
+     * @return unmarshalled object
+     * @throws IOException
+     */
+    public Object readPayload(DataInputStream dataIn) throws IOException{
+        return dataIn.readUTF();
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/BadMagicException.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/BadMagicException.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/BadMagicException.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/BadMagicException.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,45 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha.impl;
+
+import java.io.IOException;
+
+/**
+ * Occurs when bad magic occurs in reading a file
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class BadMagicException extends IOException{
+    /**
+     * 
+     */
+    private static final long serialVersionUID=-570930196733067056L;
+
+    /**
+     * Default Constructor
+     *
+     */
+    public BadMagicException(){
+        super();
+    }
+
+    /**
+     * Construct an Exception with a reason
+     * @param s
+     */
+    public BadMagicException(String s){
+        super(s);
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerCollectionSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerCollectionSupport.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerCollectionSupport.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerCollectionSupport.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+
+/**
+ * Base class for container collections
+ * 
+ * @version $Revision: 1.2 $
+ */
+class ContainerCollectionSupport{
+    
+    protected MapContainerImpl container;
+    
+    protected ContainerCollectionSupport(MapContainerImpl container){
+        this.container = container;
+    }
+    
+    public int size(){
+        return container.size();
+    }
+
+   
+    public boolean isEmpty(){
+        return container.isEmpty();
+    }
+
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySet.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySet.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySet.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,111 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+* Set of Map.Entry objects for a container
+* 
+* @version $Revision: 1.2 $
+*/
+public class ContainerEntrySet extends ContainerCollectionSupport implements Set{
+    ContainerEntrySet(MapContainerImpl container){
+        super(container);
+    }
+
+    public boolean contains(Object o){
+        return container.entrySet().contains(o);
+    }
+
+    public Iterator iterator(){
+        return new ContainerEntrySetIterator(container,buildEntrySet().iterator());
+    }
+
+    public Object[] toArray(){
+        return buildEntrySet().toArray();
+    }
+
+    public Object[] toArray(Object[] a){
+        return buildEntrySet().toArray(a);
+    }
+
+    public boolean add(Object o){
+        throw new UnsupportedOperationException("Cannot add here");
+    }
+
+    public boolean remove(Object o){
+        boolean result=false;
+        if(buildEntrySet().remove(o)){
+            ContainerMapEntry entry=(ContainerMapEntry) o;
+            container.remove(entry.getKey());
+        }
+        return result;
+    }
+
+    public boolean containsAll(Collection c){
+        return buildEntrySet().containsAll(c);
+    }
+
+    public boolean addAll(Collection c){
+        throw new UnsupportedOperationException("Cannot add here");
+    }
+
+    public boolean retainAll(Collection c){
+        List tmpList=new ArrayList();
+        for(Iterator i=c.iterator();i.hasNext();){
+            Object o=i.next();
+            if(!contains(o)){
+                tmpList.add(o);
+            }
+        }
+        boolean result=false;
+        for(Iterator i=tmpList.iterator();i.hasNext();){
+            result|=remove(i.next());
+        }
+        return result;
+    }
+
+    public boolean removeAll(Collection c){
+        boolean result=true;
+        for(Iterator i=c.iterator();i.hasNext();){
+            if(!remove(i.next())){
+                result=false;
+            }
+        }
+        return result;
+    }
+
+    public void clear(){
+        container.clear();
+    }
+
+    protected Set buildEntrySet(){
+        Set set=new HashSet();
+        for(Iterator i=container.keySet().iterator();i.hasNext();){
+            ContainerMapEntry entry=new ContainerMapEntry(container,i.next());
+            set.add(entry);
+        }
+        return set;
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySetIterator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySetIterator.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySetIterator.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerEntrySetIterator.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,52 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+import java.util.Iterator;
+
+
+/**
+* An Iterator for a container entry Set
+* 
+* @version $Revision: 1.2 $
+*/
+public class ContainerEntrySetIterator implements Iterator{
+    private MapContainerImpl container;
+    private Iterator  iter;
+    private ContainerMapEntry currentEntry;
+    ContainerEntrySetIterator(MapContainerImpl container,Iterator iter){
+        this.container = container;
+        this.iter = iter;
+    }
+    
+    public boolean hasNext(){
+        return iter.hasNext();
+    }
+
+    public Object next(){
+        currentEntry =  (ContainerMapEntry) iter.next();
+        return currentEntry;
+    }
+
+    public void remove(){
+       if (currentEntry != null){
+           container.remove(currentEntry.getKey());
+       }
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySet.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySet.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySet.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,99 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+* A Set of keys for the container
+* 
+* @version $Revision: 1.2 $
+*/
+public class ContainerKeySet extends ContainerCollectionSupport implements Set{
+  
+    
+    ContainerKeySet(MapContainerImpl container){
+        super(container);
+    }
+    
+    
+    public boolean contains(Object o){
+        return container.getInternalKeySet().contains(o);
+    }
+
+    public Iterator iterator(){
+        return new ContainerKeySetIterator(container,container.getInternalKeySet().iterator());
+    }
+
+    public Object[] toArray(){
+        return container.getInternalKeySet().toArray();
+    }
+
+    public Object[] toArray(Object[] a){
+        return container.getInternalKeySet().toArray(a);
+    }
+
+    public boolean add(Object o){
+        throw new UnsupportedOperationException("Cannot add here");
+    }
+
+    public boolean remove(Object o){
+       return container.remove(o) != null;
+    }
+
+    public boolean containsAll(Collection c){
+       return container.getInternalKeySet().containsAll(c);
+    }
+
+    public boolean addAll(Collection c){
+        throw new UnsupportedOperationException("Cannot add here");
+    }
+
+    public boolean retainAll(Collection c){
+        List tmpList = new ArrayList();
+        for (Iterator i = c.iterator(); i.hasNext(); ){
+            Object o = i.next();
+            if (!contains(o)){
+                tmpList.add(o);
+            }  
+        }
+        for(Iterator i = tmpList.iterator(); i.hasNext();){
+            remove(i.next());
+        }
+        return !tmpList.isEmpty();
+    }
+
+    public boolean removeAll(Collection c){
+        boolean result = true;
+        for (Iterator i = c.iterator(); i.hasNext(); ){
+            if (!remove(i.next())){
+                result = false;
+            }
+        }
+        return result;
+    }
+
+    public void clear(){
+      container.clear();
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySetIterator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySetIterator.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySetIterator.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerKeySetIterator.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,52 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+import java.util.Iterator;
+
+
+/**
+*Iterator for the set of keys for a container
+* 
+* @version $Revision: 1.2 $
+*/
+public class ContainerKeySetIterator implements Iterator{
+    private MapContainerImpl container;
+    private Iterator  iter;
+    private Object currentKey;
+    ContainerKeySetIterator(MapContainerImpl container,Iterator iter){
+        this.container = container;
+        this.iter = iter;
+    }
+    
+    public boolean hasNext(){
+        return iter.hasNext();
+    }
+
+    public Object next(){
+        currentKey =  iter.next();
+        return currentKey;
+    }
+
+    public void remove(){
+       if (currentKey != null){
+           container.remove(currentKey);
+       }
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerListIterator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerListIterator.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerListIterator.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerListIterator.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,117 @@
+/**
+ * 
+ */
+package org.apache.activemq.kaha.impl;
+
+import java.util.ListIterator;
+/**
+ * @author rajdavies
+ * 
+ */
+public class ContainerListIterator implements ListIterator{
+    private ListContainerImpl container;
+    private ListIterator iterator;
+    private LocatableItem current;
+
+    protected ContainerListIterator(ListContainerImpl container,ListIterator iterator){
+        this.container=container;
+        this.iterator=iterator;
+        this.current = container.internalGet(0);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#hasNext()
+     */
+    public boolean hasNext(){
+        return iterator.hasNext();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#next()
+     */
+    public Object next(){
+        Object result=null;
+        current=(LocatableItem) iterator.next();
+        if(current!=null){
+            result=container.getValue(current);
+        }
+        return result;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#hasPrevious()
+     */
+    public boolean hasPrevious(){
+        return iterator.hasPrevious();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#previous()
+     */
+    public Object previous(){
+        Object result=null;
+        current=(LocatableItem) iterator.previous();
+        if(current!=null){
+            result=container.getValue(current);
+        }
+        return result;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#nextIndex()
+     */
+    public int nextIndex(){
+        return iterator.nextIndex();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#previousIndex()
+     */
+    public int previousIndex(){
+        return iterator.previousIndex();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#remove()
+     */
+    public void remove(){
+        iterator.remove();
+        if(current!=null){
+            container.remove(current);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#set(E)
+     */
+    public void set(Object o){
+        LocatableItem item=container.internalSet(previousIndex()+1,o);
+        iterator.set(item);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.ListIterator#add(E)
+     */
+    public void add(Object o){
+        LocatableItem item=container.internalAdd(previousIndex()+1,o);
+        iterator.set(item);
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerMapEntry.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerMapEntry.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerMapEntry.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerMapEntry.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,50 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha.impl;
+
+import java.util.Map;
+import org.apache.activemq.kaha.MapContainer;
+
+/**
+* Map.Entry implementation for a container
+* 
+* @version $Revision: 1.2 $
+*/
+class ContainerMapEntry implements Map.Entry {
+
+    private MapContainer container;
+    private Object key;
+   
+    ContainerMapEntry(MapContainer container,Object key){
+        this.container = container;
+        this.key = key;
+      
+    }
+    
+    
+    public Object getKey(){
+        return key;
+    }
+
+    public Object getValue(){
+        return container.get(key);
+    }
+
+    public Object setValue(Object value){
+        return container.put(key, value);
+    }
+}
+   
+
+    

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerMapEntry.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollection.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollection.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollection.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollection.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,138 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+* Values collection for the MapContainer
+* 
+* @version $Revision: 1.2 $
+*/
+class ContainerValueCollection extends ContainerCollectionSupport implements Collection{
+    
+   
+    ContainerValueCollection(MapContainerImpl container){
+        super(container);
+    }
+    
+    
+    
+    public boolean contains(Object o){
+        return container.containsValue(o);
+    }
+
+    
+    public Iterator iterator(){
+        LinkedList list=container.getItemList();
+        list = (LinkedList) list.clone();
+        return new ContainerValueCollectionIterator(container,list.iterator());
+    }
+
+   
+    public Object[] toArray(){
+        Object[] result = null;
+        List list = container.getItemList();
+        synchronized(list){
+            result = new Object[list.size()];
+            int count = 0;
+            for(Iterator i=list.iterator();i.hasNext();){
+                LocatableItem item=(LocatableItem) i.next();
+                Object value=container.getValue(item);
+                result[count++] = value;
+            }
+        }
+        return result;
+    }
+
+    public Object[] toArray(Object[] result){
+        List list=container.getItemList();
+        synchronized(list){
+            if(result.length<list.size()){
+                int count=0;
+                result=(Object[]) java.lang.reflect.Array.newInstance(result.getClass().getComponentType(),list.size());
+                for(Iterator i=list.iterator();i.hasNext();){
+                    LocatableItem item=(LocatableItem) i.next();
+                    Object value=container.getValue(item);
+                    result[count++]=value;
+                }
+            }
+        }
+        return result;
+    }
+
+    
+    public boolean add(Object o){
+        throw  new UnsupportedOperationException("Can't add an object here");
+    }
+
+   
+    public boolean remove(Object o){
+        return container.removeValue(o);
+    }
+
+    
+    public boolean containsAll(Collection c){
+        boolean result = !c.isEmpty();
+        for (Iterator i = c.iterator(); i.hasNext(); ){
+            if (!contains(i.next())){
+                result = false;
+                break;
+            }
+        }
+        return result;
+    }
+
+   
+    public boolean addAll(Collection c){
+        throw  new UnsupportedOperationException("Can't add everything here!");
+    }
+
+    
+    public boolean removeAll(Collection c){
+        boolean result = true;
+        for (Iterator i = c.iterator(); i.hasNext(); ){
+            Object obj = i.next();
+                result&=remove(obj);
+        }
+        return result;
+    }
+
+    
+    public boolean retainAll(Collection c){
+       List tmpList = new ArrayList();
+       for (Iterator i = c.iterator(); i.hasNext(); ){
+           Object o = i.next();
+           if (!contains(o)){
+               tmpList.add(o);
+           }  
+       }
+       for(Iterator i = tmpList.iterator(); i.hasNext();){
+           remove(i.next());
+       }
+       return !tmpList.isEmpty();
+    }
+
+   
+    public void clear(){
+     container.clear();
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollectionIterator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollectionIterator.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollectionIterator.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/ContainerValueCollectionIterator.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,50 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.kaha.impl;
+
+import java.util.Iterator;
+
+/**
+* Values collection iterator for the MapContainer
+* 
+* @version $Revision: 1.2 $
+*/
+public class ContainerValueCollectionIterator implements Iterator{
+    private MapContainerImpl container;
+    private Iterator  iter;
+    private LocatableItem currentItem;
+    ContainerValueCollectionIterator(MapContainerImpl container,Iterator iter){
+        this.container = container;
+        this.iter = iter;
+    }
+    
+    public boolean hasNext(){
+        return iter.hasNext();
+    }
+
+    public Object next(){
+        currentItem = (LocatableItem) iter.next();
+        return container.getValue(currentItem);
+    }
+
+    public void remove(){
+       if (currentItem != null){
+           container.remove(currentItem);
+       }
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceManager.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceManager.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceManager.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceManager.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,162 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha.impl;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/**
+ * Free space list in the Store
+ * 
+ * @version $Revision: 1.2 $
+ */
+final class FreeSpaceManager{
+    private static final Log log = LogFactory.getLog(FreeSpaceManager.class);
+    static final int ROOT_SIZE=64;
+    static final int RESIZE_INCREMENT=4096*1024;
+    private Map map=new HashMap();
+    private Map prevMap=new HashMap();
+    private FreeSpaceTree tree=new FreeSpaceTree();
+    private StoreWriter writer;
+    private StoreReader reader;
+    private long dataEnd=ROOT_SIZE;
+    private long fileLength=-1;
+
+    FreeSpaceManager(StoreWriter writer,StoreReader reader) throws IOException{
+        this.writer=writer;
+        this.reader=reader;
+        this.fileLength=reader.length();
+    }
+
+    final Item getFreeSpace(Item item) throws IOException{
+        Item result=tree.getNextFreeSpace(item);
+        if(result==null){
+            while(dataEnd>=fileLength){
+                writer.allocateSpace(fileLength+RESIZE_INCREMENT);
+                fileLength=reader.length();
+            }
+            result=new Item();
+            result.setOffset(dataEnd);
+            int newSize = ((item.getSize()/8)+1)*8;
+
+            result.setSize(newSize);
+            dataEnd=dataEnd+result.getSize()+Item.HEAD_SIZE;
+        }else{
+            removeFreeSpace(result);
+        }
+        // reset the item
+        item.setActive(true);
+        item.setOffset(result.getOffset());
+        item.setSize(result.getSize());
+        return item;
+    }
+
+    final void addFreeSpace(Item item) throws IOException{
+        long currentOffset=reader.position();
+        reader.readHeader(item);
+        item.setActive(false);
+        // see if we can condense some space together
+        // first look for free space adjacent up the disk
+        Long nextKey=new Long(item.getOffset()+item.getSize()+Item.HEAD_SIZE);
+        Item next=(Item) map.remove(nextKey);
+        if(next!=null){
+            tree.removeItem(next);
+            Long prevKey=new Long(next.getOffset()+next.getSize()+Item.HEAD_SIZE);
+            prevMap.remove(prevKey);
+            int newSize=item.getSize()+next.getSize()+Item.HEAD_SIZE;
+            item.setSize(newSize);
+        }
+        // now see if there was a previous item
+        // in the next map
+        Long key=new Long(item.getOffset());
+        Item prev=(Item) prevMap.remove(key);
+        Long prevKey=prev!=null?new Long(prev.getOffset()):null;
+        if(prev!=null&&prevKey!=null){
+            // we can condense the free space
+            // first we are about to change the item so remove it from the tree
+            tree.removeItem(prev);
+            int newSize=prev.getSize()+item.getSize()+Item.HEAD_SIZE;
+            prev.setSize(newSize);
+            // update the header
+            writer.updateHeader(prev);
+            // put back in the tree
+            tree.addItem(prev);
+        }else{
+            // update the item header
+            writer.updateHeader(item);
+            tree.addItem(item);
+            map.put(key,item);
+            prevKey=new Long(item.getOffset()+item.getSize()+Item.HEAD_SIZE);
+            prevMap.put(prevKey,item);
+        }
+        reader.position(currentOffset);
+    }
+
+    /**
+     * validates and builds free list
+     * 
+     * @throws IOException
+     */
+    final void scanStoredItems() throws IOException{
+        if(reader.length()>ROOT_SIZE){
+            long offset=ROOT_SIZE;
+            while((offset+Item.HEAD_SIZE)<reader.length()){
+                Item item=new Item();
+                try{
+                    reader.position(offset);
+                    item.setOffset(offset);
+                    reader.readHeader(item);
+                }catch(BadMagicException e){
+                 
+                    log.error("Got bad magic reading stored items",e);
+                    break;
+                }
+                if(item.getSize()>=0){
+                    if(!item.isActive()){
+                        addFreeSpace(item);
+                    }
+                    offset+=item.getSize()+Item.HEAD_SIZE;
+                }else{
+                    // we've hit free space or end of file
+                    break;
+                }
+            }
+            dataEnd=offset;
+        }else {
+            dataEnd = ROOT_SIZE;
+        }
+    }
+
+    private void removeFreeSpace(Item item){
+        if(item!=null){
+            long next=item.getOffset()+item.getSize()+Item.HEAD_SIZE;
+            Long nextKey=new Long(next);
+            prevMap.remove(nextKey);
+            Long key=new Long(item.getOffset());
+            map.remove(key);
+        }
+    }
+
+    void dump(PrintWriter printer){
+        printer.println("FreeSpace: map size = "+map.size()+", tree size = "+tree.size()+", prevMap size = "
+                        +prevMap.size());
+        for(Iterator i=map.entrySet().iterator();i.hasNext();){
+            printer.println("map = "+i.next());
+        }
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceManager.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceTree.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceTree.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceTree.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceTree.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,109 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+/**
+ * A a wrapper for a TreeMap of free Items - sorted by size This enables us to re-use free Items on disk
+ * 
+ * @version $Revision: 1.2 $
+ */
+class FreeSpaceTree{
+    private Map sizeMap=new HashMap();
+    private TreeMap tree=new TreeMap();
+
+    void addItem(Item item){
+        Long sizeKey=new Long(item.getSize());
+        Item old=(Item) tree.put(sizeKey,item);
+        if(old!=null){
+            // We'll preserve old items to reuse
+            List list=(List) sizeMap.get(sizeKey);
+            if(list==null){
+                list=new ArrayList();
+                sizeMap.put(sizeKey,list);
+            }
+            list.add(old);
+        }
+    }
+
+    boolean removeItem(Item item){
+        boolean result=false;
+        Long sizeKey=new Long(item.getSize());
+        Item retrieved=(Item) tree.get(sizeKey);
+        if(retrieved==item){
+            Object foo=tree.remove(sizeKey);
+            if(foo!=retrieved){
+                Thread.dumpStack();
+                System.exit(0);
+            }
+            result=true;
+            reconfigureTree(sizeKey);
+        }else{
+            List list=(List) sizeMap.get(sizeKey);
+            if(list!=null){
+                boolean foo=list.remove(item);
+                if(list.isEmpty()){
+                    sizeMap.remove(sizeKey);
+                }
+            }
+        }
+        return result;
+    }
+
+    Item getNextFreeSpace(Item item){
+        Item result=null;
+        if(!tree.isEmpty()){
+            Long sizeKey=new Long(item.getSize());
+            SortedMap map=tree.tailMap(sizeKey);
+            if(map!=null&&!map.isEmpty()){
+                Long resultKey=(Long) map.firstKey();
+                result=(Item) map.get(resultKey);
+                if(result!=null){
+                    // remove from the tree
+                    tree.remove(resultKey);
+                    reconfigureTree(resultKey);
+                }
+            }
+        }
+        return result;
+    }
+
+    void reconfigureTree(Long sizeKey){
+        List list=(List) sizeMap.get(sizeKey);
+        if(list!=null){
+            if(!list.isEmpty()){
+                Object newItem=list.remove(list.size()-1);
+                tree.put(sizeKey,newItem);
+            }
+            if(list.isEmpty()){
+                sizeMap.remove(sizeKey);
+            }
+        }
+    }
+
+    int size(){
+        int result=0;
+        for(Iterator i=sizeMap.values().iterator();i.hasNext();){
+            List list=(List) i.next();
+            result+=list.size();
+        }
+        return result+tree.size();
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/FreeSpaceTree.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/Item.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/Item.java?rev=387586&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/Item.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/Item.java Tue Mar 21 09:21:33 2006
@@ -0,0 +1,116 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation
+ * 
+ * Licensed 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.kaha.impl;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import org.apache.activemq.kaha.Marshaller;
+/**
+ * A a wrapper for a data in the store
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class Item{
+    static final long POSITION_NOT_SET=-1;
+    static final short MAGIC=31317;
+    static final int ACTIVE=22;
+    static final int FREE=33;
+    static final int HEAD_SIZE=8; // magic + active + len
+    static final int LOCATION_SIZE=24;
+    private long offset=POSITION_NOT_SET;
+    private int size;
+    private boolean active;
+
+    Item(){}
+
+    void writeHeader(DataOutput dataOut) throws IOException{
+        dataOut.writeShort(MAGIC);
+        dataOut.writeByte(active?ACTIVE:FREE);
+        dataOut.writeInt(size);
+        dataOut.writeByte(0);//padding
+    }
+
+    void readHeader(DataInput dataIn) throws IOException{
+        int magic=dataIn.readShort();
+        if(magic==MAGIC){
+            active=(dataIn.readByte()==ACTIVE);
+            size=dataIn.readInt();
+        }else if (magic == 0){
+            size = -999; //end of data
+        }else{
+            throw new BadMagicException("Unexpected Magic value: "+magic);
+        }
+    }
+
+    void writePayload(Marshaller marshaller,Object object,DataOutputStream dataOut) throws IOException{
+        marshaller.writePayload(object,dataOut);
+    }
+
+    Object readPayload(Marshaller marshaller,DataInputStream dataIn) throws IOException{
+        return marshaller.readPayload(dataIn);
+    }
+
+    void readLocation(DataInput dataIn) throws IOException{}
+
+    void writeLocation(DataOutput dataOut) throws IOException{}
+
+    /**
+     * @return Returns the size.
+     */
+    int getSize(){
+        return size;
+    }
+
+    /**
+     * @param size
+     *            The size to set.
+     */
+    void setSize(int size){
+        this.size=size;
+    }
+
+    void setOffset(long pos){
+        offset=pos;
+    }
+
+    long getOffset(){
+        return offset;
+    }
+
+    /**
+     * @return Returns the active.
+     */
+    boolean isActive(){
+        return active;
+    }
+
+    /**
+     * @param active
+     *            The active to set.
+     */
+    void setActive(boolean active){
+        this.active=active;
+    }
+
+    /**
+     * @return a pretty print
+     */
+    public String toString(){
+        String result="offset = "+offset+" ,active = "+active+" , size = "+size;
+        return result;
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/Item.java
------------------------------------------------------------------------------
    svn:executable = *