You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/10/15 19:04:15 UTC

svn commit: r825564 [1/5] - in /activemq/sandbox/activemq-flow: ./ activemq-util/src/main/java/org/apache/activemq/util/buffer/ hawtdb/ hawtdb/src/ hawtdb/src/main/ hawtdb/src/main/java/ hawtdb/src/main/java/org/ hawtdb/src/main/java/org/apache/ hawtdb...

Author: chirino
Date: Thu Oct 15 17:04:11 2009
New Revision: 825564

URL: http://svn.apache.org/viewvc?rev=825564&view=rev
Log:
forked the kahadb module to experiment on a new version which will (not yet fully cooked)
 - Use memory mapped io
 - Provide snapshot isolation via MVCC for better concurrent access.


Added:
    activemq/sandbox/activemq-flow/hawtdb/
    activemq/sandbox/activemq-flow/hawtdb/README
    activemq/sandbox/activemq-flow/hawtdb/pom.xml   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/
    activemq/sandbox/activemq-flow/hawtdb/src/main/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Allocator.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/EncoderDecoder.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IOPagingException.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexException.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OptimisticUpdateException.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OutOfSpaceException.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Paged.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/PagingException.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Transaction.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/package.html   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIndex.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIterator.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeNode.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashBins.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/HashIndex.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/KeyValueEntry.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/Prefixer.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/StringPrefixer.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/package.html   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/io/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/io/MemoryMappedFile.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/io/MemoryMappedFileFactory.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/io/package.html   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/DataFile.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/DataFileAccessor.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/DataFileAccessorPool.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/DataFileAppender.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/Journal.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/Location.java   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/ReadOnlyDataFile.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/ReadOnlyJournal.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/ReplicationTarget.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/journal/package.html   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/ConcurrentPageFile.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/ConcurrentPageFileFactory.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/Extent.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/ExtentInputStream.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/ExtentOutputStream.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/PageFile.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/PageFileFactory.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/SimpleAllocator.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/page/package.html   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/util/
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/util/Ranges.java
    activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/util/package.html   (with props)
    activemq/sandbox/activemq-flow/hawtdb/src/main/resources/
    activemq/sandbox/activemq-flow/hawtdb/src/test/
    activemq/sandbox/activemq-flow/hawtdb/src/test/eclipse-resources/
    activemq/sandbox/activemq-flow/hawtdb/src/test/eclipse-resources/log4j.properties
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/Action.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/ActionActor.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/Actor.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/Benchmarker.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/MapBenchmark.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexBenchmark.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/BTreeIndexTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexBenchmark.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/HashIndexTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/IndexBenchmark.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/index/IndexTestSupport.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/io/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/io/MemoryMappedFileTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/journal/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/journal/JournalTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/page/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/page/ConcurrentPageFileTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/page/ExtentTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/page/TransactionActor.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/page/TransactionBenchmark.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/page/TransactionBenchmarker.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/util/
    activemq/sandbox/activemq-flow/hawtdb/src/test/java/org/apache/hawtdb/internal/util/RangesTest.java
    activemq/sandbox/activemq-flow/hawtdb/src/test/resources/
    activemq/sandbox/activemq-flow/hawtdb/src/test/resources/log4j.properties
Modified:
    activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java
    activemq/sandbox/activemq-flow/pom.xml

Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java?rev=825564&r1=825563&r2=825564&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java Thu Oct 15 17:04:11 2009
@@ -17,8 +17,6 @@
 
 package org.apache.activemq.util.buffer;
 
-import com.sun.org.apache.bcel.internal.util.ByteSequence;
-
 import java.util.List;
 
 /**
@@ -34,6 +32,10 @@
         this(other.data, other.offset, other.length);
     }
 
+    public Buffer(int size) {
+        this(new byte[size]);
+    }
+    
     public Buffer(byte data[]) {
         this(data, 0, data.length);
     }

Added: activemq/sandbox/activemq-flow/hawtdb/README
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/README?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/README (added)
+++ activemq/sandbox/activemq-flow/hawtdb/README Thu Oct 15 17:04:11 2009
@@ -0,0 +1,4 @@
+=======================================================================
+ HawtDB : An Embedded Lightweight Non-Relational Database
+=======================================================================
+

Added: activemq/sandbox/activemq-flow/hawtdb/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/pom.xml?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/pom.xml (added)
+++ activemq/sandbox/activemq-flow/hawtdb/pom.xml Thu Oct 15 17:04:11 2009
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <parent>
+    <groupId>org.apache.activemq</groupId>
+    <artifactId>activemq-parent</artifactId>
+    <version>6.0-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.activemq</groupId>
+  <artifactId>hawtdb</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>${pom.artifactId}</name>
+  <description>
+    HawtDB is a library for managing a database. The database is a file that allows you to store data in indexes. 
+    Each index is a map of key value pairs.</description>
+
+  <repositories>
+    <repository>
+      <id>maven2-repository.dev.java.net</id>
+      <name>Java.net Repository for Maven</name>
+      <url>http://download.java.net/maven/2/</url>
+    </repository>
+  </repositories>
+
+  <dependencies>
+  
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-util</artifactId>
+    </dependency>
+  
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javolution</groupId>
+      <artifactId>javolution</artifactId>
+      <version>5.3.1</version>
+    </dependency>  
+
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
+          <forkMode>once</forkMode>
+          <argLine>-enableassertions</argLine>
+          <failIfNoTests>false</failIfNoTests>
+          <workingDirectory>${project.build.directory}</workingDirectory>
+          <includes>
+            <include>**/*Test.java</include>
+          </includes>
+          <excludes>
+            <exclude>**/**</exclude>
+          </excludes>
+          <parallel>methods</parallel>
+          <threadCount>16</threadCount>
+        </configuration>
+      </plugin>
+    
+      <!--
+      <plugin>
+        <groupId>org.apache.activemq.protobuf</groupId>
+        <artifactId>activemq-protobuf</artifactId>
+        <version>1.1-SNAPSHOT</version>
+        <configuration>
+          <type>alt</type>
+        </configuration>
+         <executions>
+          <execution>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      -->
+      <!-- 
+      <plugin>
+        <groupId>org.fusesource.mvnplugins</groupId>
+        <artifactId>maven-avro-plugin</artifactId>
+        <version>1.3-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+       -->       
+  </plugins>
+  </build>
+    
+  
+</project>

Propchange: activemq/sandbox/activemq-flow/hawtdb/pom.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Allocator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Allocator.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Allocator.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Allocator.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+/**
+ * Handles allocation management of resources.  Used for page allocations
+ * in a {@link Paged} resource.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public interface Allocator { 
+
+    /**
+     * Allocates a continuous number of items and returns the position of first item in the sequence.
+     */
+    public int alloc(int count) throws OutOfSpaceException;
+
+    /**
+     * Frees a given number of items at a given position.
+     */
+    public void free(int firstPage, int count);
+
+    /**
+     * Undoes a previous free method call.
+     * 
+     * optional method. implementations my throw UnsupportedOperationException
+     * @throws UnsupportedOperationException may be thrown by some allocators.
+     */
+    public void unfree(int firstPage, int count) throws UnsupportedOperationException;
+
+    /**
+     * Frees all previous allocations.
+     * 
+     * optional method. implementations my throw UnsupportedOperationException
+     * @throws UnsupportedOperationException 
+     */
+    public void clear() throws UnsupportedOperationException;
+       
+    public int getLimit();
+    
+    public boolean isAllocated(int page);
+}
\ No newline at end of file

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/EncoderDecoder.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/EncoderDecoder.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/EncoderDecoder.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/EncoderDecoder.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+import java.util.List;
+
+
+/**
+ * Encodes objects to a page file and decodes them from a page file.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ * @param <T>
+ */
+public interface EncoderDecoder<T> {
+    
+    /**
+     * Store a value at the specified page.
+     * 
+     * Object encoding will be deferred as long as possible.  This allows multiple updates
+     * the the same page to avoid paying the cost of multiple encoding passes.  Only when
+     * the value is evicted from the cache or the page file is flushed, will the encoding
+     * take place.
+     * 
+     * Since the deferred encoding is no longer taking place in the context of a transaction,
+     * there are several restrictions of what pages the Marshaler can update so that transaction
+     * isolation is not violated:
+     * <ul> 
+     * <li>It can update the specified page<li>
+     * <li>It can allocate new pages and update or free those pages</li>
+     * </ul>
+     * 
+     * @param paged
+     * @param page
+     * @param value
+     * @return a list of any pages allocated by the method.
+     */
+    List<Integer> store(Paged paged, int page, T value);
+    
+    /**
+     * Load a value from a specified page.  It should not attempt do any
+     * update operations against the {@link Paged} object.
+     * 
+     * @param paged
+     * @param page
+     * @return
+     */
+    T load(Paged paged, int page);
+    
+    /**
+     * Frees any pages associated with the value stored at the given page if any.  Does not free
+     * the page supplied.
+     * 
+     * @param paged
+     * @param page
+     */
+    void remove(Paged paged, int page);
+}
\ No newline at end of file

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IOPagingException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IOPagingException.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IOPagingException.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IOPagingException.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class IOPagingException extends PagingException {
+
+    private static final long serialVersionUID = -886491791391276951L;
+
+    public IOPagingException() {
+        super();
+    }
+
+    public IOPagingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IOPagingException(String message) {
+        super(message);
+    }
+
+    public IOPagingException(Throwable cause) {
+        super(cause);
+    }
+    
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Index.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Provides Key/Value storage and retrieval. 
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public interface Index<Key,Value> extends Iterable<Map.Entry<Key, Value>> {
+
+    /**
+     * Frees any extra storage that the index created.
+     */
+    void destroy();
+    
+    /**
+     * clear the index
+     * 
+     * @throws IOException
+     * 
+     */
+    void clear();
+
+    /**
+     * @param key
+     * @return true if it contains the key
+     * @throws IOException
+     */
+    boolean containsKey(Key key);
+
+    /**
+     * remove the index key
+     * 
+     * @param key
+     * @return StoreEntry removed
+     * @throws IOException
+     */
+    Value remove(Key key);
+
+    /**
+     * store the key, item
+     * 
+     * @param key
+     * @param entry
+     * @throws IOException
+     */
+    Value put(Key key, Value entry);
+
+    /**
+     * @param key
+     * @return the entry
+     * @throws IOException
+     */
+    Value get(Key key);
+    
+    int size();
+    
+    /**
+     * @param tx
+     * @return
+     * @throws IOException
+     * @trhows UnsupportedOperationException 
+     *         if the index does not support fast iteration of the elements.
+     */
+    Iterator<Map.Entry<Key,Value>> iterator() throws UnsupportedOperationException;
+
+    int getPage();
+    
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexException.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexException.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexException.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+/**
+ * This exception is thrown by index implementation why they detect an error.
+ *  
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class IndexException extends RuntimeException {
+
+    private static final long serialVersionUID = -886491791391276951L;
+
+    public IndexException() {
+        super();
+    }
+
+    public IndexException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IndexException(String message) {
+        super(message);
+    }
+
+    public IndexException(Throwable cause) {
+        super(cause);
+    }
+    
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/IndexVisitor.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,199 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+import java.util.List;
+
+/**
+ * Interface used to selectively visit the entries in a sorted index.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public interface IndexVisitor<Key, Value> {
+
+    /**
+     * Do you want to visit the range of BTree entries between the first and and
+     * second key?
+     * 
+     * @param first
+     *            if null indicates the range of values before the second key.
+     * @param second
+     *            if null indicates the range of values after the first key.
+     * @return true if you want to visit the values between the first and second
+     *         key.
+     */
+    boolean isInterestedInKeysBetween(Key first, Key second);
+
+    /**
+     * The keys and values of a BTree leaf node.
+     * 
+     * @param keys
+     * @param values
+     */
+    void visit(List<Key> keys, List<Value> values);
+
+    /**
+     * If the visitor wishes to
+     * 
+     * @return
+     */
+    boolean isSatiated();
+
+    abstract class GTVisitor<Key extends Comparable<? super Key>, Value> implements IndexVisitor<Key, Value> {
+        final private Key value;
+        int matches = Integer.MAX_VALUE;
+        boolean limited;
+
+        public GTVisitor(Key value) {
+            this.value = value;
+        }
+
+        public GTVisitor(Key value, int limit) {
+            this.value = value;
+            limited = true;
+            matches = limit;
+        }
+
+        public boolean isInterestedInKeysBetween(Key first, Key second) {
+            return second == null || second.compareTo(value) > 0;
+        }
+
+        public void visit(List<Key> keys, List<Value> values) {
+            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
+                Key key = keys.get(i);
+                if (key.compareTo(value) > 0) {
+                    matched(key, values.get(i));
+                    if (limited) matches--;
+                }
+            }
+        }
+
+        public boolean isSatiated() {
+            return limited && matches <= 0;
+        }
+
+        abstract protected void matched(Key key, Value value);
+    }
+
+    abstract class GTEVisitor<Key extends Comparable<? super Key>, Value> implements IndexVisitor<Key, Value> {
+        final private Key value;
+        int matches = Integer.MAX_VALUE;
+        boolean limited;
+
+        public GTEVisitor(Key value) {
+            this.value = value;
+        }
+        
+        public GTEVisitor(Key value, int limit) {
+            this.value = value;
+            limited = true;
+            matches = limit;
+        }
+
+        public boolean isInterestedInKeysBetween(Key first, Key second) {
+            return second == null || second.compareTo(value) >= 0;
+        }
+
+        public void visit(List<Key> keys, List<Value> values) {
+            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
+                Key key = keys.get(i);
+                if (key.compareTo(value) >= 0) {
+                    matched(key, values.get(i));
+                    if (limited) matches--;
+                }
+            }
+        }
+
+        public boolean isSatiated() {
+            return limited && matches <= 0;
+        }
+
+        abstract protected void matched(Key key, Value value);
+    }
+
+    abstract class LTVisitor<Key extends Comparable<? super Key>, Value> implements IndexVisitor<Key, Value> {
+        final private Key value;
+        int matches = Integer.MAX_VALUE;
+        boolean limited;
+
+        public LTVisitor(Key value) {
+            this.value = value;
+        }
+        
+        public LTVisitor(Key value, int limit) {
+            this.value = value;
+            limited = true;
+            matches = limit;
+        }
+
+        public boolean isInterestedInKeysBetween(Key first, Key second) {
+            return first == null || first.compareTo(value) < 0;
+        }
+
+        public void visit(List<Key> keys, List<Value> values) {
+            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
+                Key key = keys.get(i);
+                if (key.compareTo(value) < 0) {
+                    matched(key, values.get(i));
+                    if (limited) matches--;
+                }
+            }
+        }
+
+        public boolean isSatiated() {
+            return limited && matches <= 0;
+        }
+
+        abstract protected void matched(Key key, Value value);
+    }
+
+    abstract class LTEVisitor<Key extends Comparable<? super Key>, Value> implements IndexVisitor<Key, Value> {
+        final private Key value;
+        int matches = Integer.MAX_VALUE;
+        boolean limited;
+
+        public LTEVisitor(Key value) {
+            this.value = value;
+        }
+
+        public LTEVisitor(Key value, int limit) {
+            this.value = value;
+            limited = true;
+            matches = limit;
+        }
+        
+        public boolean isInterestedInKeysBetween(Key first, Key second) {
+            return first == null || first.compareTo(value) <= 0;
+        }
+
+        public void visit(List<Key> keys, List<Value> values) {
+            for (int i = 0; i < keys.size() && !isSatiated(); i++) {
+                Key key = keys.get(i);
+                if (key.compareTo(value) <= 0) {
+                    matched(key, values.get(i));
+                    if (limited) matches--;
+                }
+            }
+        }
+
+        public boolean isSatiated() {
+            return limited && matches <= 0;
+        }
+
+        abstract protected void matched(Key key, Value value);
+    }
+}
\ No newline at end of file

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OptimisticUpdateException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OptimisticUpdateException.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OptimisticUpdateException.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OptimisticUpdateException.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class OptimisticUpdateException extends PagingException {
+
+    private static final long serialVersionUID = -2790437157681366495L;
+
+    public OptimisticUpdateException() {
+    }
+
+    public OptimisticUpdateException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public OptimisticUpdateException(String message) {
+        super(message);
+    }
+
+    public OptimisticUpdateException(Throwable cause) {
+        super(cause);
+    }
+
+
+    
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OutOfSpaceException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OutOfSpaceException.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OutOfSpaceException.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/OutOfSpaceException.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class OutOfSpaceException extends PagingException {
+
+    private static final long serialVersionUID = -886491791391276951L;
+
+    public OutOfSpaceException() {
+        super();
+    }
+
+    public OutOfSpaceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public OutOfSpaceException(String message) {
+        super(message);
+    }
+
+    public OutOfSpaceException(Throwable cause) {
+        super(cause);
+    }
+    
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Paged.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Paged.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Paged.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Paged.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,129 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+import java.nio.ByteBuffer;
+
+import org.apache.activemq.util.buffer.Buffer;
+import org.apache.hawtdb.internal.page.ConcurrentPageFile;
+
+/**
+ * Gets a named cache.
+ * 
+ * The cache can be used to reduce the CPU load of encoding an decoding complex
+ * objects from the page file.
+ * 
+ * Pages that are being read/updated via the cache should not be accessed
+ * directly via the Paged interface. The Cache will delay encoding objects until
+ * a {@link ConcurrentPageFile#flush()} occurs. During that time, page data
+ * returned from the {@link Paged} interface will be inconsistent with what was
+ * stored in the Cache.
+ * 
+ * The Cache is transactional and will remain coherent even using the same
+ * snapshot isolation level provided to the page data.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public interface Paged {
+
+    /**
+     * @return An object which provides access to allocate/deallocate pages.
+     */
+    Allocator allocator();
+
+    enum SliceType {
+        READ, WRITE, READ_WRITE
+    }
+
+    /**
+     * Provides direct access to the memory associated with a page. Specifying
+     * the correct mode argument is especially critical and the Paged resources
+     * is being accessed in a transaction context so that the transaction can
+     * maintain snapshot isolation.
+     * 
+     * @param mode
+     *            how will the buffer be used.
+     * @param pageId
+     *            the starting page of the buffer
+     * @param count
+     *            the number of pages to include in the buffer.
+     * @return
+     * @throws IOPagingException
+     */
+    public ByteBuffer slice(SliceType mode, int pageId, int count) throws IOPagingException;
+
+    public void unslice(ByteBuffer buffer);
+
+    /**
+     * Copies the contents of a page into the buffer space. The buffer offset
+     * will be updated to reflect the amount of data copied into the buffer.
+     * 
+     * @param pageId
+     * @param buffer
+     */
+    public void read(int pageId, Buffer buffer);
+
+    /**
+     * Copies the buffer into the page. The buffer offset will be updated to
+     * reflect the amount of data copied to the page.
+     * 
+     * @param pageId
+     * @param buffer
+     */
+    public void write(int pageId, Buffer buffer);
+
+    /**
+     * @return the maximum number of bytes that be read or written to a page.
+     */
+    int getPageSize();
+
+    /**
+     * @return the number of pages that would be required to store the specified
+     *         number of bytes
+     */
+    int pages(int length);
+    
+    void flush();
+    
+    
+    /**
+     * Gets an object previously put at the given page.  The returned object SHOULD NEVER be mutated.
+     *  
+     * @param page
+     * @return
+     */
+    <T> T get(EncoderDecoder<T> encoderDecoder, int page);
+    
+    /**
+     * Put an object at a given page.  The supplied object SHOULD NEVER be mutated 
+     * once it has been stored.
+     * 
+     * @param page
+     * @param value
+     */
+    <T> void put(EncoderDecoder<T> encoderDecoder, int page, T value);
+    
+    /**
+     * Frees any pages associated with the value stored at the given page if any.  Does not free
+     * the page supplied.
+     *  
+     * @param page
+     * @return
+     */
+    <T> void remove(EncoderDecoder<T> encoderDecoder, int page);
+
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/PagingException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/PagingException.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/PagingException.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/PagingException.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class PagingException extends RuntimeException {
+
+    private static final long serialVersionUID = -886491791391276951L;
+
+    public PagingException() {
+        super();
+    }
+
+    public PagingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public PagingException(String message) {
+        super(message);
+    }
+
+    public PagingException(Throwable cause) {
+        super(cause);
+    }
+    
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Transaction.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Transaction.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Transaction.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/Transaction.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.api;
+
+
+
+/**
+ * Provides transactional access to a {@link Paged} resource.
+ * The transaction provides snapshot isolation.  The snapshot view
+ * of the entire page file is obtained the first time you read data 
+ * from a page.  Committed page updates from concurrent transactions will
+ * not be visible to the snapshot.
+ * 
+ * The snapshot view of the page file is released once the transaction 
+ * commits or is rolled back.  Avoid holding a snapshot view for a long time.
+ * The page file cannot reclaim temporary processing space associated with
+ * a snapshot and subsequent snapshots while the snapshot is in use.
+ * 
+ * Pages are optimistically updated, which means they are not locked for 
+ * update.  Updating a page or committing the transaction may fail 
+ * with an {@line OptimisticUpdateException} if another committed transaction
+ * has updated the same page this transaction was trying to update.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public interface Transaction extends Paged {
+    
+    /**
+     * @return true if no updates have been performed by this transaction.
+     */
+    boolean isReadOnly();
+    
+    /**
+     * @throws OptimisticUpdateException 
+     *      is thrown if the update would conflict with a concurrent 
+     *      updated performed by another thread.
+     */
+    void commit() throws OptimisticUpdateException;
+    
+    /**
+     * 
+     */
+	void rollback();
+	
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/package.html
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/package.html?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/package.html (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/package.html Thu Oct 15 17:04:11 2009
@@ -0,0 +1,27 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+<p>The HawDB client API</p>
+
+<p>As implementation interfaces harden up, they will get moved into this package.</p>
+
+</body>
+</html>

Propchange: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/api/package.html
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIndex.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIndex.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIndex.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIndex.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,241 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.internal.index;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.activemq.util.marshaller.Marshaller;
+import org.apache.hawtdb.api.IndexVisitor;
+import org.apache.hawtdb.api.Index;
+import org.apache.hawtdb.api.Paged;
+import org.apache.hawtdb.internal.index.BTreeNode.Data;
+
+
+/**
+ * BTreeIndex represents a Variable Magnitude B+Tree in a Page File. A BTree is
+ * a bit flexible in that it can be used for set or map-based indexing. Leaf
+ * nodes are linked together for faster iteration of the values.
+ * 
+ * <br>
+ * The Variable Magnitude attribute means that the BTree attempts to store as
+ * many values and pointers on one page as is possible.
+ * 
+ * <br>
+ * The implementation can optionally a be Simple-Prefix B+Tree.
+ * 
+ * <br>
+ * For those who don't know how a Simple-Prefix B+Tree works, the primary
+ * distinction is that instead of promoting actual keys to branch pages, when
+ * leaves are split, a shortest-possible separator is generated at the pivot.
+ * That separator is what is promoted to the parent branch (and continuing up
+ * the list). As a result, actual keys and pointers can only be found at the
+ * leaf level. This also affords the index the ability to ignore costly merging
+ * and redistribution of pages when deletions occur. Deletions only affect leaf
+ * pages in this implementation, and so it is entirely possible for a leaf page
+ * to be completely empty after all of its keys have been removed.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class BTreeIndex<Key, Value> implements Index<Key, Value> {
+
+    static class Factory<Key, Value> {
+
+        private Marshaller<Key> keyMarshaller;
+        private Marshaller<Value> valueMarshaller;
+
+        public BTreeIndex<Key, Value> create(Paged paged, int page) {
+            BTreeIndex<Key, Value> index = createInstance(paged, page);
+            BTreeNode<Key, Value> root = new BTreeNode<Key, Value>(page);
+            index.storeNode(root); // Store the root page..
+            return index;
+        }
+        
+        public BTreeIndex<Key, Value> open(Paged paged, int page) {
+            BTreeIndex<Key, Value> index = createInstance(paged, page);
+            return index;
+        }
+
+        private BTreeIndex<Key, Value> createInstance(Paged paged, int page) {
+            if (keyMarshaller == null) {
+                throw new IllegalArgumentException("The key marshaller must be set before calling open");
+            }
+            if (valueMarshaller == null) {
+                throw new IllegalArgumentException("The key marshaller must be set before calling open");
+            }
+            return new BTreeIndex<Key, Value>(paged, page, keyMarshaller, valueMarshaller, null);
+        }
+
+        public Marshaller<Key> getKeyMarshaller() {
+            return keyMarshaller;
+        }
+
+        public void setKeyMarshaller(Marshaller<Key> keyMarshaller) {
+            this.keyMarshaller = keyMarshaller;
+        }
+
+        public Marshaller<Value> getValueMarshaller() {
+            return valueMarshaller;
+        }
+
+        public void setValueMarshaller(Marshaller<Value> valueMarshaller) {
+            this.valueMarshaller = valueMarshaller;
+        }
+    }
+
+    private final BTreeNode.BTreeNodeEncoderDecoder<Key, Value> PAGE_ENCODER_DECODER = new BTreeNode.BTreeNodeEncoderDecoder<Key, Value>(this);
+
+    private final Paged paged;
+    private final int page;
+    private final Marshaller<Key> keyMarshaller;
+    private final Marshaller<Value> valueMarshaller;
+    private final Prefixer<Key> prefixer;
+    
+    private BTreeIndex(Paged paged, int page, Marshaller<Key> keyMarshaller, Marshaller<Value> valueMarshaller, Prefixer<Key> prefixer) {
+        this.paged = paged;
+        this.page = page;
+        this.keyMarshaller = keyMarshaller;
+        this.valueMarshaller = valueMarshaller;
+        this.prefixer = prefixer;
+    }
+
+    public boolean containsKey(Key key) {
+        return root().contains(this, key);
+    }
+
+    public Value get(Key key) {
+        return root().get(this, key);
+    }
+
+    public Value put(Key key, Value value) {
+        return root().put(this, key, value);
+    }
+
+    public Value remove(Key key) {
+        return root().remove(this, key);
+    }
+
+    public boolean isTransient() {
+        return false;
+    }
+
+    public void clear() {
+        root().clear(this);
+    }
+
+    public int getMinLeafDepth() {
+        return root().getMinLeafDepth(this, 0);
+    }
+
+    public int getMaxLeafDepth() {
+        return root().getMaxLeafDepth(this, 0);
+    }
+
+    public void printStructure(PrintWriter out) {
+        root().printStructure(this, out, "");
+    }
+
+    public void printStructure(OutputStream out) {
+        PrintWriter pw = new PrintWriter(out, false);
+        root().printStructure(this, pw, "");
+        pw.flush();
+    }
+
+    public Iterator<Map.Entry<Key, Value>> iterator() {
+        return root().iterator(this);
+    }
+
+    public Iterator<Map.Entry<Key, Value>> iterator(final Key initialKey) {
+        return root().iterator(this, initialKey);
+    }
+
+    public void visit(IndexVisitor<Key, Value> visitor) {
+        root().visit(this, visitor);
+    }
+
+    public Map.Entry<Key, Value> getFirst() {
+        return root().getFirst(this);
+    }
+
+    public Map.Entry<Key, Value> getLast() {
+        return root().getLast(this);
+    }
+
+    // /////////////////////////////////////////////////////////////////
+    // Internal implementation methods
+    // /////////////////////////////////////////////////////////////////
+    private BTreeNode<Key, Value> root() {
+        return loadNode(page);
+    }
+
+    // /////////////////////////////////////////////////////////////////
+    // Internal methods made accessible to BTreeNode
+    // /////////////////////////////////////////////////////////////////
+    BTreeNode<Key, Value> createNode(Data<Key, Value> data) {
+        return new BTreeNode<Key, Value>(paged.allocator().alloc(1), data);
+    }
+    
+    void storeNode(BTreeNode<Key, Value> node) {
+        paged.put(PAGE_ENCODER_DECODER, node.getPage(), node);
+    }
+    
+    BTreeNode<Key, Value> loadNode(int page) {
+        BTreeNode<Key, Value> node = paged.get(PAGE_ENCODER_DECODER, page);
+        node.setPage(page);
+        return node;
+    }
+    
+    void free( int page ) {
+        paged.remove(PAGE_ENCODER_DECODER, page);
+        paged.allocator().free(page, 1);
+    }
+
+    // /////////////////////////////////////////////////////////////////
+    // Property Accessors
+    // /////////////////////////////////////////////////////////////////
+
+    public Paged getPaged() {
+        return paged;
+    }
+
+    public int getPage() {
+        return page;
+    }
+
+    public Marshaller<Key> getKeyMarshaller() {
+        return keyMarshaller;
+    }
+
+    public Marshaller<Value> getValueMarshaller() {
+        return valueMarshaller;
+    }
+
+    public Prefixer<Key> getPrefixer() {
+        return prefixer;
+    }
+
+    public void destroy() {
+        // TODO Auto-generated method stub
+    }
+
+    public int size() {
+        return root().size(this);
+    }
+
+}

Added: activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIterator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIterator.java?rev=825564&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIterator.java (added)
+++ activemq/sandbox/activemq-flow/hawtdb/src/main/java/org/apache/hawtdb/internal/index/BTreeIterator.java Thu Oct 15 17:04:11 2009
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hawtdb.internal.index;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Map.Entry;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+final class BTreeIterator<Key, Value> implements Iterator<Map.Entry<Key, Value>> {
+
+    private final BTreeIndex<Key, Value> index;
+    BTreeNode<Key, Value> current;
+    int nextIndex;
+    Map.Entry<Key, Value> nextEntry;
+
+    BTreeIterator(BTreeIndex<Key, Value> index, BTreeNode<Key, Value> current, int nextIndex) {
+        this.index = index;
+        this.current = current;
+        this.nextIndex = nextIndex;
+    }
+
+    private void findNextPage() {
+        if (nextEntry != null) {
+            return;
+        }
+
+        while (current != null) {
+            if (nextIndex >= current.data.keys.length) {
+                // we need to roll to the next leaf..
+                if (current.data.next >= 0) {
+                    current = index.loadNode(current.data.next);
+                    nextIndex = 0;
+                } else {
+                    break;
+                }
+            } else {
+                nextEntry = new KeyValueEntry<Key, Value>(current.data.keys[nextIndex], current.data.values[nextIndex]);
+                nextIndex++;
+                break;
+            }
+
+        }
+    }
+
+    public boolean hasNext() {
+        findNextPage();
+        return nextEntry != null;
+    }
+
+    public Entry<Key, Value> next() {
+        findNextPage();
+        if (nextEntry != null) {
+            Entry<Key, Value> lastEntry = nextEntry;
+            nextEntry = null;
+            return lastEntry;
+        } else {
+            throw new NoSuchElementException();
+        }
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+}
\ No newline at end of file