Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 420089350 for ; Tue, 24 Jan 2012 16:16:53 +0000 (UTC) Received: (qmail 22331 invoked by uid 500); 24 Jan 2012 16:16:53 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 22251 invoked by uid 500); 24 Jan 2012 16:16:52 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 22235 invoked by uid 99); 24 Jan 2012 16:16:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jan 2012 16:16:52 +0000 X-ASF-Spam-Status: No, hits=-1998.0 required=5.0 tests=ALL_TRUSTED,FB_GET_MEDS 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; Tue, 24 Jan 2012 16:16:47 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 952532388A3F for ; Tue, 24 Jan 2012 16:16:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1235326 [6/28] - in /directory/apacheds/trunk: jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-partition... Date: Tue, 24 Jan 2012 16:15:29 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120124161603.952532388A3F@eris.apache.org> Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/StringComparator.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/StringComparator.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/StringComparator.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/StringComparator.java Tue Jan 24 16:15:05 2012 @@ -46,11 +46,13 @@ package jdbm.helper; + import java.io.Serializable; import java.util.Comparator; import org.apache.directory.server.i18n.I18n; + /** * Comparator for String objects. Delegates to String.compareTo(). * @@ -74,17 +76,19 @@ public final class StringComparator * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2, * and a negative integer if obj1 < obj2 */ - public int compare( String obj1, String obj2 ) - { - if ( obj1 == null ) { + public int compare( String obj1, String obj2 ) + { + if ( obj1 == null ) + { throw new IllegalArgumentException( I18n.err( I18n.ERR_525 ) ); } - if ( obj2 == null ) { + if ( obj2 == null ) + { throw new IllegalArgumentException( I18n.err( I18n.ERR_526 ) ); } return obj1.compareTo( obj2 ); - } + } } Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/Tuple.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/Tuple.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/Tuple.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/Tuple.java Tue Jan 24 16:15:05 2012 @@ -52,7 +52,8 @@ package jdbm.helper; * * @author Alex Boisvert */ -public final class Tuple { +public final class Tuple +{ /** Key */ private K key; @@ -64,7 +65,7 @@ public final class Tuple { /** * Construct an empty Tuple. */ - public Tuple() + public Tuple() { // empty } @@ -76,7 +77,7 @@ public final class Tuple { * @param key The key. * @param value The value. */ - public Tuple( K key, V value ) + public Tuple( K key, V value ) { this.key = key; this.value = value; @@ -86,7 +87,7 @@ public final class Tuple { /** * Get the key. */ - public K getKey() + public K getKey() { return this.key; } @@ -95,7 +96,7 @@ public final class Tuple { /** * Set the key. */ - public void setKey( K key ) + public void setKey( K key ) { this.key = key; } @@ -104,7 +105,7 @@ public final class Tuple { /** * Get the value. */ - public V getValue() + public V getValue() { return value; } @@ -113,12 +114,12 @@ public final class Tuple { /** * Set the value. */ - public void setValue( V value ) + public void setValue( V value ) { this.value = value; } - - + + public String toString() { return "<" + key + "," + value + ">"; Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/TupleBrowser.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/TupleBrowser.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/TupleBrowser.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/TupleBrowser.java Tue Jan 24 16:15:05 2012 @@ -46,15 +46,18 @@ package jdbm.helper; + import java.io.IOException; + /** * Browser to traverse a collection of tuples. The browser allows for * forward and reverse order traversal. * * @author Alex Boisvert */ -public abstract class TupleBrowser { +public abstract class TupleBrowser +{ /** * Get the next tuple. * @@ -73,11 +76,13 @@ public abstract class TupleBrowser * no previous tuple. */ public abstract boolean getPrevious( Tuple tuple ) throws IOException; - - + + /** * Closes the browser and deallocates any resources it might have allocated. * Repeated calls of close are OK. */ - public void close() {} + public void close() + { + } } Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/WrappedRuntimeException.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/WrappedRuntimeException.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/WrappedRuntimeException.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/WrappedRuntimeException.java Tue Jan 24 16:15:05 2012 @@ -46,9 +46,11 @@ package jdbm.helper; + import java.io.PrintStream; import java.io.PrintWriter; + /** * A run-time exception that wraps another exception. The printed stack * trace will be that of the wrapped exception. @@ -59,7 +61,6 @@ public class WrappedRuntimeException extends RuntimeException { - /** * The underlying exception. */ @@ -77,10 +78,12 @@ public class WrappedRuntimeException super( message == null ? "No message available" : message ); if ( except instanceof WrappedRuntimeException && - ( (WrappedRuntimeException) except )._except != null ) + ( ( WrappedRuntimeException ) except )._except != null ) + { + _except = ( ( WrappedRuntimeException ) except )._except; + } + else { - _except = ( (WrappedRuntimeException) except )._except; - } else { _except = except; } } @@ -93,13 +96,16 @@ public class WrappedRuntimeException */ public WrappedRuntimeException( Exception except ) { - super( except == null || except.getLocalizedMessage() == null ? "No message available" : except.getLocalizedMessage() ); + super( except == null || except.getLocalizedMessage() == null ? "No message available" : except + .getLocalizedMessage() ); if ( except instanceof WrappedRuntimeException && - ( (WrappedRuntimeException) except )._except != null ) + ( ( WrappedRuntimeException ) except )._except != null ) + { + _except = ( ( WrappedRuntimeException ) except )._except; + } + else { - _except = ( (WrappedRuntimeException) except )._except; - } else { _except = except; } } @@ -118,9 +124,12 @@ public class WrappedRuntimeException public void printStackTrace() { - if ( _except == null ) { + if ( _except == null ) + { super.printStackTrace(); - } else { + } + else + { _except.printStackTrace(); } } @@ -128,9 +137,12 @@ public class WrappedRuntimeException public void printStackTrace( PrintStream stream ) { - if ( _except == null ) { + if ( _except == null ) + { super.printStackTrace( stream ); - } else { + } + else + { _except.printStackTrace( stream ); } } @@ -138,13 +150,14 @@ public class WrappedRuntimeException public void printStackTrace( PrintWriter writer ) { - if ( _except == null ) { + if ( _except == null ) + { super.printStackTrace( writer ); - } else { + } + else + { _except.printStackTrace( writer ); } } } - - Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HTree.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HTree.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HTree.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HTree.java Tue Jan 24 16:15:05 2012 @@ -46,10 +46,12 @@ package jdbm.htree; + import jdbm.RecordManager; import jdbm.helper.FastIterator; import java.io.IOException; + /** * Persistent hashtable implementation for PageManager. * Implemented as an H*Tree structure. @@ -73,7 +75,8 @@ public class HTree * * @param root Root hash directory. */ - private HTree( HashDirectory root ) { + private HTree( HashDirectory root ) + { _root = root; } @@ -86,10 +89,10 @@ public class HTree public static HTree createInstance( RecordManager recman ) throws IOException { - HashDirectory root; - long recid; + HashDirectory root; + long recid; - root = new HashDirectory( (byte) 0 ); + root = new HashDirectory( ( byte ) 0 ); recid = recman.insert( root ); root.setPersistenceContext( recman, recid ); @@ -109,7 +112,7 @@ public class HTree HTree tree; HashDirectory root; - root = (HashDirectory) recman.fetch( root_recid ); + root = ( HashDirectory ) recman.fetch( root_recid ); root.setPersistenceContext( recman, root_recid ); tree = new HTree( root ); return tree; @@ -122,10 +125,10 @@ public class HTree * @param key key with which the specified value is to be assocated. * @param value value to be associated with the specified key. */ - public synchronized void put(Object key, Object value) + public synchronized void put( Object key, Object value ) throws IOException { - _root.put(key, value); + _root.put( key, value ); } @@ -135,10 +138,10 @@ public class HTree * * @param key key whose associated value is to be returned */ - public synchronized Object get(Object key) + public synchronized Object get( Object key ) throws IOException { - return _root.get(key); + return _root.get( key ); } @@ -148,10 +151,10 @@ public class HTree * * @param key key whose associated value is to be removed */ - public synchronized void remove(Object key) + public synchronized void remove( Object key ) throws IOException { - _root.remove(key); + _root.remove( key ); } @@ -184,4 +187,3 @@ public class HTree } } - Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashBucket.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashBucket.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashBucket.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashBucket.java Tue Jan 24 16:15:05 2012 @@ -46,6 +46,7 @@ package jdbm.htree; + import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; @@ -55,6 +56,7 @@ import java.util.ArrayList; import org.apache.directory.server.i18n.I18n; + /** * A bucket is a placeholder for multiple (key, value) pairs. Buckets * are used to store collisions (same hash value) at all levels of an @@ -89,20 +91,17 @@ final class HashBucket */ public static final int OVERFLOW_SIZE = 8; - /** * Depth of this bucket. */ private int _depth; - /** * Keys in this bucket. Keys are ordered to match their respective * value in _values. */ private ArrayList _keys; - /** * Values in this bucket. Values are ordered to match their respective * key in _keys. @@ -113,7 +112,8 @@ final class HashBucket /** * Public constructor for serialization. */ - public HashBucket() { + public HashBucket() + { // empty } @@ -124,7 +124,8 @@ final class HashBucket */ public HashBucket( int level ) { - if ( level > HashDirectory.MAX_DEPTH+1 ) { + if ( level > HashDirectory.MAX_DEPTH + 1 ) + { throw new IllegalArgumentException( I18n.err( I18n.ERR_534, level ) ); } _depth = level; @@ -156,9 +157,12 @@ final class HashBucket */ public boolean hasRoom() { - if ( isLeaf() ) { - return true; // leaf buckets are never full - } else { + if ( isLeaf() ) + { + return true; // leaf buckets are never full + } + else + { // non-leaf bucket return ( _keys.size() < OVERFLOW_SIZE ); } @@ -174,13 +178,16 @@ final class HashBucket */ public Object addElement( Object key, Object value ) { - int existing = _keys.indexOf(key); - if ( existing != -1 ) { + int existing = _keys.indexOf( key ); + if ( existing != -1 ) + { // replace existing element Object before = _values.get( existing ); _values.set( existing, value ); return before; - } else { + } + else + { // add new (key, value) pair _keys.add( key ); _values.add( value ); @@ -198,13 +205,16 @@ final class HashBucket */ public Object removeElement( Object key ) { - int existing = _keys.indexOf(key); - if ( existing != -1 ) { + int existing = _keys.indexOf( key ); + if ( existing != -1 ) + { Object obj = _values.get( existing ); _keys.remove( existing ); _values.remove( existing ); return obj; - } else { + } + else + { // not found return null; } @@ -217,10 +227,13 @@ final class HashBucket */ public Object getValue( Object key ) { - int existing = _keys.indexOf(key); - if ( existing != -1 ) { + int existing = _keys.indexOf( key ); + if ( existing != -1 ) + { return _values.get( existing ); - } else { + } + else + { // key not found return null; } @@ -265,11 +278,13 @@ final class HashBucket out.writeInt( entries ); // write keys - for (int i=0; inull if there is not association for this key. * * @param key key whose associated value is to be returned */ - Object get(Object key) + Object get( Object key ) throws IOException { int hash = hashCode( key ); - long child_recid = _children[ hash ]; - if ( child_recid == 0 ) { + long child_recid = _children[hash]; + if ( child_recid == 0 ) + { // not bucket/page --> not found return null; - } else { - HashNode node = (HashNode) _recman.fetch( child_recid ); + } + else + { + HashNode node = ( HashNode ) _recman.fetch( child_recid ); // System.out.println("HashDirectory.get() child is : "+node); - if ( node instanceof HashDirectory ) { + if ( node instanceof HashDirectory ) + { // recurse into next directory level - HashDirectory dir = (HashDirectory) node; + HashDirectory dir = ( HashDirectory ) node; dir.setPersistenceContext( _recman, child_recid ); return dir.get( key ); - } else { + } + else + { // node is a bucket - HashBucket bucket = (HashBucket) node; + HashBucket bucket = ( HashBucket ) node; return bucket.getValue( key ); } } @@ -213,49 +222,61 @@ final class HashDirectory * @return object which was previously associated with the given key, * or null if no association existed. */ - Object put(Object key, Object value) - throws IOException { - if (value == null) { - return remove(key); + Object put( Object key, Object value ) + throws IOException + { + if ( value == null ) + { + return remove( key ); } - int hash = hashCode(key); + int hash = hashCode( key ); long child_recid = _children[hash]; - if (child_recid == 0) { + if ( child_recid == 0 ) + { // no bucket/page here yet, let's create a bucket - HashBucket bucket = new HashBucket(_depth+1); + HashBucket bucket = new HashBucket( _depth + 1 ); // insert (key,value) pair in bucket - Object existing = bucket.addElement(key, value); + Object existing = bucket.addElement( key, value ); - long b_recid = _recman.insert(bucket); + long b_recid = _recman.insert( bucket ); _children[hash] = b_recid; - _recman.update(_recid, this); + _recman.update( _recid, this ); // System.out.println("Added: "+bucket); return existing; - } else { - HashNode node = (HashNode) _recman.fetch( child_recid ); + } + else + { + HashNode node = ( HashNode ) _recman.fetch( child_recid ); - if ( node instanceof HashDirectory ) { + if ( node instanceof HashDirectory ) + { // recursive insert in next directory level - HashDirectory dir = (HashDirectory) node; + HashDirectory dir = ( HashDirectory ) node; dir.setPersistenceContext( _recman, child_recid ); return dir.put( key, value ); - } else { + } + else + { // node is a bucket - HashBucket bucket = (HashBucket)node; - if (bucket.hasRoom()) { - Object existing = bucket.addElement(key, value); - _recman.update(child_recid, bucket); + HashBucket bucket = ( HashBucket ) node; + if ( bucket.hasRoom() ) + { + Object existing = bucket.addElement( key, value ); + _recman.update( child_recid, bucket ); // System.out.println("Added: "+bucket); return existing; - } else { + } + else + { // overflow, so create a new directory - if (_depth == MAX_DEPTH) { + if ( _depth == MAX_DEPTH ) + { throw new RuntimeException( I18n.err( I18n.ERR_535, _depth ) ); } - HashDirectory dir = new HashDirectory( (byte) (_depth+1) ); + HashDirectory dir = new HashDirectory( ( byte ) ( _depth + 1 ) ); long dir_recid = _recman.insert( dir ); dir.setPersistenceContext( _recman, dir_recid ); @@ -269,7 +290,8 @@ final class HashDirectory ArrayList keys = bucket.getKeys(); ArrayList values = bucket.getValues(); int entries = keys.size(); - for ( int i=0; inull if no association existed with given key. */ - Object remove(Object key) throws IOException { - int hash = hashCode(key); + Object remove( Object key ) throws IOException + { + int hash = hashCode( key ); long child_recid = _children[hash]; - if (child_recid == 0) { + if ( child_recid == 0 ) + { // not bucket/page --> not found return null; - } else { - HashNode node = (HashNode) _recman.fetch( child_recid ); + } + else + { + HashNode node = ( HashNode ) _recman.fetch( child_recid ); // System.out.println("HashDirectory.remove() child is : "+node); - if (node instanceof HashDirectory) { + if ( node instanceof HashDirectory ) + { // recurse into next directory level - HashDirectory dir = (HashDirectory)node; + HashDirectory dir = ( HashDirectory ) node; dir.setPersistenceContext( _recman, child_recid ); - Object existing = dir.remove(key); - if (existing != null && dir.isEmpty()) { + Object existing = dir.remove( key ); + if ( existing != null && dir.isEmpty() ) + { // delete empty directory - _recman.delete(child_recid); + _recman.delete( child_recid ); _children[hash] = 0; - _recman.update(_recid, this); + _recman.update( _recid, this ); } return existing; - } else { + } + else + { // node is a bucket - HashBucket bucket = (HashBucket)node; - Object existing = bucket.removeElement(key); - if (existing != null) { - if (bucket.getElementCount() >= 1) { - _recman.update(child_recid, bucket); - } else { + HashBucket bucket = ( HashBucket ) node; + Object existing = bucket.removeElement( key ); + if ( existing != null ) + { + if ( bucket.getElementCount() >= 1 ) + { + _recman.update( child_recid, bucket ); + } + else + { // delete bucket, it's empty - _recman.delete(child_recid); + _recman.delete( child_recid ); _children[hash] = 0; - _recman.update(_recid, this); + _recman.update( _recid, this ); } } return existing; @@ -330,15 +364,17 @@ final class HashDirectory } } + /** * Calculates the hashcode of a key, based on the current directory * depth. */ - private int hashCode(Object key) { + private int hashCode( Object key ) + { int hashMask = hashMask(); int hash = key.hashCode(); hash = hash & hashMask; - hash = hash >>> ((MAX_DEPTH - _depth) * BIT_SIZE); + hash = hash >>> ( ( MAX_DEPTH - _depth ) * BIT_SIZE ); hash = hash % MAX_CHILDREN; /* System.out.println("HashDirectory.hashCode() is: 0x" @@ -349,14 +385,16 @@ final class HashDirectory return hash; } + /** * Calculates the hashmask of this directory. The hashmask is the * bit mask applied to a hashcode to retain only bits that are * relevant to this directory level. */ - int hashMask() { - int bits = MAX_CHILDREN-1; - int hashMask = bits << ((MAX_DEPTH - _depth) * BIT_SIZE); + int hashMask() + { + int bits = MAX_CHILDREN - 1; + int hashMask = bits << ( ( MAX_DEPTH - _depth ) * BIT_SIZE ); /* System.out.println("HashDirectory.hashMask() is: 0x" +Integer.toHexString(hashMask)); @@ -364,6 +402,7 @@ final class HashDirectory return hashMask; } + /** * Returns an enumeration of the keys contained in this */ @@ -373,6 +412,7 @@ final class HashDirectory return new HDIterator( true ); } + /** * Returns an enumeration of the values contained in this */ @@ -386,23 +426,24 @@ final class HashDirectory /** * Implement Externalizable interface */ - public void writeExternal(ObjectOutput out) - throws IOException { - out.writeByte(_depth); - out.writeObject(_children); + public void writeExternal( ObjectOutput out ) + throws IOException + { + out.writeByte( _depth ); + out.writeObject( _children ); } /** * Implement Externalizable interface */ - public synchronized void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { + public synchronized void readExternal( ObjectInput in ) + throws IOException, ClassNotFoundException + { _depth = in.readByte(); - _children = (long[])in.readObject(); + _children = ( long[] ) in.readObject(); } - //////////////////////////////////////////////////////////////////////// // INNER CLASS //////////////////////////////////////////////////////////////////////// @@ -464,21 +505,28 @@ final class HashDirectory * Returns the next object. */ public Object next() - { - Object next = null; - if( _iter != null && _iter.hasNext() ) { - next = _iter.next(); - } else { - try { - prepareNext(); - } catch ( IOException except ) { - throw new IterationException( except ); - } - if ( _iter != null && _iter.hasNext() ) { - return next(); - } + { + Object next = null; + if ( _iter != null && _iter.hasNext() ) + { + next = _iter.next(); } - return next; + else + { + try + { + prepareNext(); + } + catch ( IOException except ) + { + throw new IterationException( except ); + } + if ( _iter != null && _iter.hasNext() ) + { + return next(); + } + } + return next; } @@ -489,51 +537,63 @@ final class HashDirectory * Bucket to enumerate. If no following bucket is found, * the next Enumeration is set to null. */ - private void prepareNext() throws IOException { + private void prepareNext() throws IOException + { long child_recid = 0; // find next bucket/directory to enumerate - do { + do + { _child++; - if (_child >= MAX_CHILDREN) { + if ( _child >= MAX_CHILDREN ) + { - if (_dirStack.isEmpty()) { + if ( _dirStack.isEmpty() ) + { // no more directory in the stack, we're finished return; } // try next page - _dir = (HashDirectory) _dirStack.remove( _dirStack.size()-1 ); - _child = ( (Integer) _childStack.remove( _childStack.size()-1 ) ).intValue(); + _dir = ( HashDirectory ) _dirStack.remove( _dirStack.size() - 1 ); + _child = ( ( Integer ) _childStack.remove( _childStack.size() - 1 ) ).intValue(); continue; } child_recid = _dir._children[_child]; - } while (child_recid == 0); + } + while ( child_recid == 0 ); - if (child_recid == 0) { - throw new Error("child_recid cannot be 0"); + if ( child_recid == 0 ) + { + throw new Error( "child_recid cannot be 0" ); } - HashNode node = (HashNode) _recman.fetch( child_recid ); + HashNode node = ( HashNode ) _recman.fetch( child_recid ); // System.out.println("HDEnumeration.get() child is : "+node); - - if ( node instanceof HashDirectory ) { + + if ( node instanceof HashDirectory ) + { // save current position _dirStack.add( _dir ); _childStack.add( Integer.valueOf( _child ) ); - _dir = (HashDirectory)node; + _dir = ( HashDirectory ) node; _child = -1; // recurse into _dir.setPersistenceContext( _recman, child_recid ); prepareNext(); - } else { + } + else + { // node is a bucket - HashBucket bucket = (HashBucket)node; - if ( _iterateKeys ) { + HashBucket bucket = ( HashBucket ) node; + if ( _iterateKeys ) + { _iter = bucket.getKeys().iterator(); - } else { + } + else + { _iter = bucket.getValues().iterator(); } } @@ -541,4 +601,3 @@ final class HashDirectory } } - Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashNode.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashNode.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashNode.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/htree/HashNode.java Tue Jan 24 16:15:05 2012 @@ -1,56 +1 @@ -/** - * JDBM LICENSE v1.00 - * - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "JDBM" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Cees de Groot. For written permission, - * please contact cg@cdegroot.com. - * - * 4. Products derived from this Software may not be called "JDBM" - * nor may "JDBM" appear in their names without prior written - * permission of Cees de Groot. - * - * 5. Due credit should be given to the JDBM Project - * (http://jdbm.sourceforge.net/). - * - * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 2000 (C) Cees de Groot. All Rights Reserved. - * Contributions are Copyright (C) 2000 by their associated contributors. - * - */ - -package jdbm.htree; - -import java.io.Serializable; - -/** * Abstract class for Hashtable directory nodes * * @author Alex Boisvert */ class HashNode implements Serializable { - - // Empty, there's no common functionality. We use this abstract - // class for typing only. - -} +/** * JDBM LICENSE v1.00 * * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "JDBM" must not be used to endorse or promote * products derived from this Software without prior written * permission of Cees de Groot. For written permission, * please contact cg@cdegroot.com. * * 4. Products derived from this Software may not be called "JDBM" * nor may "JDBM" appear in their names without prior written * permission of Cees de Groot. * * 5. Due credit should be given to the JDBM Project * (http://jdbm.sourceforge.net/). * * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2000 (C) Cees de Groot. All Rights Reserved. * Contributions are Copyright (C) 2000 by their associated contributors. * */ package jdbm.htree; import java.io.Serializable; /** * Abstract class for Hashtable directory nodes * * @author Alex Boisvert */ class HashNode implements Serializable { // Empty, there's no common functionality. We use this abstract // class for typing only. } \ No newline at end of file Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java Tue Jan 24 16:15:05 2012 @@ -48,6 +48,7 @@ package jdbm.recman; + import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -64,6 +65,7 @@ import org.apache.directory.server.i18n. import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * This class manages records, which are uninterpreted blobs of data. The * set of operations is simple and straightforward: you communicate with @@ -90,7 +92,7 @@ public final class BaseRecordManager imp { /** A logger for this class */ private static final Logger LOG = LoggerFactory.getLogger( BaseRecordManager.class.getSimpleName() ); - + /** Underlying record recordFile. */ private RecordFile recordFile; @@ -114,8 +116,8 @@ public final class BaseRecordManager imp * directory, stored as a Hashtable. It can be retrieved by using * the NAME_DIRECTORY_ROOT. */ - private Map nameDirectory; - + private Map nameDirectory; + private static enum IOType { READ_IO, @@ -205,7 +207,6 @@ public final class BaseRecordManager imp } } - /** * Map used to synchronize reads and writes on the same logical * recid. @@ -235,7 +236,7 @@ public final class BaseRecordManager imp public TransactionManager getTransactionManager() throws IOException { checkIfClosed(); - + return recordFile.getTxnMgr(); } @@ -255,7 +256,7 @@ public final class BaseRecordManager imp recordFile.disableTransactions(); } - + /** * Closes the record manager. * @@ -285,7 +286,7 @@ public final class BaseRecordManager imp return insert( obj, DefaultSerializer.INSTANCE ); } - + /** * Inserts a new record using a custom serializer. * @@ -296,22 +297,22 @@ public final class BaseRecordManager imp */ public long insert( Object obj, Serializer serializer ) throws IOException { - byte[] data; - long recid; - Location physRowId; - + byte[] data; + long recid; + Location physRowId; + checkIfClosed(); data = serializer.serialize( obj ); physRowId = physMgr.insert( data, 0, data.length ); recid = logMgr.insert( physRowId ).toLong(); - - LOG.debug( "BaseRecordManager.insert() recid {} length {}", recid, data.length ) ; - + + LOG.debug( "BaseRecordManager.insert() recid {} length {}", recid, data.length ); + return recid; } - + /** * Deletes a record. * @@ -322,17 +323,16 @@ public final class BaseRecordManager imp { LockElement element; checkIfClosed(); - - if ( recid <= 0 ) + + if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } - LOG.debug( "BaseRecordManager.delete() recid {}", recid ) ; + LOG.debug( "BaseRecordManager.delete() recid {}", recid ); - element = beginIO( recid, IOType.WRITE_IO ); - + try { Location logRowId = new Location( recid ); @@ -358,7 +358,7 @@ public final class BaseRecordManager imp { update( recid, obj, DefaultSerializer.INSTANCE ); } - + /** * Updates a record using a custom serializer. @@ -371,38 +371,38 @@ public final class BaseRecordManager imp public void update( long recid, Object obj, Serializer serializer ) throws IOException { LockElement element; - + checkIfClosed(); - if ( recid <= 0 ) + if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } element = this.beginIO( recid, IOType.WRITE_IO ); - + try { Location logRecid = new Location( recid ); Location physRecid = logMgr.fetch( logRecid ); byte[] data = serializer.serialize( obj ); - - LOG.debug( "BaseRecordManager.update() recid {} length {}", recid, data.length ) ; - + + LOG.debug( "BaseRecordManager.update() recid {} length {}", recid, data.length ); + Location newRecid = physMgr.update( physRecid, data, 0, data.length ); - - if ( ! newRecid.equals( physRecid ) ) + + if ( !newRecid.equals( physRecid ) ) { logMgr.update( logRecid, newRecid ); } - } - finally - { - endIO( recid, element, IOType.WRITE_IO ); - } + } + finally + { + endIO( recid, element, IOType.WRITE_IO ); + } } - + /** * Fetches a record using standard java object serialization. @@ -416,7 +416,7 @@ public final class BaseRecordManager imp return fetch( recid, DefaultSerializer.INSTANCE ); } - + /** * Fetches a record using a custom serializer. * @@ -429,32 +429,32 @@ public final class BaseRecordManager imp { Object result; LockElement element; - + checkIfClosed(); - - if ( recid <= 0 ) + + if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } - - element = this.beginIO(recid, IOType.READ_IO); - + + element = this.beginIO( recid, IOType.READ_IO ); + try { - byte[] data; - - Location location = logMgr.fetch( new Location( recid ) ) ; + byte[] data; + + Location location = logMgr.fetch( new Location( recid ) ); data = physMgr.fetch( location ); - - LOG.debug( "BaseRecordManager.fetch() recid {} length {}", recid, data.length ) ; - + + LOG.debug( "BaseRecordManager.fetch() recid {} length {}", recid, data.length ); + result = serializer.deserialize( data ); } finally { - endIO(recid, element, IOType.READ_IO); + endIO( recid, element, IOType.READ_IO ); } - + return result; } @@ -470,7 +470,7 @@ public final class BaseRecordManager imp return FileHeader.NROOTS; } - + /** * Returns the indicated root rowid. * @@ -505,17 +505,17 @@ public final class BaseRecordManager imp { checkIfClosed(); - Map nameDirectory = getNameDirectory(); + Map nameDirectory = getNameDirectory(); Long recid = nameDirectory.get( name ); - if ( recid == null ) + if ( recid == null ) { return 0; } - + return recid; } - + /** * Set the record id of a named object. @@ -524,17 +524,17 @@ public final class BaseRecordManager imp { checkIfClosed(); - if ( recid == 0 ) + if ( recid == 0 ) { // remove from hashtable getNameDirectory().remove( name ); - } - else + } + else { getNameDirectory().put( name, recid ); } - - saveNameDirectory( ); + + saveNameDirectory(); } @@ -564,35 +564,35 @@ public final class BaseRecordManager imp * Load name directory */ @SuppressWarnings("unchecked") - private Map getNameDirectory() throws IOException + private Map getNameDirectory() throws IOException { // retrieve directory of named hashtable long nameDirectory_recid = getRoot( NAME_DIRECTORY_ROOT ); - - if ( nameDirectory_recid == 0 ) + + if ( nameDirectory_recid == 0 ) { nameDirectory = new HashMap(); nameDirectory_recid = insert( nameDirectory ); setRoot( NAME_DIRECTORY_ROOT, nameDirectory_recid ); - } - else + } + else { nameDirectory = ( Map ) fetch( nameDirectory_recid ); } - + return nameDirectory; } - private void saveNameDirectory( ) throws IOException + private void saveNameDirectory() throws IOException { long recid = getRoot( NAME_DIRECTORY_ROOT ); - - if ( recid == 0 ) + + if ( recid == 0 ) { throw new IOException( I18n.err( I18n.ERR_537 ) ); } - + update( recid, nameDirectory ); } @@ -602,12 +602,12 @@ public final class BaseRecordManager imp */ private void checkIfClosed() throws IllegalStateException { - if ( recordFile == null ) + if ( recordFile == null ) { throw new IllegalStateException( I18n.err( I18n.ERR_538 ) ); } } - + /** * Used to serialize reads/write on a given logical rowid. Checks if there is a @@ -624,96 +624,96 @@ public final class BaseRecordManager imp LockElement element = null; // loop until we successfully verify that there is no concurrent writer -/* - element = lockElements.get( recid ); - - do - { - if ( element == null ) - { - element = new LockElement(); - - if ( io == IOType.READ_IO ) - { - element.bumpReaders(); - } - else - { - element.setWritten(); - } - - LockElement existingElement = lockElements.putIfAbsent( recid, element ); - - if ( existingElement == null ) - { - lockVerified = true; - } - else - { - element = existingElement; - } - } - else - { - Lock lock = element.getLock(); - lock.lock(); + /* + element = lockElements.get( recid ); - if ( element.anyUser() ) + do { - if ( this.conflictingIOPredicate( io, element ) ) + if ( element == null ) { - element.bumpWaiters(); - - do + element = new LockElement(); + + if ( io == IOType.READ_IO ) { - element.getNoConflictingIOCondition() - .awaitUninterruptibly(); + element.bumpReaders(); + } + else + { + element.setWritten(); } - while ( this.conflictingIOPredicate( io, element ) ); - - element.decrementWaiters(); - } - - // no conflicting IO anymore..done - if ( io == IOType.READ_IO ) - { - element.bumpReaders(); - } - else - { - element.setWritten(); - } - - lockVerified = true; - } - else - { - if ( io == IOType.READ_IO ) - { - element.bumpReaders(); - } - else - { - element.setWritten(); - } - LockElement existingElement = lockElements.get( recid ); + LockElement existingElement = lockElements.putIfAbsent( recid, element ); - if ( element != existingElement ) - { - element = existingElement; + if ( existingElement == null ) + { + lockVerified = true; + } + else + { + element = existingElement; + } } else { - lockVerified = true; // done + Lock lock = element.getLock(); + lock.lock(); + + if ( element.anyUser() ) + { + if ( this.conflictingIOPredicate( io, element ) ) + { + element.bumpWaiters(); + + do + { + element.getNoConflictingIOCondition() + .awaitUninterruptibly(); + } + while ( this.conflictingIOPredicate( io, element ) ); + + element.decrementWaiters(); + } + + // no conflicting IO anymore..done + if ( io == IOType.READ_IO ) + { + element.bumpReaders(); + } + else + { + element.setWritten(); + } + + lockVerified = true; + } + else + { + if ( io == IOType.READ_IO ) + { + element.bumpReaders(); + } + else + { + element.setWritten(); + } + + LockElement existingElement = lockElements.get( recid ); + + if ( element != existingElement ) + { + element = existingElement; + } + else + { + lockVerified = true; // done + } + } + + lock.unlock(); } } - - lock.unlock(); - } - } - while ( !lockVerified ); -*/ + while ( !lockVerified ); + */ return element; } @@ -758,7 +758,7 @@ public final class BaseRecordManager imp private boolean conflictingIOPredicate( IOType io, LockElement element ) { if ( io == IOType.READ_IO ) - { + { return element.beingWritten(); } else Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java Tue Jan 24 16:15:05 2012 @@ -52,7 +52,6 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.directory.server.i18n.I18n; @@ -67,7 +66,7 @@ import org.apache.directory.server.i18n. * @see java.io.DataInput * @see java.io.DataOutput */ -public final class BlockIo implements java.io.Externalizable +public final class BlockIo implements java.io.Externalizable { public final static long serialVersionUID = 2L; @@ -76,136 +75,136 @@ public final class BlockIo implements ja /** The row data contained in this block */ private byte[] data; - + /** A view on the BlockIo */ private BlockView view = null; - + /** A flag set when this block has been modified */ private boolean dirty = false; - + /** The number of pending transaction on this block */ private AtomicInteger transactionCount = new AtomicInteger( 0 ); - + /** * Default constructor for serialization */ - public BlockIo() + public BlockIo() { // empty } - + /** * Constructs a new BlockIo instance. * * @param blockId The identifier for this block * @param data The data to store */ - /*No qualifier*/ BlockIo( long blockId, byte[] data ) + /*No qualifier*/BlockIo( long blockId, byte[] data ) { // remove me for production version if ( blockId < 0 ) { throw new Error( I18n.err( I18n.ERR_539_BAD_BLOCK_ID, blockId ) ); } - + this.blockId = blockId; this.data = data; } - + /** * @return the underlying array */ - /*No qualifier*/ byte[] getData() + /*No qualifier*/byte[] getData() { return data; } - + /** * Sets the block number. Should only be called by RecordFile. * * @param The block identifier */ - /*No qualifier*/ void setBlockId( long blockId ) + /*No qualifier*/void setBlockId( long blockId ) { if ( isInTransaction() ) { throw new Error( I18n.err( I18n.ERR_540 ) ); } - + if ( blockId < 0 ) { throw new Error( I18n.err( I18n.ERR_539_BAD_BLOCK_ID, blockId ) ); } - + this.blockId = blockId; } - + /** * @return the block number. */ - /*No qualifier*/ long getBlockId() + /*No qualifier*/long getBlockId() { return blockId; } - + /** * @return the current view of the block. */ - public BlockView getView() + public BlockView getView() { return view; } - + /** * Sets the current view of the block. * * @param view the current view */ - public void setView( BlockView view ) + public void setView( BlockView view ) { this.view = view; } - + /** * Sets the dirty flag */ - /*No qualifier*/ void setDirty() + /*No qualifier*/void setDirty() { dirty = true; } - + /** * Clears the dirty flag */ - /*No qualifier*/ void setClean() + /*No qualifier*/void setClean() { dirty = false; } - + /** * Returns true if the dirty flag is set. */ - /*No qualifier*/ boolean isDirty() + /*No qualifier*/boolean isDirty() { return dirty; } - + /** * Returns true if the block is still dirty with respect to the * transaction log. */ - /*No qualifier*/ boolean isInTransaction() + /*No qualifier*/boolean isInTransaction() { return transactionCount.get() != 0; } @@ -216,24 +215,24 @@ public final class BlockIo implements ja * block is in the log but not yet in the data recordFile. The method also * takes a snapshot so that the data may be modified in new transactions. */ - /*No qualifier*/ void incrementTransactionCount() + /*No qualifier*/void incrementTransactionCount() { transactionCount.getAndIncrement(); } - + /** * Decrements transaction count for this block, to signal that this * block has been written from the log to the data recordFile. */ - /*No qualifier*/ void decrementTransactionCount() + /*No qualifier*/void decrementTransactionCount() { if ( transactionCount.decrementAndGet() < 0 ) { throw new Error( I18n.err( I18n.ERR_541, getBlockId() ) ); } } - + /** * Reads a byte from the indicated position @@ -241,11 +240,11 @@ public final class BlockIo implements ja * @param pos the position at which we will read the byte * @return the read byte */ - public byte readByte( int pos ) + public byte readByte( int pos ) { return data[pos]; } - + /** * Writes a byte to the indicated position @@ -253,73 +252,70 @@ public final class BlockIo implements ja * @param pos The position where we want to write the value to * @param value the byte value we want to write into the BlockIo */ - public void writeByte( int pos, byte value ) + public void writeByte( int pos, byte value ) { data[pos] = value; dirty = true; } - + /** * Reads a short from the indicated position * * @param pos the position at which we will read the short * @return the read short */ - public short readShort( int pos ) + public short readShort( int pos ) { - return ( short ) - ( ( ( data[pos+0] & 0xff ) << 8 ) | - ( ( data[pos+1] & 0xff ) << 0 ) ); + return ( short ) ( ( ( data[pos + 0] & 0xff ) << 8 ) | ( ( data[pos + 1] & 0xff ) << 0 ) ); } - + /** * Writes a short to the indicated position * * @param pos The position where we want to write the value to * @param value the short value we want to write into the BlockIo */ - public void writeShort( int pos, short value ) + public void writeShort( int pos, short value ) { - data[pos+0] = ( byte ) ( 0xff & ( value >> 8 ) ); - data[pos+1] = ( byte ) ( 0xff & ( value >> 0 ) ); + data[pos + 0] = ( byte ) ( 0xff & ( value >> 8 ) ); + data[pos + 1] = ( byte ) ( 0xff & ( value >> 0 ) ); dirty = true; } - + /** * Reads an int from the indicated position * * @param pos the position at which we will read the int * @return the read int */ - public int readInt( int pos ) + public int readInt( int pos ) { - return - ( data[pos+0] << 24) | - ( ( data[pos+1] & 0xff ) << 16) | - ( ( data[pos+2] & 0xff ) << 8) | - ( ( data[pos+3] & 0xff ) << 0 ); + return ( data[pos + 0] << 24 ) | + ( ( data[pos + 1] & 0xff ) << 16 ) | + ( ( data[pos + 2] & 0xff ) << 8 ) | + ( ( data[pos + 3] & 0xff ) << 0 ); } - + /** * Writes an int to the indicated position * * @param pos The position where we want to write the value to * @param value the int value we want to write into the BlockIo */ - public void writeInt( int pos, int value ) + public void writeInt( int pos, int value ) { - data[pos+0] = ( byte ) ( 0xff & ( value >> 24 ) ); - data[pos+1] = ( byte ) ( 0xff & ( value >> 16 ) ); - data[pos+2] = ( byte ) ( 0xff & ( value >> 8 ) ); - data[pos+3] = ( byte ) ( 0xff & ( value >> 0 ) ); + data[pos + 0] = ( byte ) ( 0xff & ( value >> 24 ) ); + data[pos + 1] = ( byte ) ( 0xff & ( value >> 16 ) ); + data[pos + 2] = ( byte ) ( 0xff & ( value >> 8 ) ); + data[pos + 3] = ( byte ) ( 0xff & ( value >> 0 ) ); dirty = true; } - + /** * Reads a long from the indicated position * @@ -328,54 +324,53 @@ public final class BlockIo implements ja */ public long readLong( int pos ) { - return - ( ( long )( (long)data[pos+0] << 56 ) | - ( (long)( data[pos+1] & 0xff ) << 48 ) | - ( (long)( data[pos+2] & 0xff ) << 40 ) | - ( (long)( data[pos+3] & 0xff ) << 32 ) | - ( (long)( data[pos+4] & 0xff ) << 24 ) | - ( (long)( data[pos+5] & 0xff ) << 16 ) | - ( (long)( data[pos+6] & 0xff ) << 8 ) | - ( (long)( data[pos+7] & 0xff ) ) ); + return ( ( long ) ( ( long ) data[pos + 0] << 56 ) | + ( ( long ) ( data[pos + 1] & 0xff ) << 48 ) | + ( ( long ) ( data[pos + 2] & 0xff ) << 40 ) | + ( ( long ) ( data[pos + 3] & 0xff ) << 32 ) | + ( ( long ) ( data[pos + 4] & 0xff ) << 24 ) | + ( ( long ) ( data[pos + 5] & 0xff ) << 16 ) | + ( ( long ) ( data[pos + 6] & 0xff ) << 8 ) | ( ( long ) ( data[pos + 7] & 0xff ) ) ); } - + /** * Writes a long to the indicated position * * @param pos The position where we want to write the value to * @param value the long value we want to write into the BlockIo */ - public void writeLong(int pos, long value) { - data[pos+0] = (byte)(0xff & (value >> 56)); - data[pos+1] = (byte)(0xff & (value >> 48)); - data[pos+2] = (byte)(0xff & (value >> 40)); - data[pos+3] = (byte)(0xff & (value >> 32)); - data[pos+4] = (byte)(0xff & (value >> 24)); - data[pos+5] = (byte)(0xff & (value >> 16)); - data[pos+6] = (byte)(0xff & (value >> 8)); - data[pos+7] = (byte)(0xff & (value >> 0)); + public void writeLong( int pos, long value ) + { + data[pos + 0] = ( byte ) ( 0xff & ( value >> 56 ) ); + data[pos + 1] = ( byte ) ( 0xff & ( value >> 48 ) ); + data[pos + 2] = ( byte ) ( 0xff & ( value >> 40 ) ); + data[pos + 3] = ( byte ) ( 0xff & ( value >> 32 ) ); + data[pos + 4] = ( byte ) ( 0xff & ( value >> 24 ) ); + data[pos + 5] = ( byte ) ( 0xff & ( value >> 16 ) ); + data[pos + 6] = ( byte ) ( 0xff & ( value >> 8 ) ); + data[pos + 7] = ( byte ) ( 0xff & ( value >> 0 ) ); dirty = true; } - + /** * {@inheritDoc} */ - public String toString() + public String toString() { if ( view != null ) { return view.toString(); } - + StringBuilder sb = new StringBuilder(); - + sb.append( "BlockIO ( " ); - + // The blockID sb.append( blockId ).append( ", " ); - + // Is it dirty ? if ( dirty ) { @@ -385,7 +380,7 @@ public final class BlockIo implements ja { sb.append( "clean, " ); } - + // The view if ( view != null ) { @@ -395,32 +390,32 @@ public final class BlockIo implements ja { sb.append( "no view, " ); } - + // The transaction count sb.append( "tx: " ).append( transactionCount.get() ); sb.append( " )" ); - + return sb.toString(); } - + /** * implement externalizable interface */ - public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException + public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { blockId = in.readLong(); int length = in.readInt(); data = new byte[length]; - in.readFully(data); + in.readFully( data ); } - + /** * implement externalizable interface */ - public void writeExternal( ObjectOutput out ) throws IOException + public void writeExternal( ObjectOutput out ) throws IOException { out.writeLong( blockId ); out.writeInt( data.length ); Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java Tue Jan 24 16:15:05 2012 @@ -47,7 +47,6 @@ package jdbm.recman; - /** * This is a marker interface that is implemented by classes that * interpret blocks of data by pretending to be an overlay. Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java Tue Jan 24 16:15:05 2012 @@ -84,14 +84,14 @@ public class CacheRecordManager implemen * @param recordManager Wrapped RecordManager * @param cache Cache policy */ - public CacheRecordManager( RecordManager recordManager, CachePolicy cache ) + public CacheRecordManager( RecordManager recordManager, CachePolicy cache ) { - if ( recordManager == null ) + if ( recordManager == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_517 ) ); } - - if ( cache == null ) + + if ( cache == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_542 ) ); } @@ -101,7 +101,7 @@ public class CacheRecordManager implemen this.cache.addListener( new CacheListener() ); } - + /** * Get the underlying Record Manager. * @@ -113,19 +113,19 @@ public class CacheRecordManager implemen return recordManager; } - + /** * Get the underlying cache policy * * @return underlying CachePolicy or null if CacheRecordManager has * been closed. */ - public CachePolicy getCachePolicy() + public CachePolicy getCachePolicy() { return cache; } - + /** * Inserts a new record using a custom serializer. * @@ -137,8 +137,8 @@ public class CacheRecordManager implemen { return insert( obj, DefaultSerializer.INSTANCE ); } - - + + /** * Inserts a new record using a custom serializer. * @@ -152,16 +152,16 @@ public class CacheRecordManager implemen checkIfClosed(); long recid = recordManager.insert( obj, serializer ); - - try + + try { cache.put( recid, new CacheEntry( recid, obj, serializer, false ) ); - } - catch ( CacheEvictionException except ) + } + catch ( CacheEvictionException except ) { throw new WrappedRuntimeException( except ); } - + return recid; } @@ -178,7 +178,7 @@ public class CacheRecordManager implemen // Remove the entry from the underlying storage recordManager.delete( recid ); - + // And now update the cache cache.remove( recid ); } @@ -195,7 +195,7 @@ public class CacheRecordManager implemen { update( recid, obj, DefaultSerializer.INSTANCE ); } - + /** * Updates a record using a custom serializer. @@ -209,22 +209,23 @@ public class CacheRecordManager implemen { checkIfClosed(); - try { + try + { CacheEntry entry = cache.get( recid ); - - if ( entry != null ) + + if ( entry != null ) { // reuse existing cache entry entry.obj = obj; entry.serializer = serializer; entry.isDirty = true; - } - else + } + else { cache.put( recid, new CacheEntry( recid, obj, serializer, true ) ); } - } - catch ( CacheEvictionException except ) + } + catch ( CacheEvictionException except ) { throw new IOException( except.getLocalizedMessage() ); } @@ -243,7 +244,7 @@ public class CacheRecordManager implemen return fetch( recid, DefaultSerializer.INSTANCE ); } - + /** * Fetches a record using a custom serializer. * @@ -257,29 +258,29 @@ public class CacheRecordManager implemen checkIfClosed(); CacheEntry entry = cache.get( recid ); - - if ( entry == null ) + + if ( entry == null ) { entry = new CacheEntry( recid, null, serializer, false ); entry.obj = recordManager.fetch( recid, serializer ); - - try + + try { cache.put( recid, entry ); - } - catch ( CacheEvictionException except ) + } + catch ( CacheEvictionException except ) { throw new WrappedRuntimeException( except ); } } - + if ( entry.obj instanceof byte[] ) { - byte[] copy = new byte[ ( ( byte[] ) entry.obj ).length ]; + byte[] copy = new byte[( ( byte[] ) entry.obj ).length]; System.arraycopy( entry.obj, 0, copy, 0, ( ( byte[] ) entry.obj ).length ); return copy; } - + return entry.obj; } @@ -394,25 +395,25 @@ public class CacheRecordManager implemen */ private void checkIfClosed() throws IllegalStateException { - if ( recordManager == null ) + if ( recordManager == null ) { throw new IllegalStateException( I18n.err( I18n.ERR_538 ) ); } } - + /** * Update all dirty cache objects to the underlying RecordManager. */ protected void updateCacheEntries() throws IOException { Enumeration enume = cache.elements(); - - while ( enume.hasMoreElements() ) + + while ( enume.hasMoreElements() ) { CacheEntry entry = enume.nextElement(); - - if ( entry.isDirty ) + + if ( entry.isDirty ) { recordManager.update( entry.recid, entry.obj, entry.serializer ); entry.isDirty = false; @@ -429,7 +430,8 @@ public class CacheRecordManager implemen Object obj; Serializer serializer; boolean isDirty; - + + CacheEntry( long recid, Object obj, Serializer serializer, boolean isDirty ) { this.recid = recid; @@ -437,13 +439,12 @@ public class CacheRecordManager implemen this.serializer = serializer; this.isDirty = isDirty; } - + } // class CacheEntry - private class CacheListener implements CachePolicyListener { - + /** * Notification that cache is evicting an object * @@ -452,13 +453,13 @@ public class CacheRecordManager implemen public void cacheObjectEvicted( CacheEntry obj ) throws CacheEvictionException { CacheEntry entry = obj; - if ( entry.isDirty ) + if ( entry.isDirty ) { - try + try { recordManager.update( entry.recid, entry.obj, entry.serializer ); - } - catch ( IOException except ) + } + catch ( IOException except ) { throw new CacheEvictionException( except ); } Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java Tue Jan 24 16:15:05 2012 @@ -47,99 +47,98 @@ package jdbm.recman; - import org.apache.directory.server.i18n.I18n; /** * Class describing a page that holds data. */ -final class DataPage extends PageHeader +final class DataPage extends PageHeader { // offsets /** first short in the file after the page header info: 18 byte offset */ private static final short O_FIRST = PageHeader.SIZE; // short firstrowid - + /** start of the data in this block: 20 byte offset */ static final short O_DATA = ( short ) ( O_FIRST + Magic.SZ_SHORT ); - + /** total amount of data in this page/block: BLOCK_SIZE - 20 bytes */ static final short DATA_PER_PAGE = ( short ) ( RecordFile.BLOCK_SIZE - O_DATA ); - + /** * Constructs a data page view from the indicated block. */ - DataPage( BlockIo block ) + DataPage( BlockIo block ) { super( block ); } - + /** * Factory method to create or return a data page for the indicated block. */ - static DataPage getDataPageView( BlockIo blockIo ) + static DataPage getDataPageView( BlockIo blockIo ) { BlockView view = blockIo.getView(); - + if ( ( view != null ) && ( view instanceof DataPage ) ) { return ( DataPage ) view; } else - { + { return new DataPage( blockIo ); } } - + /** * @return the first rowid's offset */ - short getFirst() + short getFirst() { return blockIo.readShort( O_FIRST ); } - - + + /** * Sets the first rowid's offset */ - void setFirst( short value ) + void setFirst( short value ) { paranoiaMagicOk(); - + if ( value > 0 && value < O_DATA ) { throw new Error( I18n.err( I18n.ERR_543, value ) ); } - + blockIo.writeShort( O_FIRST, value ); } - - + + /** * {@inheritDoc} */ - public String toString() + public String toString() { StringBuilder sb = new StringBuilder(); - + sb.append( "DataPage ( " ); - + // The blockIO sb.append( super.toString() ).append( ", " ); - + // The first rowId sb.append( "first rowId: " ).append( getFirst() ).append( ", " ); - + // The data per page sb.append( "[p:" ).append( getPrev() ).append( ", " ); - + // The next page sb.append( "n:" ).append( getNext() ).append( "] )" ); - + return sb.toString(); } } Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java?rev=1235326&r1=1235325&r2=1235326&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java (original) +++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java Tue Jan 24 16:15:05 2012 @@ -73,14 +73,14 @@ import org.apache.directory.server.i18n. * We may have more than one, but no more than 1014, if the BLOCK_SIZE is 8192 * */ -class FileHeader implements BlockView +class FileHeader implements BlockView { /** Position of the Magic number for FileHeader */ private static final short O_MAGIC = 0; // short magic - + /** Position of the Lists in the blockIo */ private static final short O_LISTS = Magic.SZ_SHORT; // long[2*NLISTS] - + /** Position of the ROOTs in the blockIo */ private static final int O_ROOTS = O_LISTS + ( Magic.NLISTS * 2 * Magic.SZ_LONG ); @@ -90,7 +90,7 @@ class FileHeader implements BlockView /** The number of "root" rowids available in the file. */ static final int NROOTS = ( RecordFile.BLOCK_SIZE - O_ROOTS ) / Magic.SZ_LONG; - + /** * Constructs a FileHeader object from a block. * @@ -99,10 +99,10 @@ class FileHeader implements BlockView * @throws IOException if the block is too short to keep the file * header. */ - FileHeader( BlockIo block, boolean isNew ) + FileHeader( BlockIo block, boolean isNew ) { this.block = block; - + if ( isNew ) { block.writeShort( O_MAGIC, Magic.FILE_HEADER ); @@ -117,65 +117,65 @@ class FileHeader implements BlockView /** * Returns the offset of the "first" block of the indicated list */ - private short offsetOfFirst( int list ) + private short offsetOfFirst( int list ) { return ( short ) ( O_LISTS + ( 2 * Magic.SZ_LONG * list ) ); } - + /** * Returns the offset of the "last" block of the indicated list */ - private short offsetOfLast( int list ) + private short offsetOfLast( int list ) { return ( short ) ( offsetOfFirst( list ) + Magic.SZ_LONG ); } - + /** * Returns the offset of the indicated root */ - private short offsetOfRoot( int root ) + private short offsetOfRoot( int root ) { return ( short ) ( O_ROOTS + ( root * Magic.SZ_LONG ) ); } - + /** * Returns the first block of the indicated list */ - long getFirstOf( int list ) + long getFirstOf( int list ) { return block.readLong( offsetOfFirst( list ) ); } - - + + /** * Sets the first block of the indicated list */ - void setFirstOf( int list, long value ) + void setFirstOf( int list, long value ) { block.writeLong( offsetOfFirst( list ), value ); } - - + + /** * Returns the last block of the indicated list */ - long getLastOf( int list ) + long getLastOf( int list ) { return block.readLong( offsetOfLast( list ) ); } - - + + /** * Sets the last block of the indicated list */ - void setLastOf( int list, long value ) + void setLastOf( int list, long value ) { block.writeLong( offsetOfLast( list ), value ); } - + /** * Returns the indicated root rowid. A root rowid is a special rowid @@ -186,19 +186,19 @@ class FileHeader implements BlockView * * @see #NROOTS */ - long getRoot( int root ) + long getRoot( int root ) { return block.readLong( offsetOfRoot( root ) ); } - + /** * Sets the indicated root rowid. * * @see #getRoot * @see #NROOTS */ - void setRoot( int root, long rowid ) + void setRoot( int root, long rowid ) { block.writeLong( offsetOfRoot( root ), rowid ); } @@ -207,52 +207,52 @@ class FileHeader implements BlockView /** * {@inheritDoc} */ - public String toString() + public String toString() { StringBuilder sb = new StringBuilder(); - + sb.append( "FileHeader ( " ); - + // The blockIO sb.append( block ).append( ", " ); - + // The free pages sb.append( "free[" ); sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREE_PAGE ) ) ) ); sb.append( ", " ); - sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREE_PAGE ) + Magic.SZ_LONG ) ) ); + sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREE_PAGE ) + Magic.SZ_LONG ) ) ); sb.append( "], " ); // The used pages sb.append( "used[" ); sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.USED_PAGE ) ) ) ); sb.append( ", " ); - sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.USED_PAGE ) + Magic.SZ_LONG ) ) ); + sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.USED_PAGE ) + Magic.SZ_LONG ) ) ); sb.append( "], " ); - + // The translation pages sb.append( "translation[" ); sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.TRANSLATION_PAGE ) ) ) ); sb.append( ", " ); - sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.TRANSLATION_PAGE ) + Magic.SZ_LONG ) ) ); + sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.TRANSLATION_PAGE ) + Magic.SZ_LONG ) ) ); sb.append( "], " ); // The freeLogIds pages sb.append( "freeLogIds[" ); sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREELOGIDS_PAGE ) ) ) ); sb.append( ", " ); - sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREELOGIDS_PAGE ) + Magic.SZ_LONG ) ) ); + sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREELOGIDS_PAGE ) + Magic.SZ_LONG ) ) ); sb.append( "], " ); // The freePhysIds pages sb.append( "freePhysIds[" ); sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREEPHYSIDS_PAGE ) ) ) ); sb.append( ", " ); - sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREEPHYSIDS_PAGE ) + Magic.SZ_LONG ) ) ); + sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREEPHYSIDS_PAGE ) + Magic.SZ_LONG ) ) ); sb.append( "]" ); sb.append( " )" ); - + return sb.toString(); } }