Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 62450 invoked from network); 18 Jul 2008 15:50:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Jul 2008 15:50:20 -0000 Received: (qmail 24696 invoked by uid 500); 18 Jul 2008 15:50:20 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 24679 invoked by uid 500); 18 Jul 2008 15:50:20 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 24669 invoked by uid 99); 18 Jul 2008 15:50:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Jul 2008 08:50:20 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Jul 2008 15:49:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2EB8F238896E; Fri, 18 Jul 2008 08:49:58 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r677944 [1/11] - in /activemq/sandbox/kahadb: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/kahadb/ src/main/java/org/apache/kahadb/impl/ src/main/java/org/apache/kahadb/impl/async/ s... Date: Fri, 18 Jul 2008 15:49:52 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080718154958.2EB8F238896E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chirino Date: Fri Jul 18 08:49:48 2008 New Revision: 677944 URL: http://svn.apache.org/viewvc?rev=677944&view=rev Log: creating a little kahadb module where we can evovle kaha some more without breaking ActiveMQ Added: activemq/sandbox/kahadb/README activemq/sandbox/kahadb/pom.xml (with props) activemq/sandbox/kahadb/src/ activemq/sandbox/kahadb/src/main/ activemq/sandbox/kahadb/src/main/java/ activemq/sandbox/kahadb/src/main/java/org/ activemq/sandbox/kahadb/src/main/java/org/apache/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/BytesMarshaller.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ContainerId.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/IndexMBean.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ListContainer.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/MapContainer.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Marshaller.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ObjectMarshaller.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/RuntimeStoreException.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Store.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreEntry.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreFactory.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreLocation.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StringMarshaller.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/DataManager.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/IndexRootContainer.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/KahaStore.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/StoreLockedExcpetion.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/AsyncDataManager.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/ControlFile.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/DataFile.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/DataFileAccessor.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/DataFileAccessorPool.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/DataFileAppender.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/DataManagerFacade.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/Location.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/NIODataFileAppender.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/ReadOnlyAsyncDataManager.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/ReadOnlyDataFile.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/async/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/BaseContainerImpl.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerCollectionSupport.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerEntrySet.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerEntrySetIterator.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerKeySet.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerKeySetIterator.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerListIterator.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerMapEntry.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerValueCollection.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ContainerValueCollectionIterator.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/ListContainerImpl.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/MapContainerImpl.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/container/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/DataFile.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/DataItem.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/DataManagerImpl.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/Item.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/RedoListener.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/SyncDataFileReader.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/SyncDataFileWriter.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/data/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/BadMagicException.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/DiskIndexLinkedList.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/Index.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/IndexItem.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/IndexLinkedList.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/IndexManager.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/RedoStoreIndexItem.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/StoreIndexReader.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/StoreIndexWriter.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/VMIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/VMIndexLinkedList.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/HashBin.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/HashEntry.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/HashIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/HashIndexMBean.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/HashPage.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/HashPageInfo.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/hash/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/tree/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/tree/TreeEntry.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/tree/TreeIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/tree/TreePage.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/tree/TreePageEntry.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/index/tree/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/package.html (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/ByteArrayInputStream.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/ByteArrayOutputStream.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/ByteSequence.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/DataByteArrayInputStream.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/DataByteArrayOutputStream.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/HexSupport.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/IOExceptionSupport.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/IOHelper.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/LRUCache.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/LinkedNode.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/Scheduler.java (with props) activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/util/SchedulerTimerTask.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/FaultCodes.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/Index.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/IndexException.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/Key.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/Record.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/RecordSet.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/Value.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/btree/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/btree/BTree.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/btree/BTreeCallback.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/btree/BTreeCorruptException.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/btree/BTreeIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/btree/BTreeNotFoundException.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/fs/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/fs/FileCache.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/fs/FileSystemIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/fs/LockManager.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/hash/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/hash/HashIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/mem/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/mem/MemIndex.java activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/page/ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/xindice/page/Paged.java activemq/sandbox/kahadb/src/main/resources/ activemq/sandbox/kahadb/src/test/ activemq/sandbox/kahadb/src/test/java/ activemq/sandbox/kahadb/src/test/java/org/ activemq/sandbox/kahadb/src/test/java/org/apache/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/ListContainerTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/LoadTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/Loader.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/MapContainerTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/StoreTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/VolumeTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/async/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/async/DataFileAppenderTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/async/NioDataFileAppenderTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/DiskIndexLinkedListTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/IndexBenchmark.java (with props) activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/VMIndexLinkedListTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/hash/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/hash/HashIndexBenchMark.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/hash/HashTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/tree/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/impl/index/tree/TreeTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/IndexBenchmark.java (with props) activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/IndexTestBase.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/btree/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/btree/BTreeIndexBenchmark.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/btree/BTreeIndexTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/fs/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/fs/FileSystemIndexTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/hash/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/hash/HashIndexBenchmark.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/hash/HashIndexTest.java activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/mem/ activemq/sandbox/kahadb/src/test/java/org/apache/kahadb/xindice/mem/MemIndexTest.java activemq/sandbox/kahadb/src/test/resources/ Added: activemq/sandbox/kahadb/README URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/README?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/README (added) +++ activemq/sandbox/kahadb/README Fri Jul 18 08:49:48 2008 @@ -0,0 +1,24 @@ +======================================================================= + KahaDB : An Embedded Lightweight Non-Relational Database +======================================================================= + +Goals: + * Provide a simple collections based interface for storing persistent + data. + * Provide a lower level key value interface for storing data. Secondary + keys should be supported. + * Fast recovery + +Status: + * Moved the org.apache.activemq.kaha package into this module + and renamed it as org.apache.kahadb + * Moved a refactored version of the low level indexing logic + used by Apache xindice to the org.apache.kahadb.xindice page. + +TODO: + * None of our current index support fast recovery. They suffer + from partial page write failures so on a crash, they have + to be fully rebuilt from the data logs. + * Indexes should know what the last transaction id that updated + it, so that missing operations can be replayed. + * Investigate implementing data log replication for HA. \ No newline at end of file Added: activemq/sandbox/kahadb/pom.xml URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/pom.xml?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/pom.xml (added) +++ activemq/sandbox/kahadb/pom.xml Fri Jul 18 08:49:48 2008 @@ -0,0 +1,81 @@ + + + + + org.apache + apache + 4 + + 4.0.0 + + org.apache.activemq + kahadb + 1.0-SNAPSHOT + + + + commons-logging + commons-logging + 1.1 + + + avalon-framework + avalon-framework + + + logkit + logkit + + + log4j + log4j + + + javax.servlet + servlet-api + + + + + junit + junit + 3.8.1 + test + + + log4j + log4j + 1.2.14 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + Propchange: activemq/sandbox/kahadb/pom.xml ------------------------------------------------------------------------------ svn:executable = * Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/BytesMarshaller.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/BytesMarshaller.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/BytesMarshaller.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/BytesMarshaller.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,55 @@ +/** + * 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.kahadb; + +import java.io.DataInput; +import java.io.DataOutput; +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, DataOutput 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(DataInput dataIn) throws IOException { + int size = dataIn.readInt(); + byte[] data = new byte[size]; + dataIn.readFully(data); + return data; + } +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ContainerId.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ContainerId.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ContainerId.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ContainerId.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,95 @@ +/** + * 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.kahadb; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * Used by RootContainers + * + * @version $Revision: 1.1.1.1 $ + */ +public class ContainerId implements Externalizable { + private static final long serialVersionUID = -8883779541021821943L; + private Object key; + private String dataContainerName; + + public ContainerId() { + } + + public ContainerId(Object key, String dataContainerName) { + this.key = key; + this.dataContainerName = dataContainerName; + } + + /** + * @return Returns the dataContainerPrefix. + */ + public String getDataContainerName() { + return dataContainerName; + } + + /** + * @param dataContainerName The dataContainerPrefix to set. + */ + public void setDataContainerName(String dataContainerName) { + this.dataContainerName = dataContainerName; + } + + /** + * @return Returns the key. + */ + public Object getKey() { + return key; + } + + /** + * @param key The key to set. + */ + public void setKey(Object key) { + this.key = key; + } + + public int hashCode() { + return key.hashCode() ^ dataContainerName.hashCode(); + } + + public boolean equals(Object obj) { + if (obj == null || obj.getClass() != ContainerId.class) { + return false; + } + ContainerId other = (ContainerId)obj; + return other.key.equals(this.key) && other.dataContainerName.equals(this.dataContainerName); + } + + public void writeExternal(ObjectOutput out) throws IOException { + out.writeUTF(getDataContainerName()); + out.writeObject(key); + } + + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + dataContainerName = in.readUTF(); + key = in.readObject(); + } + + public String toString() { + return "CID{" + dataContainerName + ":" + key + "}"; + } +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/IndexMBean.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/IndexMBean.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/IndexMBean.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/IndexMBean.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,26 @@ +/** + * 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.kahadb; + +/** + * Index MBean + * + */ +public interface IndexMBean { + int getSize(); + boolean isTransient(); +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ListContainer.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ListContainer.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ListContainer.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ListContainer.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,186 @@ +/** + * 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.kahadb; + +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 + */ + void load(); + + /** + * unload indexes from the container + * + */ + void unload(); + + /** + * @return true if the indexes are loaded + */ + boolean isLoaded(); + + /** + * For homogenous containers can set a custom marshaller for loading values + * The default uses Object serialization + * + * @param marshaller + */ + void setMarshaller(Marshaller marshaller); + + /** + * @return the id the MapContainer was create with + */ + Object getId(); + + /** + * @return the number of values in the container + */ + 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. + */ + void addFirst(V o); + + /** + * Appends the given element to the end of this list. (Identical in function + * to the add method; included only for consistency.) + * + * @param o the element to be inserted at the end of this list. + */ + void addLast(V o); + + /** + * Removes and returns the first element from this list. + * + * @return the first element from this list. + * @throws NoSuchElementException if this list is empty. + */ + V removeFirst(); + + /** + * Removes and returns the last element from this list. + * + * @return the last element from this list. + * @throws NoSuchElementException if this list is empty. + */ + V removeLast(); + + /** + * remove an objecr from the list without retrieving the old value from the + * store + * + * @param position + * @return true if successful + */ + boolean doRemove(int position); + + /** + * add an Object to the list but get a StoreEntry of its position + * + * @param object + * @return the entry in the Store + */ + StoreEntry placeLast(V object); + + /** + * insert an Object in first position int the list but get a StoreEntry of + * its position + * + * @param object + * @return the location in the Store + */ + StoreEntry placeFirst(V object); + + /** + * Advanced feature = must ensure the object written doesn't overwrite other + * objects in the container + * + * @param entry + * @param object + */ + void update(StoreEntry entry, V object); + + /** + * Retrieve an Object from the Store by its location + * + * @param entry + * @return the Object at that entry + */ + V get(StoreEntry entry); + + /** + * Get the StoreEntry for the first item of the list + * + * @return the first StoreEntry or null if the list is empty + */ + StoreEntry getFirst(); + + /** + * Get the StoreEntry for the last item of the list + * + * @return the last StoreEntry or null if the list is empty + */ + StoreEntry getLast(); + + /** + * Get the next StoreEntry from the list + * + * @param entry + * @return the next StoreEntry or null + */ + StoreEntry getNext(StoreEntry entry); + + /** + * Get the previous StoreEntry from the list + * + * @param entry + * @return the previous store entry or null + */ + StoreEntry getPrevious(StoreEntry entry); + + /** + * remove the Object at the StoreEntry + * + * @param entry + * @return true if successful + */ + boolean remove(StoreEntry entry); + + /** + * It's possible that a StoreEntry could be come stale this will return an + * upto date entry for the StoreEntry position + * + * @param entry old entry + * @return a refreshed StoreEntry + */ + StoreEntry refresh(StoreEntry entry); +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/MapContainer.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/MapContainer.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/MapContainer.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/MapContainer.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,286 @@ +/** + * 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.kahadb; + +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 + */ + void load(); + + /** + * unload indexes from the container + * + */ + void unload(); + + /** + * @return true if the indexes are loaded + */ + boolean isLoaded(); + + /** + * For homogenous containers can set a custom marshaller for loading keys + * The default uses Object serialization + * + * @param keyMarshaller + */ + void setKeyMarshaller(Marshaller keyMarshaller); + + /** + * For homogenous containers can set a custom marshaller for loading values + * The default uses Object serialization + * + * @param valueMarshaller + * + */ + void setValueMarshaller(Marshaller valueMarshaller); + + /** + * @return the id the MapContainer was create with + */ + Object getId(); + + /** + * @return the number of values in the container + */ + int size(); + + /** + * @return true if there are no values stored in the container + */ + boolean isEmpty(); + + /** + * @param key + * @return true if the container contains the key + */ + boolean containsKey(K key); + + /** + * Get the value associated with the key + * + * @param key + * @return the value associated with the key from the store + */ + V get(K key); + + /** + * @param o + * @return true if the MapContainer contains the value o + */ + boolean containsValue(K o); + + /** + * Add add entries in the supplied Map + * + * @param map + */ + void putAll(Map map); + + /** + * @return a Set of all the keys + */ + Set keySet(); + + /** + * @return a collection of all the values - the values will be lazily pulled + * out of the store if iterated etc. + */ + Collection values(); + + /** + * @return a Set of all the Map.Entry instances - the values will be lazily + * pulled out of the store if iterated etc. + */ + Set> entrySet(); + + /** + * Add an entry + * + * @param key + * @param value + * @return the old value for the key + */ + V put(K key, V value); + + /** + * remove an entry associated with the key + * + * @param key + * @return the old value assocaited with the key or null + */ + V remove(K key); + + /** + * empty the container + */ + void clear(); + + /** + * Add an entry to the Store Map + * + * @param key + * @param Value + * @return the StoreEntry associated with the entry + */ + StoreEntry place(K key, V value); + + /** + * Remove an Entry from ther Map + * + * @param entry + */ + void remove(StoreEntry entry); + + /** + * Get the Key object from it's location + * + * @param keyLocation + * @return the key for the entry + */ + K getKey(StoreEntry keyLocation); + + /** + * Get the value from it's location + * + * @param Valuelocation + * @return the Object + */ + V getValue(StoreEntry valueLocation); + + /** + * Get the StoreEntry for the first value in the Map + * + * @return the first StoreEntry or null if the map is empty + */ + StoreEntry getFirst(); + + /** + * Get the StoreEntry for the last value item of the Map + * + * @return the last StoreEntry or null if the list is empty + */ + StoreEntry getLast(); + + /** + * Get the next StoreEntry value from the map + * + * @param entry + * @return the next StoreEntry or null + */ + StoreEntry getNext(StoreEntry entry); + + /** + * Get the previous StoreEntry from the map + * + * @param entry + * @return the previous store entry or null + */ + StoreEntry getPrevious(StoreEntry entry); + + /** + * It's possible that a StoreEntry could be come stale this will return an + * upto date entry for the StoreEntry position + * + * @param entry old entry + * @return a refreshed StoreEntry + */ + StoreEntry refresh(StoreEntry entry); + + /** + * Get the StoreEntry associated with the key + * + * @param key + * @return the StoreEntry + */ + StoreEntry getEntry(K key); + + /** + * Set the index bin size + * @param size + */ + void setIndexBinSize(int size); + + /** + * @return index bin size + */ + int getIndexBinSize(); + + + /** + * Add the index key size + * @param size + */ + void setIndexKeySize(int size); + + + /** + * @return the index key size + */ + int getIndexKeySize(); + + + /** + * Set the index page size + * @param size + */ + void setIndexPageSize(int size); + + /** + * @return the index page size + */ + int getIndexPageSize(); + + /** + * set the meximum bin size + */ + void setIndexMaxBinSize(int size); + + /** + * @return the maximum bin size + * @return + */ + int getIndexMaxBinSize(); + + /** + * @return the loadFactor + */ + public int getIndexLoadFactor(); + /** + * @param loadFactor the loadFactor to set + */ + public void setIndexLoadFactor(int loadFactor); + + /** + * @return the Index MBean + */ + IndexMBean getIndexMBean(); +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Marshaller.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Marshaller.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Marshaller.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Marshaller.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,49 @@ +/** + * 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.kahadb; + +import java.io.DataInput; +import java.io.DataOutput; +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 + */ + void writePayload(T object, DataOutput dataOut) throws IOException; + + + /** + * Read the entry from the RawContainer + * @param dataIn + * @return unmarshalled object + * @throws IOException + */ + T readPayload(DataInput dataIn) throws IOException; + + +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ObjectMarshaller.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ObjectMarshaller.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ObjectMarshaller.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/ObjectMarshaller.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,70 @@ +/** + * 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.kahadb; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInput; +import java.io.DataOutput; +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, DataOutput 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(DataInput 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: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/RuntimeStoreException.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/RuntimeStoreException.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/RuntimeStoreException.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/RuntimeStoreException.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,63 @@ +/** + * 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.kahadb; + +/** + * 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: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Store.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Store.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Store.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/Store.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,295 @@ +/** + * 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.kahadb; + +import java.io.IOException; +import java.util.Set; + +/** + * A Store is holds persistent containers + * + * @version $Revision: 1.2 $ + */ +public interface Store { + /** + * Defauly container name + */ + String DEFAULT_CONTAINER_NAME = "kaha"; + + /** + * Byte Marshaller + */ + Marshaller BYTES_MARSHALLER = new BytesMarshaller(); + + /** + * Object Marshaller + */ + Marshaller OBJECT_MARSHALLER = new ObjectMarshaller(); + + /** + * String Marshaller + */ + Marshaller STRING_MARSHALLER = new StringMarshaller(); + + /** + * close the store + * + * @throws IOException + */ + void close() throws IOException; + + /** + * Force all writes to disk + * + * @throws IOException + */ + void force() throws IOException; + + /** + * empty all the contents of the store + * + * @throws IOException + */ + void clear() throws IOException; + + /** + * delete the store + * + * @return true if the delete was successful + * @throws IOException + */ + boolean delete() throws IOException; + + /** + * Checks if a MapContainer exists in the default container + * + * @param id + * @return new MapContainer + * @throws IOException + */ + boolean doesMapContainerExist(Object id) throws IOException; + + /** + * Checks if a MapContainer exists in the named container + * + * @param id + * @param containerName + * @return new MapContainer + * @throws IOException + */ + boolean doesMapContainerExist(Object id, String containerName) throws IOException; + + /** + * 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 + */ + MapContainer getMapContainer(Object id) throws IOException; + + /** + * Get a MapContainer with the given id - the MapContainer is created if + * needed + * + * @param id + * @param containerName + * @return container for the associated id or null if it doesn't exist + * @throws IOException + */ + MapContainer getMapContainer(Object id, String containerName) throws IOException; + + /** + * Get a MapContainer with the given id - the MapContainer is created if + * needed + * + * @param id + * @param containerName + * @param persistentIndex + * @return container for the associated id or null if it doesn't exist + * @throws IOException + */ + MapContainer getMapContainer(Object id, String containerName, boolean persistentIndex) throws IOException; + + /** + * delete a container from the default container + * + * @param id + * @throws IOException + */ + void deleteMapContainer(Object id) throws IOException; + + /** + * delete a MapContainer from the name container + * + * @param id + * @param containerName + * @throws IOException + */ + void deleteMapContainer(Object id, String containerName) throws IOException; + + /** + * Delete Map container + * + * @param id + * @throws IOException + */ + void deleteMapContainer(ContainerId id) throws IOException; + + /** + * Get a Set of call MapContainer Ids + * + * @return the set of ids + * @throws IOException + */ + Set getMapContainerIds() throws IOException; + + /** + * Checks if a ListContainer exists in the default container + * + * @param id + * @return new MapContainer + * @throws IOException + */ + boolean doesListContainerExist(Object id) throws IOException; + + /** + * Checks if a ListContainer exists in the named container + * + * @param id + * @param containerName + * @return new MapContainer + * @throws IOException + */ + boolean doesListContainerExist(Object id, String containerName) throws IOException; + + /** + * 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 + */ + ListContainer getListContainer(Object id) throws IOException; + + /** + * Get a ListContainer with the given id and creates it if it doesn't exist + * + * @param id + * @param containerName + * @return container for the associated id or null if it doesn't exist + * @throws IOException + */ + ListContainer getListContainer(Object id, String containerName) throws IOException; + + /** + * Get a ListContainer with the given id and creates it if it doesn't exist + * + * @param id + * @param containerName + * @param persistentIndex + * @return container for the associated id or null if it doesn't exist + * @throws IOException + */ + ListContainer getListContainer(Object id, String containerName, boolean persistentIndex) throws IOException; + + /** + * delete a ListContainer from the default container + * + * @param id + * @throws IOException + */ + void deleteListContainer(Object id) throws IOException; + + /** + * delete a ListContainer from the named container + * + * @param id + * @param containerName + * @throws IOException + */ + void deleteListContainer(Object id, String containerName) throws IOException; + + /** + * delete a list container + * + * @param id + * @throws IOException + */ + void deleteListContainer(ContainerId id) throws IOException; + + /** + * Get a Set of call ListContainer Ids + * + * @return the set of ids + * @throws IOException + */ + Set getListContainerIds() throws IOException; + + /** + * @return the maxDataFileLength + */ + long getMaxDataFileLength(); + + /** + * @param maxDataFileLength the maxDataFileLength to set + */ + void setMaxDataFileLength(long maxDataFileLength); + + + /** + * @return true if the store has been initialized + */ + boolean isInitialized(); + + /** + * @return the amount of disk space the store is occupying + */ + long size(); + + /** + * @return true if persistent indexes are used by default + */ + public boolean isPersistentIndex(); + + /** + * Set a persistent index as the default if the parameter is true + * @param persistentIndex + */ + public void setPersistentIndex(boolean persistentIndex); + + /** + * @return the default container name + */ + public String getDefaultContainerName(); + + /** + * set the default container name + * @param defaultContainerName + */ + public void setDefaultContainerName(String defaultContainerName); + + + /** + * An explict call to initialize - this will also be called + * implicitly for any other operation on the store. + * @throws IOException + */ + public void initialize() throws IOException; + +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreEntry.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreEntry.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreEntry.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreEntry.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,58 @@ +/** + * 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.kahadb; + +/** + * Entry for Store data + * + * @version $Revision: 1.2 $ + */ +public interface StoreEntry { + + StoreLocation getKeyDataItem(); + + StoreLocation getValueDataItem(); + + /** + * @return next item + */ + long getNextItem(); + + /** + * @return Returns the keyFile. + */ + int getKeyFile(); + + /** + * @return Returns the valueFile. + */ + int getValueFile(); + + /** + * @return Returns the valueOffset. + */ + long getValueOffset(); + + /** + * @return Returns the offset. + */ + long getOffset(); + + int getKeySize(); + + int getValueSize(); +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreFactory.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreFactory.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreFactory.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreFactory.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,109 @@ +/** + * 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.kahadb; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.kahadb.impl.KahaStore; + +/** + * Factory for creating stores + * + * @version $Revision: 1.2 $ + */ +public final class StoreFactory { + + private 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 KahaStore(name, mode,new AtomicLong()); + } + + /** + * Open or create a Store + * + * @param directory + * @param mode + * @return + * @throws IOException + */ + public static Store open(File directory, String mode) throws IOException { + return new KahaStore(directory, mode, new AtomicLong()); + } + + /** + * open or create a Store + * @param name + * @param mode + * @param size + * @return the opened/created store + * @throws IOException + */ + public static Store open(String name, String mode, AtomicLong size) throws IOException { + return new KahaStore(name, mode,size); + } + + + /** + * Open or create a Store + * + * @param directory + * @param mode + * @param size + * @return + * @throws IOException + */ + public static Store open(File directory, String mode, AtomicLong size) throws IOException { + return new KahaStore(directory, mode, size); + } + + + /** + * Delete a database + * + * @param name of the database + * @return true if successful + * @throws IOException + */ + public static boolean delete(String name) throws IOException { + KahaStore store = new KahaStore(name, "rw"); + return store.delete(); + } + + /** + * Delete a database + * + * @param directory + * @return true if successful + * @throws IOException + */ + public static boolean delete(File directory) throws IOException { + KahaStore store = new KahaStore(directory, "rw"); + return store.delete(); + } +} Propchange: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreFactory.java ------------------------------------------------------------------------------ svn:executable = * Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreLocation.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreLocation.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreLocation.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StoreLocation.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,40 @@ +/** + * 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.kahadb; + +/** + * Location of a data in the Store + * + * @version $Revision: 1.2 $ + */ +public interface StoreLocation { + + /** + * @return Returns the size. + */ + int getSize(); + + /** + * @return Returns the offset. + */ + long getOffset(); + + /** + * @return Returns the file. + */ + int getFile(); +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StringMarshaller.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StringMarshaller.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StringMarshaller.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/StringMarshaller.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,50 @@ +/** + * 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.kahadb; + +import java.io.DataInput; +import java.io.DataOutput; +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(String object, DataOutput dataOut) throws IOException { + dataOut.writeUTF(object); + } + + /** + * Read the entry from the RawContainer + * + * @param dataIn + * @return unmarshalled object + * @throws IOException + */ + public String readPayload(DataInput dataIn) throws IOException { + return dataIn.readUTF(); + } +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/DataManager.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/DataManager.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/DataManager.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/DataManager.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,55 @@ +/** + * 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.kahadb.impl; + +import java.io.IOException; + +import org.apache.kahadb.Marshaller; +import org.apache.kahadb.StoreLocation; +import org.apache.kahadb.impl.data.RedoListener; + +public interface DataManager { + + String getName(); + + Object readItem(Marshaller marshaller, StoreLocation item) throws IOException; + + StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException; + + StoreLocation storeRedoItem(Object payload) throws IOException; + + void updateItem(StoreLocation location, Marshaller marshaller, Object payload) throws IOException; + + void recoverRedoItems(RedoListener listener) throws IOException; + + void close() throws IOException; + + void force() throws IOException; + + boolean delete() throws IOException; + + void addInterestInFile(int file) throws IOException; + + void removeInterestInFile(int file) throws IOException; + + void consolidateDataFiles() throws IOException; + + Marshaller getRedoMarshaller(); + + void setRedoMarshaller(Marshaller redoMarshaller); + +} Added: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/IndexRootContainer.java URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/IndexRootContainer.java?rev=677944&view=auto ============================================================================== --- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/IndexRootContainer.java (added) +++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/IndexRootContainer.java Fri Jul 18 08:49:48 2008 @@ -0,0 +1,135 @@ +/** + * 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.kahadb.impl; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.kahadb.ContainerId; +import org.apache.kahadb.Marshaller; +import org.apache.kahadb.Store; +import org.apache.kahadb.StoreEntry; +import org.apache.kahadb.StoreLocation; +import org.apache.kahadb.impl.data.Item; +import org.apache.kahadb.impl.index.IndexItem; +import org.apache.kahadb.impl.index.IndexManager; + +/** + * A container of roots for other Containers + * + * @version $Revision: 1.2 $ + */ + +class IndexRootContainer { + + protected static final Marshaller ROOT_MARSHALLER = Store.OBJECT_MARSHALLER; + private static final Log LOG = LogFactory.getLog(IndexRootContainer.class); + + protected IndexItem root; + protected IndexManager indexManager; + protected DataManager dataManager; + protected Map map = new ConcurrentHashMap(); + protected LinkedList list = new LinkedList(); + + IndexRootContainer(IndexItem root, IndexManager im, DataManager dfm) throws IOException { + this.root = root; + this.indexManager = im; + this.dataManager = dfm; + long nextItem = root.getNextItem(); + while (nextItem != Item.POSITION_NOT_SET) { + StoreEntry item = indexManager.getIndex(nextItem); + StoreLocation data = item.getKeyDataItem(); + Object key = dataManager.readItem(ROOT_MARSHALLER, data); + map.put(key, item); + list.add(item); + nextItem = item.getNextItem(); + dataManager.addInterestInFile(item.getKeyFile()); + } + } + + Set getKeys() { + return map.keySet(); + } + + IndexItem addRoot(IndexManager containerIndexManager, ContainerId key) throws IOException { + if (map.containsKey(key)) { + removeRoot(containerIndexManager, key); + } + + StoreLocation data = dataManager.storeDataItem(ROOT_MARSHALLER, key); + IndexItem newRoot = indexManager.createNewIndex(); + newRoot.setKeyData(data); + IndexItem containerRoot = containerIndexManager.createNewIndex(); + containerIndexManager.storeIndex(containerRoot); + newRoot.setValueOffset(containerRoot.getOffset()); + + IndexItem last = list.isEmpty() ? null : (IndexItem)list.getLast(); + last = last == null ? root : last; + long prev = last.getOffset(); + newRoot.setPreviousItem(prev); + indexManager.storeIndex(newRoot); + last.setNextItem(newRoot.getOffset()); + indexManager.storeIndex(last); + map.put(key, newRoot); + list.add(newRoot); + return containerRoot; + } + + void removeRoot(IndexManager containerIndexManager, ContainerId key) throws IOException { + StoreEntry oldRoot = map.remove(key); + if (oldRoot != null) { + dataManager.removeInterestInFile(oldRoot.getKeyFile()); + // get the container root + IndexItem containerRoot = containerIndexManager.getIndex(oldRoot.getValueOffset()); + if (containerRoot != null) { + containerIndexManager.freeIndex(containerRoot); + } + int index = list.indexOf(oldRoot); + IndexItem prev = index > 0 ? (IndexItem)list.get(index - 1) : root; + prev = prev == null ? root : prev; + IndexItem next = index < (list.size() - 1) ? (IndexItem)list.get(index + 1) : null; + if (next != null) { + prev.setNextItem(next.getOffset()); + next.setPreviousItem(prev.getOffset()); + indexManager.updateIndexes(next); + } else { + prev.setNextItem(Item.POSITION_NOT_SET); + } + indexManager.updateIndexes(prev); + list.remove(oldRoot); + indexManager.freeIndex((IndexItem)oldRoot); + } + } + + IndexItem getRoot(IndexManager containerIndexManager, ContainerId key) throws IOException { + StoreEntry index = map.get(key); + if (index != null) { + return containerIndexManager.getIndex(index.getValueOffset()); + } + return null; + } + + boolean doesRootExist(Object key) { + return map.containsKey(key); + } + +} Propchange: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/impl/IndexRootContainer.java ------------------------------------------------------------------------------ svn:executable = *