You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by zs...@apache.org on 2010/01/21 11:38:15 UTC
svn commit: r901644 [31/37] - in /hadoop/hive/trunk: ./
ql/src/java/org/apache/hadoop/hive/ql/
ql/src/java/org/apache/hadoop/hive/ql/exec/
ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/
ql/src/java/org/apache/hadoop/hive/ql/history/ ql/src/jav...
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/DefaultSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/DefaultSerializer.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/DefaultSerializer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/DefaultSerializer.java Thu Jan 21 10:37:58 2010
@@ -68,54 +68,45 @@
/**
* Default java serializer.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: DefaultSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
-public class DefaultSerializer
- implements Serializer
-{
-
-
- public static final DefaultSerializer INSTANCE = new DefaultSerializer();
-
-
- /**
- * Construct a DefaultSerializer.
- */
- public DefaultSerializer()
- {
- // no op
- }
+public class DefaultSerializer implements Serializer {
+
+ public static final DefaultSerializer INSTANCE = new DefaultSerializer();
+
+ /**
+ * Construct a DefaultSerializer.
+ */
+ public DefaultSerializer() {
+ // no op
+ }
-
- /**
- * Serialize the content of an object into a byte array.
- *
- * @param obj Object to serialize
- * @return a byte array representing the object's state
- */
- public byte[] serialize( Object obj )
- throws IOException
- {
- return Serialization.serialize( obj );
- }
-
-
- /**
- * Deserialize the content of an object from a byte array.
- *
- * @param serialized Byte array representation of the object
- * @return deserialized object
- */
- public Object deserialize( byte[] serialized )
- throws IOException
- {
- try {
- return Serialization.deserialize( serialized );
- } catch ( ClassNotFoundException except ) {
- throw new WrappedRuntimeException( except );
- }
- }
+ /**
+ * Serialize the content of an object into a byte array.
+ *
+ * @param obj
+ * Object to serialize
+ * @return a byte array representing the object's state
+ */
+ public byte[] serialize(Object obj) throws IOException {
+ return Serialization.serialize(obj);
+ }
+
+ /**
+ * Deserialize the content of an object from a byte array.
+ *
+ * @param serialized
+ * Byte array representation of the object
+ * @return deserialized object
+ */
+ public Object deserialize(byte[] serialized) throws IOException {
+ try {
+ return Serialization.deserialize(serialized);
+ } catch (ClassNotFoundException except) {
+ throw new WrappedRuntimeException(except);
+ }
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/FastIterator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/FastIterator.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/FastIterator.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/FastIterator.java Thu Jan 21 10:37:58 2010
@@ -65,22 +65,19 @@
package org.apache.hadoop.hive.ql.util.jdbm.helper;
-
/**
* Fast and simple iterator.
- *
+ *
* @version $Revision: 1.2 $
* @author <a href="boisvert@intalio.com">Alex Boisvert</a>
*/
-public abstract class FastIterator
-{
+public abstract class FastIterator {
- /**
- * Returns the next element in the interation.
- *
- * @return the next element in the iteration, or null if no more element.
- */
- public abstract Object next()
- throws IterationException;
+ /**
+ * Returns the next element in the interation.
+ *
+ * @return the next element in the iteration, or null if no more element.
+ */
+ public abstract Object next() throws IterationException;
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerComparator.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerComparator.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerComparator.java Thu Jan 21 10:37:58 2010
@@ -69,55 +69,53 @@
/**
* Comparator for Integer objects.
- *
+ *
* @author <a href="mailto:cdaller@iicm.edu">Christof Dallermassl</a>
* @version $Id: IntegerComparator.java,v 1.2 2002/05/31 06:33:20 boisvert Exp $
*/
-public final class IntegerComparator
- implements Comparator, Serializable
-{
-
- /**
- * Version id for serialization.
- */
- final static long serialVersionUID = 1L;
-
-
- /**
- * Compare two objects.
- *
- * @param obj1 First object
- * @param obj2 Second object
- * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
- * and a negative integer if obj1 < obj2
- */
- public int compare( Object obj1, Object obj2 )
- {
- if ( obj1 == obj2 ) {
- return 0;
- }
-
- if ( obj1 == null ) {
- throw new IllegalArgumentException( "Argument 'obj1' is null" );
- }
-
- if ( obj2 == null ) {
- throw new IllegalArgumentException( "Argument 'obj2' is null" );
- }
-
- // complicated to avoid usage of Integer.compareTo, as this
- // method is Java 1.2 only!
- int int1 = ( (Integer) obj1 ).intValue();
- int int2 = ( (Integer) obj2 ).intValue();
- if ( int1 == int2 ) {
- return 0;
- }
-
- if ( int1 < int2 ) {
- return -1;
- } else {
- return 1;
- }
+public final class IntegerComparator implements Comparator, Serializable {
+
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+ /**
+ * Compare two objects.
+ *
+ * @param obj1
+ * First object
+ * @param obj2
+ * Second object
+ * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2, and a
+ * negative integer if obj1 < obj2
+ */
+ public int compare(Object obj1, Object obj2) {
+ if (obj1 == obj2) {
+ return 0;
+ }
+
+ if (obj1 == null) {
+ throw new IllegalArgumentException("Argument 'obj1' is null");
+ }
+
+ if (obj2 == null) {
+ throw new IllegalArgumentException("Argument 'obj2' is null");
+ }
+
+ // complicated to avoid usage of Integer.compareTo, as this
+ // method is Java 1.2 only!
+ int int1 = ((Integer) obj1).intValue();
+ int int2 = ((Integer) obj2).intValue();
+ if (int1 == int2) {
+ return 0;
+ }
+
+ if (int1 < int2) {
+ return -1;
+ } else {
+ return 1;
}
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerSerializer.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerSerializer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IntegerSerializer.java Thu Jan 21 10:37:58 2010
@@ -68,52 +68,43 @@
/**
* Optimized serializer for integers.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: IntegerSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
-public class IntegerSerializer
- implements Serializer
-{
-
-
- public static final IntegerSerializer INSTANCE = new IntegerSerializer();
-
-
- /**
- * Construct an IntegerSerializer.
- */
- public IntegerSerializer()
- {
- // no op
- }
-
-
- /**
- * Serialize the content of an object into a byte array.
- *
- * @param obj Object to serialize
- * @return a byte array representing the object's state
- */
- public byte[] serialize( Object obj )
- throws IOException
- {
- Integer number = (Integer) obj;
- return Conversion.convertToByteArray( number.intValue() );
- }
-
-
- /**
- * Deserialize the content of an object from a byte array.
- *
- * @param serialized Byte array representation of the object
- * @return deserialized object
- */
- public Object deserialize( byte[] serialized )
- throws IOException
- {
- int number = Conversion.convertToInt( serialized );
- return new Integer( number );
- }
+public class IntegerSerializer implements Serializer {
+
+ public static final IntegerSerializer INSTANCE = new IntegerSerializer();
+
+ /**
+ * Construct an IntegerSerializer.
+ */
+ public IntegerSerializer() {
+ // no op
+ }
+
+ /**
+ * Serialize the content of an object into a byte array.
+ *
+ * @param obj
+ * Object to serialize
+ * @return a byte array representing the object's state
+ */
+ public byte[] serialize(Object obj) throws IOException {
+ Integer number = (Integer) obj;
+ return Conversion.convertToByteArray(number.intValue());
+ }
+
+ /**
+ * Deserialize the content of an object from a byte array.
+ *
+ * @param serialized
+ * Byte array representation of the object
+ * @return deserialized object
+ */
+ public Object deserialize(byte[] serialized) throws IOException {
+ int number = Conversion.convertToInt(serialized);
+ return new Integer(number);
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/IterationException.java Thu Jan 21 10:37:58 2010
@@ -65,51 +65,45 @@
package org.apache.hadoop.hive.ql.util.jdbm.helper;
-
/**
* Iteration exception.
- *
+ *
* @author <a href="boisvert@intalio.com">Alex Boisvert</a>
* @version $Revision: 1.2 $
*/
-public class IterationException
- extends WrappedRuntimeException
-{
-
- /**
- * Construct a new iteration exception wrapping an underlying exception
- * and providing a message.
- *
- * @param message The exception message
- * @param except The underlying exception
- */
- public IterationException( String message, Exception except )
- {
- super( message, except );
- }
-
-
- /**
- * Construct a new iteration exception with a message.
- *
- * @param message The exception message
- */
- public IterationException( String message )
- {
- super( message, null );
- }
-
-
- /**
- * Construct a new iteration exception wrapping an underlying exception.
- *
- * @param except The underlying exception
- */
- public IterationException( Exception except )
- {
- super( except );
- }
-
-}
+public class IterationException extends WrappedRuntimeException {
+ /**
+ * Construct a new iteration exception wrapping an underlying exception and
+ * providing a message.
+ *
+ * @param message
+ * The exception message
+ * @param except
+ * The underlying exception
+ */
+ public IterationException(String message, Exception except) {
+ super(message, except);
+ }
+
+ /**
+ * Construct a new iteration exception with a message.
+ *
+ * @param message
+ * The exception message
+ */
+ public IterationException(String message) {
+ super(message, null);
+ }
+
+ /**
+ * Construct a new iteration exception wrapping an underlying exception.
+ *
+ * @param except
+ * The underlying exception
+ */
+ public IterationException(Exception except) {
+ super(except);
+ }
+}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongComparator.java Thu Jan 21 10:37:58 2010
@@ -69,48 +69,46 @@
/**
* Comparator for java.lang.Long objects.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: LongComparator.java,v 1.4 2002/05/31 06:33:20 boisvert Exp $
*/
-public final class LongComparator
- implements Comparator, Serializable
-{
-
- /**
- * Version id for serialization.
- */
- final static long serialVersionUID = 1L;
-
-
- /**
- * Compare two objects.
- *
- * @param obj1 First object
- * @param obj2 Second object
- * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
- * and a negative integer if obj1 < obj2
- */
- public int compare( Object obj1, Object obj2 )
- {
- if ( obj1 == null ) {
- throw new IllegalArgumentException( "Argument 'obj1' is null" );
- }
-
- if ( obj2 == null ) {
- throw new IllegalArgumentException( "Argument 'obj2' is null" );
- }
-
- long l1 = ( (Long) obj1 ).longValue();
- long l2 = ( (Long) obj2 ).longValue();
-
- if ( l1 > l2 ) {
- return 1;
- } else if ( l1 == l2 ) {
- return 0;
- } else {
- return -1;
- }
- }
+public final class LongComparator implements Comparator, Serializable {
+
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+ /**
+ * Compare two objects.
+ *
+ * @param obj1
+ * First object
+ * @param obj2
+ * Second object
+ * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2, and a
+ * negative integer if obj1 < obj2
+ */
+ public int compare(Object obj1, Object obj2) {
+ if (obj1 == null) {
+ throw new IllegalArgumentException("Argument 'obj1' is null");
+ }
+
+ if (obj2 == null) {
+ throw new IllegalArgumentException("Argument 'obj2' is null");
+ }
+
+ long l1 = ((Long) obj1).longValue();
+ long l2 = ((Long) obj2).longValue();
+
+ if (l1 > l2) {
+ return 1;
+ } else if (l1 == l2) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/LongSerializer.java Thu Jan 21 10:37:58 2010
@@ -68,52 +68,43 @@
/**
* Optimized serializer for long integers.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: LongSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
-public class LongSerializer
- implements Serializer
-{
-
-
- public static final LongSerializer INSTANCE = new LongSerializer();
-
-
- /**
- * Construct a LongSerializer.
- */
- public LongSerializer()
- {
- // no op
- }
-
-
- /**
- * Serialize the content of an object into a byte array.
- *
- * @param obj Object to serialize
- * @return a byte array representing the object's state
- */
- public byte[] serialize( Object obj )
- throws IOException
- {
- Long number = (Long) obj;
- return Conversion.convertToByteArray( number.longValue() );
- }
-
-
- /**
- * Deserialize the content of an object from a byte array.
- *
- * @param serialized Byte array representation of the object
- * @return deserialized object
- */
- public Object deserialize( byte[] serialized )
- throws IOException
- {
- long number = Conversion.convertToLong( serialized );
- return new Long( number );
- }
+public class LongSerializer implements Serializer {
+
+ public static final LongSerializer INSTANCE = new LongSerializer();
+
+ /**
+ * Construct a LongSerializer.
+ */
+ public LongSerializer() {
+ // no op
+ }
+
+ /**
+ * Serialize the content of an object into a byte array.
+ *
+ * @param obj
+ * Object to serialize
+ * @return a byte array representing the object's state
+ */
+ public byte[] serialize(Object obj) throws IOException {
+ Long number = (Long) obj;
+ return Conversion.convertToByteArray(number.longValue());
+ }
+
+ /**
+ * Deserialize the content of an object from a byte array.
+ *
+ * @param serialized
+ * Byte array representation of the object
+ * @return deserialized object
+ */
+ public Object deserialize(byte[] serialized) throws IOException {
+ long number = Conversion.convertToLong(serialized);
+ return new Long(number);
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/MRU.java Thu Jan 21 10:37:58 2010
@@ -69,216 +69,210 @@
import java.util.Hashtable;
import java.util.Vector;
-
/**
- * MRU - Most Recently Used cache policy.
- *
- * Methods are *not* synchronized, so no concurrent access is allowed.
- *
+ * MRU - Most Recently Used cache policy.
+ *
+ * Methods are *not* synchronized, so no concurrent access is allowed.
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: MRU.java,v 1.8 2005/06/25 23:12:31 doomdark Exp $
*/
public class MRU implements CachePolicy {
- /** Cached object hashtable */
- Hashtable _hash = new Hashtable();
-
- /**
- * Maximum number of objects in the cache.
- */
- int _max;
-
- /**
- * Beginning of linked-list of cache elements. First entry is element
- * which has been used least recently.
- */
- CacheEntry _first;
-
- /**
- * End of linked-list of cache elements. Last entry is element
- * which has been used most recently.
- */
- CacheEntry _last;
-
-
- /**
- * Cache eviction listeners
- */
- Vector listeners = new Vector();
-
-
- /**
- * Construct an MRU with a given maximum number of objects.
- */
- public MRU(int max) {
- if (max <= 0) {
- throw new IllegalArgumentException("MRU cache must contain at least one entry");
- }
- _max = max;
- }
-
-
- /**
- * Place an object in the cache.
- */
- public void put(Object key, Object value) throws CacheEvictionException {
- CacheEntry entry = (CacheEntry)_hash.get(key);
- if (entry != null) {
- entry.setValue(value);
- touchEntry(entry);
- } else {
-
- if (_hash.size() == _max) {
- // purge and recycle entry
- entry = purgeEntry();
- entry.setKey(key);
- entry.setValue(value);
- } else {
- entry = new CacheEntry(key, value);
- }
- addEntry(entry);
- _hash.put(entry.getKey(), entry);
- }
- }
-
-
- /**
- * Obtain an object in the cache
- */
- public Object get(Object key) {
- CacheEntry entry = (CacheEntry)_hash.get(key);
- if (entry != null) {
- touchEntry(entry);
- return entry.getValue();
- } else {
- return null;
- }
- }
-
-
- /**
- * Remove an object from the cache
- */
- public void remove(Object key) {
- CacheEntry entry = (CacheEntry)_hash.get(key);
- if (entry != null) {
- removeEntry(entry);
- _hash.remove(entry.getKey());
- }
- }
-
-
- /**
- * Remove all objects from the cache
- */
- public void removeAll() {
- _hash = new Hashtable();
- _first = null;
- _last = null;
- }
-
-
- /**
- * Enumerate elements' values in the cache
- */
- public Enumeration elements() {
- return new MRUEnumeration(_hash.elements());
- }
-
- /**
- * Add a listener to this cache policy
- *
- * @param listener Listener to add to this policy
- */
- public void addListener(CachePolicyListener listener) {
- if (listener == null) {
- throw new IllegalArgumentException("Cannot add null listener.");
- }
- if ( ! listeners.contains(listener)) {
- listeners.addElement(listener);
- }
- }
-
- /**
- * Remove a listener from this cache policy
- *
- * @param listener Listener to remove from this policy
- */
- public void removeListener(CachePolicyListener listener) {
- listeners.removeElement(listener);
- }
-
- /**
- * Add a CacheEntry. Entry goes at the end of the list.
- */
- protected void addEntry(CacheEntry entry) {
- if (_first == null) {
- _first = entry;
- _last = entry;
- } else {
- _last.setNext(entry);
- entry.setPrevious(_last);
- _last = entry;
- }
- }
-
-
- /**
- * Remove a CacheEntry from linked list
- */
- protected void removeEntry(CacheEntry entry) {
- if (entry == _first) {
- _first = entry.getNext();
- }
- if (_last == entry) {
- _last = entry.getPrevious();
- }
- CacheEntry previous = entry.getPrevious();
- CacheEntry next = entry.getNext();
- if (previous != null) {
- previous.setNext(next);
- }
- if (next != null) {
- next.setPrevious(previous);
- }
- entry.setPrevious(null);
- entry.setNext(null);
- }
-
- /**
- * Place entry at the end of linked list -- Most Recently Used
- */
- protected void touchEntry(CacheEntry entry) {
- if (_last == entry) {
- return;
- }
- removeEntry(entry);
- addEntry(entry);
- }
-
- /**
- * Purge least recently used object from the cache
- *
- * @return recyclable CacheEntry
- */
- protected CacheEntry purgeEntry() throws CacheEvictionException {
- CacheEntry entry = _first;
-
- // Notify policy listeners first. if any of them throw an
- // eviction exception, then the internal data structure
- // remains untouched.
- CachePolicyListener listener;
- for (int i=0; i<listeners.size(); i++) {
- listener = (CachePolicyListener)listeners.elementAt(i);
- listener.cacheObjectEvicted(entry.getValue());
- }
+ /** Cached object hashtable */
+ Hashtable _hash = new Hashtable();
- removeEntry(entry);
- _hash.remove(entry.getKey());
-
- entry.setValue(null);
- return entry;
- }
+ /**
+ * Maximum number of objects in the cache.
+ */
+ int _max;
+
+ /**
+ * Beginning of linked-list of cache elements. First entry is element which
+ * has been used least recently.
+ */
+ CacheEntry _first;
+
+ /**
+ * End of linked-list of cache elements. Last entry is element which has been
+ * used most recently.
+ */
+ CacheEntry _last;
+
+ /**
+ * Cache eviction listeners
+ */
+ Vector listeners = new Vector();
+
+ /**
+ * Construct an MRU with a given maximum number of objects.
+ */
+ public MRU(int max) {
+ if (max <= 0) {
+ throw new IllegalArgumentException(
+ "MRU cache must contain at least one entry");
+ }
+ _max = max;
+ }
+
+ /**
+ * Place an object in the cache.
+ */
+ public void put(Object key, Object value) throws CacheEvictionException {
+ CacheEntry entry = (CacheEntry) _hash.get(key);
+ if (entry != null) {
+ entry.setValue(value);
+ touchEntry(entry);
+ } else {
+
+ if (_hash.size() == _max) {
+ // purge and recycle entry
+ entry = purgeEntry();
+ entry.setKey(key);
+ entry.setValue(value);
+ } else {
+ entry = new CacheEntry(key, value);
+ }
+ addEntry(entry);
+ _hash.put(entry.getKey(), entry);
+ }
+ }
+
+ /**
+ * Obtain an object in the cache
+ */
+ public Object get(Object key) {
+ CacheEntry entry = (CacheEntry) _hash.get(key);
+ if (entry != null) {
+ touchEntry(entry);
+ return entry.getValue();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Remove an object from the cache
+ */
+ public void remove(Object key) {
+ CacheEntry entry = (CacheEntry) _hash.get(key);
+ if (entry != null) {
+ removeEntry(entry);
+ _hash.remove(entry.getKey());
+ }
+ }
+
+ /**
+ * Remove all objects from the cache
+ */
+ public void removeAll() {
+ _hash = new Hashtable();
+ _first = null;
+ _last = null;
+ }
+
+ /**
+ * Enumerate elements' values in the cache
+ */
+ public Enumeration elements() {
+ return new MRUEnumeration(_hash.elements());
+ }
+
+ /**
+ * Add a listener to this cache policy
+ *
+ * @param listener
+ * Listener to add to this policy
+ */
+ public void addListener(CachePolicyListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException("Cannot add null listener.");
+ }
+ if (!listeners.contains(listener)) {
+ listeners.addElement(listener);
+ }
+ }
+
+ /**
+ * Remove a listener from this cache policy
+ *
+ * @param listener
+ * Listener to remove from this policy
+ */
+ public void removeListener(CachePolicyListener listener) {
+ listeners.removeElement(listener);
+ }
+
+ /**
+ * Add a CacheEntry. Entry goes at the end of the list.
+ */
+ protected void addEntry(CacheEntry entry) {
+ if (_first == null) {
+ _first = entry;
+ _last = entry;
+ } else {
+ _last.setNext(entry);
+ entry.setPrevious(_last);
+ _last = entry;
+ }
+ }
+
+ /**
+ * Remove a CacheEntry from linked list
+ */
+ protected void removeEntry(CacheEntry entry) {
+ if (entry == _first) {
+ _first = entry.getNext();
+ }
+ if (_last == entry) {
+ _last = entry.getPrevious();
+ }
+ CacheEntry previous = entry.getPrevious();
+ CacheEntry next = entry.getNext();
+ if (previous != null) {
+ previous.setNext(next);
+ }
+ if (next != null) {
+ next.setPrevious(previous);
+ }
+ entry.setPrevious(null);
+ entry.setNext(null);
+ }
+
+ /**
+ * Place entry at the end of linked list -- Most Recently Used
+ */
+ protected void touchEntry(CacheEntry entry) {
+ if (_last == entry) {
+ return;
+ }
+ removeEntry(entry);
+ addEntry(entry);
+ }
+
+ /**
+ * Purge least recently used object from the cache
+ *
+ * @return recyclable CacheEntry
+ */
+ protected CacheEntry purgeEntry() throws CacheEvictionException {
+ CacheEntry entry = _first;
+
+ // Notify policy listeners first. if any of them throw an
+ // eviction exception, then the internal data structure
+ // remains untouched.
+ CachePolicyListener listener;
+ for (int i = 0; i < listeners.size(); i++) {
+ listener = (CachePolicyListener) listeners.elementAt(i);
+ listener.cacheObjectEvicted(entry.getValue());
+ }
+
+ removeEntry(entry);
+ _hash.remove(entry.getKey());
+
+ entry.setValue(null);
+ return entry;
+ }
}
@@ -286,67 +280,66 @@
* State information for cache entries.
*/
class CacheEntry {
- private Object _key;
- private Object _value;
-
- private CacheEntry _previous;
- private CacheEntry _next;
-
- CacheEntry(Object key, Object value) {
- _key = key;
- _value = value;
- }
-
- Object getKey() {
- return _key;
- }
-
- void setKey(Object obj) {
- _key = obj;
- }
-
- Object getValue() {
- return _value;
- }
+ private Object _key;
+ private Object _value;
- void setValue(Object obj) {
- _value = obj;
- }
-
- CacheEntry getPrevious() {
- return _previous;
- }
-
- void setPrevious(CacheEntry entry) {
- _previous = entry;
- }
-
- CacheEntry getNext() {
- return _next;
- }
+ private CacheEntry _previous;
+ private CacheEntry _next;
- void setNext(CacheEntry entry) {
- _next = entry;
- }
+ CacheEntry(Object key, Object value) {
+ _key = key;
+ _value = value;
+ }
+
+ Object getKey() {
+ return _key;
+ }
+
+ void setKey(Object obj) {
+ _key = obj;
+ }
+
+ Object getValue() {
+ return _value;
+ }
+
+ void setValue(Object obj) {
+ _value = obj;
+ }
+
+ CacheEntry getPrevious() {
+ return _previous;
+ }
+
+ void setPrevious(CacheEntry entry) {
+ _previous = entry;
+ }
+
+ CacheEntry getNext() {
+ return _next;
+ }
+
+ void setNext(CacheEntry entry) {
+ _next = entry;
+ }
}
/**
- * Enumeration wrapper to return actual user objects instead of
- * CacheEntries.
+ * Enumeration wrapper to return actual user objects instead of CacheEntries.
*/
class MRUEnumeration implements Enumeration {
- Enumeration _enum;
-
- MRUEnumeration(Enumeration enume) {
- _enum = enume;
- }
+ Enumeration _enum;
- public boolean hasMoreElements() {
- return _enum.hasMoreElements();
- }
-
- public Object nextElement() {
- CacheEntry entry = (CacheEntry)_enum.nextElement();
- return entry.getValue();
- }
+ MRUEnumeration(Enumeration enume) {
+ _enum = enume;
+ }
+
+ public boolean hasMoreElements() {
+ return _enum.hasMoreElements();
+ }
+
+ public Object nextElement() {
+ CacheEntry entry = (CacheEntry) _enum.nextElement();
+ return entry.getValue();
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/ObjectBAComparator.java Thu Jan 21 10:37:58 2010
@@ -69,116 +69,111 @@
import java.util.Comparator;
/**
- * Comparator for objects which have been serialized into byte arrays.
- * In effect, it wraps another Comparator which compares object and provides
+ * Comparator for objects which have been serialized into byte arrays. In
+ * effect, it wraps another Comparator which compares object and provides
* transparent deserialization from byte array to object.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
- * @version $Id: ObjectBAComparator.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $
+ * @version $Id: ObjectBAComparator.java,v 1.1 2002/05/31 06:33:20 boisvert Exp
+ * $
*/
-public final class ObjectBAComparator
- implements Comparator, Serializable
-{
-
- /**
- * Version id for serialization.
- */
- final static long serialVersionUID = 1L;
-
-
- /**
- * Wrapped comparator.
- */
- private Comparator _comparator;
-
-
- /**
- * Construct an ObjectByteArrayComparator which wraps an Object Comparator.
- *
- * @param comparator Object comparator.
- */
- public ObjectBAComparator( Comparator comparator )
- {
- if ( comparator == null ) {
- throw new IllegalArgumentException( "Argument 'comparator' is null" );
- }
+public final class ObjectBAComparator implements Comparator, Serializable {
- _comparator = comparator;
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+ /**
+ * Wrapped comparator.
+ */
+ private final Comparator _comparator;
+
+ /**
+ * Construct an ObjectByteArrayComparator which wraps an Object Comparator.
+ *
+ * @param comparator
+ * Object comparator.
+ */
+ public ObjectBAComparator(Comparator comparator) {
+ if (comparator == null) {
+ throw new IllegalArgumentException("Argument 'comparator' is null");
}
+ _comparator = comparator;
+ }
- /**
- * Compare two objects.
- *
- * @param obj1 First object
- * @param obj2 Second object
- * @return 1 if obj1 > obj2, 0 if obj1 == obj2, -1 if obj1 < obj2
- */
- public int compare( Object obj1, Object obj2 )
- {
- if ( obj1 == null ) {
- throw new IllegalArgumentException( "Argument 'obj1' is null" );
- }
-
- if ( obj2 == null ) {
- throw new IllegalArgumentException( "Argument 'obj2' is null" );
- }
+ /**
+ * Compare two objects.
+ *
+ * @param obj1
+ * First object
+ * @param obj2
+ * Second object
+ * @return 1 if obj1 > obj2, 0 if obj1 == obj2, -1 if obj1 < obj2
+ */
+ public int compare(Object obj1, Object obj2) {
+ if (obj1 == null) {
+ throw new IllegalArgumentException("Argument 'obj1' is null");
+ }
- try {
- obj1 = Serialization.deserialize( (byte[]) obj1 );
- obj2 = Serialization.deserialize( (byte[]) obj2 );
-
- return _comparator.compare( obj1, obj2 );
- } catch ( IOException except ) {
- throw new WrappedRuntimeException( except );
- } catch ( ClassNotFoundException except ) {
- throw new WrappedRuntimeException( except );
- }
- }
+ if (obj2 == null) {
+ throw new IllegalArgumentException("Argument 'obj2' is null");
+ }
+ try {
+ obj1 = Serialization.deserialize((byte[]) obj1);
+ obj2 = Serialization.deserialize((byte[]) obj2);
+
+ return _comparator.compare(obj1, obj2);
+ } catch (IOException except) {
+ throw new WrappedRuntimeException(except);
+ } catch (ClassNotFoundException except) {
+ throw new WrappedRuntimeException(except);
+ }
+ }
- /**
- * Compare two byte arrays.
- */
- public static int compareByteArray( byte[] thisKey, byte[] otherKey )
- {
- int len = Math.min( thisKey.length, otherKey.length );
-
- // compare the byte arrays
- for ( int i=0; i<len; i++ ) {
- if ( thisKey[i] >= 0 ) {
- if ( otherKey[i] >= 0 ) {
- // both positive
- if ( thisKey[i] < otherKey[i] ) {
- return -1;
- } else if ( thisKey[i] > otherKey[i] ) {
- return 1;
- }
- } else {
- // otherKey is negative => greater (because MSB is 1)
- return -1;
- }
- } else {
- if ( otherKey[i] >= 0 ) {
- // thisKey is negative => greater (because MSB is 1)
- return 1;
- } else {
- // both negative
- if ( thisKey[i] < otherKey[i] ) {
- return -1;
- } else if ( thisKey[i] > otherKey[i] ) {
- return 1;
- }
- }
- }
- }
- if ( thisKey.length == otherKey.length) {
- return 0;
- }
- if ( thisKey.length < otherKey.length ) {
+ /**
+ * Compare two byte arrays.
+ */
+ public static int compareByteArray(byte[] thisKey, byte[] otherKey) {
+ int len = Math.min(thisKey.length, otherKey.length);
+
+ // compare the byte arrays
+ for (int i = 0; i < len; i++) {
+ if (thisKey[i] >= 0) {
+ if (otherKey[i] >= 0) {
+ // both positive
+ if (thisKey[i] < otherKey[i]) {
return -1;
+ } else if (thisKey[i] > otherKey[i]) {
+ return 1;
+ }
+ } else {
+ // otherKey is negative => greater (because MSB is 1)
+ return -1;
+ }
+ } else {
+ if (otherKey[i] >= 0) {
+ // thisKey is negative => greater (because MSB is 1)
+ return 1;
+ } else {
+ // both negative
+ if (thisKey[i] < otherKey[i]) {
+ return -1;
+ } else if (thisKey[i] > otherKey[i]) {
+ return 1;
+ }
}
- return 1;
+ }
+ }
+ if (thisKey.length == otherKey.length) {
+ return 0;
+ }
+ if (thisKey.length < otherKey.length) {
+ return -1;
}
+ return 1;
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serialization.java Thu Jan 21 10:37:58 2010
@@ -72,43 +72,38 @@
/**
* Serialization-related utility methods.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: Serialization.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $
*/
-public final class Serialization
-{
+public final class Serialization {
- /**
- * Serialize the object into a byte array.
- */
- public static byte[] serialize( Object obj )
- throws IOException
- {
- ByteArrayOutputStream baos;
- ObjectOutputStream oos;
-
- baos = new ByteArrayOutputStream();
- oos = new ObjectOutputStream( baos );
- oos.writeObject( obj );
- oos.close();
-
- return baos.toByteArray();
- }
-
-
- /**
- * Deserialize an object from a byte array
- */
- public static Object deserialize( byte[] buf )
- throws ClassNotFoundException, IOException
- {
- ByteArrayInputStream bais;
- ObjectInputStream ois;
-
- bais = new ByteArrayInputStream( buf );
- ois = new ObjectInputStream( bais );
- return ois.readObject();
- }
+ /**
+ * Serialize the object into a byte array.
+ */
+ public static byte[] serialize(Object obj) throws IOException {
+ ByteArrayOutputStream baos;
+ ObjectOutputStream oos;
+
+ baos = new ByteArrayOutputStream();
+ oos = new ObjectOutputStream(baos);
+ oos.writeObject(obj);
+ oos.close();
+
+ return baos.toByteArray();
+ }
+
+ /**
+ * Deserialize an object from a byte array
+ */
+ public static Object deserialize(byte[] buf) throws ClassNotFoundException,
+ IOException {
+ ByteArrayInputStream bais;
+ ObjectInputStream ois;
+
+ bais = new ByteArrayInputStream(buf);
+ ois = new ObjectInputStream(bais);
+ return ois.readObject();
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Serializer.java Thu Jan 21 10:37:58 2010
@@ -68,33 +68,30 @@
import java.io.Serializable;
/**
- * Interface used to provide a serialization mechanism other than a class' normal
- * serialization.
- *
+ * Interface used to provide a serialization mechanism other than a class'
+ * normal serialization.
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: Serializer.java,v 1.1 2003/03/21 02:48:42 boisvert Exp $
*/
-public interface Serializer
- extends Serializable
-{
+public interface Serializer extends Serializable {
- /**
- * Serialize the content of an object into a byte array.
- *
- * @param obj Object to serialize
- * @return a byte array representing the object's state
- */
- public byte[] serialize( Object obj )
- throws IOException;
-
-
- /**
- * Deserialize the content of an object from a byte array.
- *
- * @param serialized Byte array representation of the object
- * @return deserialized object
- */
- public Object deserialize( byte[] serialized )
- throws IOException;
+ /**
+ * Serialize the content of an object into a byte array.
+ *
+ * @param obj
+ * Object to serialize
+ * @return a byte array representing the object's state
+ */
+ public byte[] serialize(Object obj) throws IOException;
+
+ /**
+ * Deserialize the content of an object from a byte array.
+ *
+ * @param serialized
+ * Byte array representation of the object
+ * @return deserialized object
+ */
+ public Object deserialize(byte[] serialized) throws IOException;
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/SoftCache.java Thu Jan 21 10:37:58 2010
@@ -64,249 +64,265 @@
*/
package org.apache.hadoop.hive.ql.util.jdbm.helper;
+import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
-import java.lang.ref.Reference;
import java.util.Enumeration;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
/**
* Wraps a deterministic cache policy with a <q>Level-2</q> cache based on
- * J2SE's {@link SoftReference soft references}. Soft references allow
- * this cache to keep references to objects until the memory they occupy
- * is required elsewhere.
+ * J2SE's {@link SoftReference soft references}. Soft references allow this
+ * cache to keep references to objects until the memory they occupy is required
+ * elsewhere.
* <p>
- * Since the {@link CachePolicy} interface requires an event be fired
- * when an object is evicted, and the event contains the actual object,
- * this class cannot be a stand-alone implementation of
- * <code>CachePolicy</code>. This limitation arises because Java References
- * does not support notification before references are cleared; nor do
- * they support reaching soft referents. Therefore, this wrapper cache
- * aggressively notifies evictions: events are fired when the objects are
- * evicted from the internal cache. Consequently, the soft cache may return
- * a non-null object when <code>get( )</code> is called, even if that
- * object was said to have been evicted.
+ * Since the {@link CachePolicy} interface requires an event be fired when an
+ * object is evicted, and the event contains the actual object, this class
+ * cannot be a stand-alone implementation of <code>CachePolicy</code>. This
+ * limitation arises because Java References does not support notification
+ * before references are cleared; nor do they support reaching soft referents.
+ * Therefore, this wrapper cache aggressively notifies evictions: events are
+ * fired when the objects are evicted from the internal cache. Consequently, the
+ * soft cache may return a non-null object when <code>get( )</code> is called,
+ * even if that object was said to have been evicted.
* <p>
- * The current implementation uses a hash structure for its internal key
- * to value mappings.
+ * The current implementation uses a hash structure for its internal key to
+ * value mappings.
* <p>
* Note: this component's publicly exposed methods are not threadsafe;
* potentially concurrent code should synchronize on the cache instance.
- *
+ *
* @author <a href="mailto:dranatunga@users.sourceforge.net">Dilum Ranatunga</a>
* @version $Id: SoftCache.java,v 1.1 2003/11/01 13:29:27 dranatunga Exp $
*/
public class SoftCache implements CachePolicy {
- private static final int INITIAL_CAPACITY = 128;
- private static final float DEFAULT_LOAD_FACTOR = 1.5f;
-
- private final ReferenceQueue _clearQueue = new ReferenceQueue();
- private final CachePolicy _internal;
- private final Map _cacheMap;
-
- /**
- * Creates a soft-reference based L2 cache with a {@link MRU} cache as
- * the internal (L1) cache. The soft reference cache uses the
- * default load capacity of 1.5f, which is intended to sacrifice some
- * performance for space. This compromise is reasonable, since all
- * {@link #get(Object) get( )s} first try the L1 cache anyway. The
- * internal MRU is given a capacity of 128 elements.
- */
- public SoftCache() {
- this(new MRU(INITIAL_CAPACITY));
- }
-
- /**
- * Creates a soft-reference based L2 cache wrapping the specified
- * L1 cache.
- *
- * @param internal non null internal cache.
- * @throws NullPointerException if the internal cache is null.
- */
- public SoftCache(CachePolicy internal) throws NullPointerException {
- this(DEFAULT_LOAD_FACTOR, internal);
- }
+ private static final int INITIAL_CAPACITY = 128;
+ private static final float DEFAULT_LOAD_FACTOR = 1.5f;
- /**
- * Creates a soft-reference based L2 cache wrapping the specified
- * L1 cache. This constructor is somewhat implementation-specific,
- * so users are encouraged to use {@link #SoftCache(CachePolicy)}
- * instead.
- *
- * @param loadFactor load factor that the soft cache's hash structure
- * should use.
- * @param internal non null internal cache.
- * @throws IllegalArgumentException if the load factor is nonpositive.
- * @throws NullPointerException if the internal cache is null.
- */
- public SoftCache(float loadFactor, CachePolicy internal) throws IllegalArgumentException, NullPointerException {
- if (internal == null) {
- throw new NullPointerException("Internal cache cannot be null.");
- }
- _internal = internal;
- _cacheMap = new HashMap(INITIAL_CAPACITY, loadFactor);
- }
-
- /**
- * Adds the specified value to the cache under the specified key. Note
- * that the object is added to both this and the internal cache.
- * @param key the (non-null) key to store the object under
- * @param value the (non-null) object to place in the cache
- * @throws CacheEvictionException exception that the internal cache
- * would have experienced while evicting an object it currently
- * cached.
- */
- public void put(Object key, Object value) throws CacheEvictionException {
- if (key == null) {
- throw new IllegalArgumentException("key cannot be null.");
- } else if (value == null) {
- throw new IllegalArgumentException("value cannot be null.");
- }
- _internal.put(key, value);
- removeClearedEntries();
- _cacheMap.put(key, new Entry(key, value, _clearQueue));
- }
-
- /**
- * Gets the object cached under the specified key.
- * <p>
- * The cache is looked up in the following manner:
- * <ol>
- * <li>The internal (L1) cache is checked. If the object is found, it is
- * returned.</li>
- * <li>This (L2) cache is checked. If the object is not found, then
- * the caller is informed that the object is inaccessible.</li>
- * <li>Since the object exists in L2, but not in L1, the object is
- * readded to L1 using {@link CachePolicy#put(Object, Object)}.</li>
- * <li>If the readding succeeds, the value is returned to caller.</li>
- * <li>If a cache eviction exception is encountered instead, we
- * remove the object from L2 and behave as if the object was
- * inaccessible.</li>
- * </ol>
- * @param key the key that the object was stored under.
- * @return the object stored under the key specified; null if the
- * object is not (nolonger) accessible via this cache.
- */
- public Object get(Object key) {
- // first try the internal cache.
- Object value = _internal.get(key);
- if (value != null) {
- return value;
- }
- // poll and remove cleared references.
- removeClearedEntries();
- Entry entry = (Entry)_cacheMap.get(key);
- if (entry == null) { // object is not in cache.
- return null;
- }
- value = entry.getValue();
- if (value == null) { // object was in cache, but it was cleared.
- return null;
- }
- // we have the object. so we try to re-insert it into internal cache
- try {
- _internal.put(key, value);
- } catch (CacheEvictionException e) {
- // if the internal cache causes a fuss, we kick the object out.
- _cacheMap.remove(key);
- return null;
- }
- return value;
- }
-
- /**
- * Removes any object stored under the key specified. Note that the
- * object is removed from both this (L2) and the internal (L1)
- * cache.
- * @param key the key whose object should be removed
+ private final ReferenceQueue _clearQueue = new ReferenceQueue();
+ private final CachePolicy _internal;
+ private final Map _cacheMap;
+
+ /**
+ * Creates a soft-reference based L2 cache with a {@link MRU} cache as the
+ * internal (L1) cache. The soft reference cache uses the default load
+ * capacity of 1.5f, which is intended to sacrifice some performance for
+ * space. This compromise is reasonable, since all {@link #get(Object) get(
+ * )s} first try the L1 cache anyway. The internal MRU is given a capacity of
+ * 128 elements.
+ */
+ public SoftCache() {
+ this(new MRU(INITIAL_CAPACITY));
+ }
+
+ /**
+ * Creates a soft-reference based L2 cache wrapping the specified L1 cache.
+ *
+ * @param internal
+ * non null internal cache.
+ * @throws NullPointerException
+ * if the internal cache is null.
+ */
+ public SoftCache(CachePolicy internal) throws NullPointerException {
+ this(DEFAULT_LOAD_FACTOR, internal);
+ }
+
+ /**
+ * Creates a soft-reference based L2 cache wrapping the specified L1 cache.
+ * This constructor is somewhat implementation-specific, so users are
+ * encouraged to use {@link #SoftCache(CachePolicy)} instead.
+ *
+ * @param loadFactor
+ * load factor that the soft cache's hash structure should use.
+ * @param internal
+ * non null internal cache.
+ * @throws IllegalArgumentException
+ * if the load factor is nonpositive.
+ * @throws NullPointerException
+ * if the internal cache is null.
+ */
+ public SoftCache(float loadFactor, CachePolicy internal)
+ throws IllegalArgumentException, NullPointerException {
+ if (internal == null) {
+ throw new NullPointerException("Internal cache cannot be null.");
+ }
+ _internal = internal;
+ _cacheMap = new HashMap(INITIAL_CAPACITY, loadFactor);
+ }
+
+ /**
+ * Adds the specified value to the cache under the specified key. Note that
+ * the object is added to both this and the internal cache.
+ *
+ * @param key
+ * the (non-null) key to store the object under
+ * @param value
+ * the (non-null) object to place in the cache
+ * @throws CacheEvictionException
+ * exception that the internal cache would have experienced while
+ * evicting an object it currently cached.
+ */
+ public void put(Object key, Object value) throws CacheEvictionException {
+ if (key == null) {
+ throw new IllegalArgumentException("key cannot be null.");
+ } else if (value == null) {
+ throw new IllegalArgumentException("value cannot be null.");
+ }
+ _internal.put(key, value);
+ removeClearedEntries();
+ _cacheMap.put(key, new Entry(key, value, _clearQueue));
+ }
+
+ /**
+ * Gets the object cached under the specified key.
+ * <p>
+ * The cache is looked up in the following manner:
+ * <ol>
+ * <li>The internal (L1) cache is checked. If the object is found, it is
+ * returned.</li>
+ * <li>This (L2) cache is checked. If the object is not found, then the caller
+ * is informed that the object is inaccessible.</li>
+ * <li>Since the object exists in L2, but not in L1, the object is readded to
+ * L1 using {@link CachePolicy#put(Object, Object)}.</li>
+ * <li>If the readding succeeds, the value is returned to caller.</li>
+ * <li>If a cache eviction exception is encountered instead, we remove the
+ * object from L2 and behave as if the object was inaccessible.</li>
+ * </ol>
+ *
+ * @param key
+ * the key that the object was stored under.
+ * @return the object stored under the key specified; null if the object is
+ * not (nolonger) accessible via this cache.
+ */
+ public Object get(Object key) {
+ // first try the internal cache.
+ Object value = _internal.get(key);
+ if (value != null) {
+ return value;
+ }
+ // poll and remove cleared references.
+ removeClearedEntries();
+ Entry entry = (Entry) _cacheMap.get(key);
+ if (entry == null) { // object is not in cache.
+ return null;
+ }
+ value = entry.getValue();
+ if (value == null) { // object was in cache, but it was cleared.
+ return null;
+ }
+ // we have the object. so we try to re-insert it into internal cache
+ try {
+ _internal.put(key, value);
+ } catch (CacheEvictionException e) {
+ // if the internal cache causes a fuss, we kick the object out.
+ _cacheMap.remove(key);
+ return null;
+ }
+ return value;
+ }
+
+ /**
+ * Removes any object stored under the key specified. Note that the object is
+ * removed from both this (L2) and the internal (L1) cache.
+ *
+ * @param key
+ * the key whose object should be removed
+ */
+ public void remove(Object key) {
+ _cacheMap.remove(key);
+ _internal.remove(key);
+ }
+
+ /**
+ * Removes all objects in this (L2) and its internal (L1) cache.
+ */
+ public void removeAll() {
+ _cacheMap.clear();
+ _internal.removeAll();
+ }
+
+ /**
+ * Gets all the objects stored by the internal (L1) cache.
+ *
+ * @return an enumeration of objects in internal cache.
+ */
+ public Enumeration elements() {
+ return _internal.elements();
+ }
+
+ /**
+ * Adds the specified listener to this cache. Note that the events fired by
+ * this correspond to the <em>internal</em> cache's events.
+ *
+ * @param listener
+ * the (non-null) listener to add to this policy
+ * @throws IllegalArgumentException
+ * if listener is null.
+ */
+ public void addListener(CachePolicyListener listener)
+ throws IllegalArgumentException {
+ _internal.addListener(listener);
+ }
+
+ /**
+ * Removes a listener that was added earlier.
+ *
+ * @param listener
+ * the listener to remove.
+ */
+ public void removeListener(CachePolicyListener listener) {
+ _internal.removeListener(listener);
+ }
+
+ /**
+ * Cleans the mapping structure of any obsolete entries. This is usually
+ * called before insertions and lookups on the mapping structure. The runtime
+ * of this is usually very small, but it can be as expensive as n * log(n) if
+ * a large number of soft references were recently cleared.
+ */
+ private final void removeClearedEntries() {
+ for (Reference r = _clearQueue.poll(); r != null; r = _clearQueue.poll()) {
+ Object key = ((Entry) r).getKey();
+ _cacheMap.remove(key);
+ }
+ }
+
+ /**
+ * Value objects we keep in the internal map. This contains the key in
+ * addition to the value, because polling for cleared references returns these
+ * instances, and having access to their corresponding keys drastically
+ * improves the performance of removing the pair from the map (see
+ * {@link SoftCache#removeClearedEntries()}.)
+ */
+ private static class Entry extends SoftReference {
+ private final Object _key;
+
+ /**
+ * Constructor that uses <code>value</code> as the soft reference's
+ * referent.
+ */
+ public Entry(Object key, Object value, ReferenceQueue queue) {
+ super(value, queue);
+ _key = key;
+ }
+
+ /**
+ * Gets the key
+ *
+ * @return the key associated with this value.
+ */
+ final Object getKey() {
+ return _key;
+ }
+
+ /**
+ * Gets the value
+ *
+ * @return the value; null if it is no longer accessible
*/
- public void remove(Object key) {
- _cacheMap.remove(key);
- _internal.remove(key);
- }
-
- /**
- * Removes all objects in this (L2) and its internal (L1) cache.
- */
- public void removeAll() {
- _cacheMap.clear();
- _internal.removeAll();
- }
-
- /**
- * Gets all the objects stored by the internal (L1) cache.
- * @return an enumeration of objects in internal cache.
- */
- public Enumeration elements() {
- return _internal.elements();
- }
-
- /**
- * Adds the specified listener to this cache. Note that the events
- * fired by this correspond to the <em>internal</em> cache's events.
- * @param listener the (non-null) listener to add to this policy
- * @throws IllegalArgumentException if listener is null.
- */
- public void addListener(CachePolicyListener listener)
- throws IllegalArgumentException {
- _internal.addListener(listener);
- }
-
- /**
- * Removes a listener that was added earlier.
- * @param listener the listener to remove.
- */
- public void removeListener(CachePolicyListener listener) {
- _internal.removeListener(listener);
- }
-
- /**
- * Cleans the mapping structure of any obsolete entries. This is usually
- * called before insertions and lookups on the mapping structure. The
- * runtime of this is usually very small, but it can be as expensive as
- * n * log(n) if a large number of soft references were recently cleared.
- */
- private final void removeClearedEntries() {
- for (Reference r = _clearQueue.poll(); r != null; r = _clearQueue.poll()) {
- Object key = ((Entry)r).getKey();
- _cacheMap.remove(key);
- }
- }
-
- /**
- * Value objects we keep in the internal map. This contains the key in
- * addition to the value, because polling for cleared references
- * returns these instances, and having access to their corresponding
- * keys drastically improves the performance of removing the pair
- * from the map (see {@link SoftCache#removeClearedEntries()}.)
- */
- private static class Entry extends SoftReference {
- private final Object _key;
-
- /**
- * Constructor that uses <code>value</code> as the soft
- * reference's referent.
- */
- public Entry(Object key, Object value, ReferenceQueue queue) {
- super(value, queue);
- _key = key;
- }
-
- /**
- * Gets the key
- * @return the key associated with this value.
- */
- final Object getKey() {
- return _key;
- }
-
- /**
- * Gets the value
- * @return the value; null if it is no longer accessible
- */
- final Object getValue() {
- return this.get();
- }
+ final Object getValue() {
+ return this.get();
}
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/StringComparator.java Thu Jan 21 10:37:58 2010
@@ -68,40 +68,38 @@
import java.util.Comparator;
/**
- * Comparator for String objects. Delegates to String.compareTo().
- *
+ * Comparator for String objects. Delegates to String.compareTo().
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: StringComparator.java,v 1.5 2005/06/25 23:12:31 doomdark Exp $
*/
-public final class StringComparator
- implements Comparator, Serializable
-{
-
- /**
- * Version id for serialization.
- */
- final static long serialVersionUID = 1L;
-
-
- /**
- * Compare two objects.
- *
- * @param obj1 First object
- * @param obj2 Second object
- * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
- * and a negative integer if obj1 < obj2
- */
- public int compare( Object obj1, Object obj2 )
- {
- if ( obj1 == null ) {
- throw new IllegalArgumentException( "Argument 'obj1' is null" );
- }
-
- if ( obj2 == null ) {
- throw new IllegalArgumentException( "Argument 'obj2' is null" );
- }
+public final class StringComparator implements Comparator, Serializable {
- return ( (String) obj1 ).compareTo((String) obj2 );
- }
+ /**
+ * Version id for serialization.
+ */
+ final static long serialVersionUID = 1L;
+
+ /**
+ * Compare two objects.
+ *
+ * @param obj1
+ * First object
+ * @param obj2
+ * Second object
+ * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2, and a
+ * negative integer if obj1 < obj2
+ */
+ public int compare(Object obj1, Object obj2) {
+ if (obj1 == null) {
+ throw new IllegalArgumentException("Argument 'obj1' is null");
+ }
+
+ if (obj2 == null) {
+ throw new IllegalArgumentException("Argument 'obj2' is null");
+ }
+
+ return ((String) obj1).compareTo((String) obj2);
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/Tuple.java Thu Jan 21 10:37:58 2010
@@ -64,76 +64,70 @@
package org.apache.hadoop.hive.ql.util.jdbm.helper;
-
/**
* Tuple consisting of a key-value pair.
- *
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: Tuple.java,v 1.2 2001/05/19 14:02:00 boisvert Exp $
*/
public final class Tuple {
- /**
- * Key
- */
- private Object _key;
-
-
- /**
- * Value
- */
- private Object _value;
-
-
- /**
- * Construct an empty Tuple.
- */
- public Tuple() {
- // empty
- }
-
-
- /**
- * Construct a Tuple.
- *
- * @param key The key.
- * @param value The value.
- */
- public Tuple( Object key, Object value ) {
- _key = key;
- _value = value;
- }
-
-
- /**
- * Get the key.
- */
- public Object getKey() {
- return _key;
- }
-
-
- /**
- * Set the key.
- */
- public void setKey( Object key ) {
- _key = key;
- }
-
-
- /**
- * Get the value.
- */
- public Object getValue() {
- return _value;
- }
-
-
- /**
- * Set the value.
- */
- public void setValue( Object value ) {
- _value = value;
- }
+ /**
+ * Key
+ */
+ private Object _key;
+
+ /**
+ * Value
+ */
+ private Object _value;
+
+ /**
+ * Construct an empty Tuple.
+ */
+ public Tuple() {
+ // empty
+ }
+
+ /**
+ * Construct a Tuple.
+ *
+ * @param key
+ * The key.
+ * @param value
+ * The value.
+ */
+ public Tuple(Object key, Object value) {
+ _key = key;
+ _value = value;
+ }
+
+ /**
+ * Get the key.
+ */
+ public Object getKey() {
+ return _key;
+ }
+
+ /**
+ * Set the key.
+ */
+ public void setKey(Object key) {
+ _key = key;
+ }
+
+ /**
+ * Get the value.
+ */
+ public Object getValue() {
+ return _value;
+ }
+
+ /**
+ * Set the value.
+ */
+ public void setValue(Object value) {
+ _value = value;
+ }
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/TupleBrowser.java Thu Jan 21 10:37:58 2010
@@ -67,33 +67,32 @@
import java.io.IOException;
/**
- * Browser to traverse a collection of tuples. The browser allows for
- * forward and reverse order traversal.
- *
+ * Browser to traverse a collection of tuples. The browser allows for forward
+ * and reverse order traversal.
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: TupleBrowser.java,v 1.2 2001/05/19 14:02:00 boisvert Exp $
*/
public abstract class TupleBrowser {
- /**
- * Get the next tuple.
- *
- * @param tuple Tuple into which values are copied.
- * @return True if values have been copied in tuple, or false if there is
- * no next tuple.
- */
- public abstract boolean getNext( Tuple tuple )
- throws IOException;
+ /**
+ * Get the next tuple.
+ *
+ * @param tuple
+ * Tuple into which values are copied.
+ * @return True if values have been copied in tuple, or false if there is no
+ * next tuple.
+ */
+ public abstract boolean getNext(Tuple tuple) throws IOException;
-
- /**
- * Get the previous tuple.
- *
- * @param tuple Tuple into which values are copied.
- * @return True if values have been copied in tuple, or false if there is
- * no previous tuple.
- */
- public abstract boolean getPrevious( Tuple tuple )
- throws IOException;
+ /**
+ * Get the previous tuple.
+ *
+ * @param tuple
+ * Tuple into which values are copied.
+ * @return True if values have been copied in tuple, or false if there is no
+ * previous tuple.
+ */
+ public abstract boolean getPrevious(Tuple tuple) throws IOException;
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/helper/WrappedRuntimeException.java Thu Jan 21 10:37:58 2010
@@ -68,102 +68,92 @@
import java.io.PrintWriter;
/**
- * A run-time exception that wraps another exception. The printed stack
- * trace will be that of the wrapped exception.
- *
+ * A run-time exception that wraps another exception. The printed stack trace
+ * will be that of the wrapped exception.
+ *
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
- * @version $Id: WrappedRuntimeException.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $
+ * @version $Id: WrappedRuntimeException.java,v 1.1 2002/05/31 06:33:20 boisvert
+ * Exp $
*/
-public class WrappedRuntimeException
- extends RuntimeException
-{
-
-
- /**
- * The underlying exception.
- */
- private final Exception _except;
-
-
- /**
- * Constructs a new runtime exception based on a checked exception.
- *
- * @param message The error message
- * @param except The checked exception
- */
- public WrappedRuntimeException( String message, Exception except )
- {
- super( message == null ? "No message available" : message );
-
- if ( except instanceof WrappedRuntimeException &&
- ( (WrappedRuntimeException) except )._except != null )
- {
- _except = ( (WrappedRuntimeException) except )._except;
- } else {
- _except = except;
- }
- }
-
-
- /**
- * Constructs a new runtime exception based on a checked exception.
- *
- * @param except The checked exception
- */
- public WrappedRuntimeException( Exception except )
- {
- super( except == null || except.getMessage() == null ? "No message available" : except.getMessage() );
-
- if ( except instanceof WrappedRuntimeException &&
- ( (WrappedRuntimeException) except )._except != null )
- {
- _except = ( (WrappedRuntimeException) except )._except;
- } else {
- _except = except;
- }
- }
-
-
- /**
- * Returns the exception wrapped by this runtime exception.
- *
- * @return The exception wrapped by this runtime exception
- */
- public Exception getException()
- {
- return _except;
- }
-
+public class WrappedRuntimeException extends RuntimeException {
- public void printStackTrace()
- {
- if ( _except == null ) {
- super.printStackTrace();
- } else {
- _except.printStackTrace();
- }
- }
-
-
- public void printStackTrace( PrintStream stream )
- {
- if ( _except == null ) {
- super.printStackTrace( stream );
- } else {
- _except.printStackTrace( stream );
- }
- }
-
-
- public void printStackTrace( PrintWriter writer )
- {
- if ( _except == null ) {
- super.printStackTrace( writer );
- } else {
- _except.printStackTrace( writer );
- }
+ /**
+ * The underlying exception.
+ */
+ private final Exception _except;
+
+ /**
+ * Constructs a new runtime exception based on a checked exception.
+ *
+ * @param message
+ * The error message
+ * @param except
+ * The checked exception
+ */
+ public WrappedRuntimeException(String message, Exception except) {
+ super(message == null ? "No message available" : message);
+
+ if (except instanceof WrappedRuntimeException
+ && ((WrappedRuntimeException) except)._except != null) {
+ _except = ((WrappedRuntimeException) except)._except;
+ } else {
+ _except = except;
+ }
+ }
+
+ /**
+ * Constructs a new runtime exception based on a checked exception.
+ *
+ * @param except
+ * The checked exception
+ */
+ public WrappedRuntimeException(Exception except) {
+ super(
+ except == null || except.getMessage() == null ? "No message available"
+ : except.getMessage());
+
+ if (except instanceof WrappedRuntimeException
+ && ((WrappedRuntimeException) except)._except != null) {
+ _except = ((WrappedRuntimeException) except)._except;
+ } else {
+ _except = except;
+ }
+ }
+
+ /**
+ * Returns the exception wrapped by this runtime exception.
+ *
+ * @return The exception wrapped by this runtime exception
+ */
+ public Exception getException() {
+ return _except;
+ }
+
+ @Override
+ public void printStackTrace() {
+ if (_except == null) {
+ super.printStackTrace();
+ } else {
+ _except.printStackTrace();
+ }
+ }
+
+ @Override
+ public void printStackTrace(PrintStream stream) {
+ if (_except == null) {
+ super.printStackTrace(stream);
+ } else {
+ _except.printStackTrace(stream);
+ }
+ }
+
+ @Override
+ public void printStackTrace(PrintWriter writer) {
+ if (_except == null) {
+ super.printStackTrace(writer);
+ } else {
+ _except.printStackTrace(writer);
}
+ }
}
-
-
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/util/jdbm/htree/HTree.java Thu Jan 21 10:37:58 2010
@@ -64,143 +64,127 @@
package org.apache.hadoop.hive.ql.util.jdbm.htree;
+import java.io.IOException;
+
import org.apache.hadoop.hive.ql.util.jdbm.RecordManager;
import org.apache.hadoop.hive.ql.util.jdbm.helper.FastIterator;
-import java.io.IOException;
/**
- * Persistent hashtable implementation for PageManager.
- * Implemented as an H*Tree structure.
- *
- * WARNING! If this instance is used in a transactional context, it
- * *must* be discarded after a rollback.
- *
- * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
- * @version $Id: HTree.java,v 1.3 2005/06/25 23:12:32 doomdark Exp $
+ * Persistent hashtable implementation for PageManager. Implemented as an H*Tree
+ * structure.
+ *
+ * WARNING! If this instance is used in a transactional context, it *must* be
+ * discarded after a rollback.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: HTree.java,v 1.3 2005/06/25 23:12:32 doomdark Exp $
*/
-public class HTree
-{
+public class HTree {
- /**
- * Root hash directory.
- */
- private HashDirectory _root;
-
-
- /**
- * Private constructor
- *
- * @param root Root hash directory.
- */
- private HTree( HashDirectory root ) {
- _root = root;
- }
-
-
- /**
- * Create a persistent hashtable.
- *
- * @param recman Record manager used for persistence.
- */
- public static HTree createInstance( RecordManager recman )
- throws IOException
- {
- HashDirectory root;
- long recid;
-
- root = new HashDirectory( (byte) 0 );
- recid = recman.insert( root );
- root.setPersistenceContext( recman, recid );
-
- return new HTree( root );
- }
-
-
- /**
- * Load a persistent hashtable
- *
- * @param recman RecordManager used to store the persistent hashtable
- * @param root_recid Record id of the root directory of the HTree
- */
- public static HTree load( RecordManager recman, long root_recid )
- throws IOException
- {
- HTree tree;
- HashDirectory root;
-
- root = (HashDirectory) recman.fetch( root_recid );
- root.setPersistenceContext( recman, root_recid );
- tree = new HTree( root );
- return tree;
- }
-
-
- /**
- * Associates the specified value with the specified key.
- *
- * @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)
- throws IOException
- {
- _root.put(key, value);
- }
-
-
- /**
- * Returns the value which is associated with the given key. Returns
- * <code>null</code> if there is not association for this key.
- *
- * @param key key whose associated value is to be returned
- */
- public synchronized Object get(Object key)
- throws IOException
- {
- return _root.get(key);
- }
-
-
- /**
- * Remove the value which is associated with the given key. If the
- * key does not exist, this method simply ignores the operation.
- *
- * @param key key whose associated value is to be removed
- */
- public synchronized void remove(Object key)
- throws IOException
- {
- _root.remove(key);
- }
-
-
- /**
- * Returns an enumeration of the keys contained in this
- */
- public synchronized FastIterator keys()
- throws IOException
- {
- return _root.keys();
- }
-
-
- /**
- * Returns an enumeration of the values contained in this
- */
- public synchronized FastIterator values()
- throws IOException
- {
- return _root.values();
- }
-
-
- /**
- * Get the record identifier used to load this hashtable.
- */
- public long getRecid()
- {
- return _root.getRecid();
- }
+ /**
+ * Root hash directory.
+ */
+ private final HashDirectory _root;
+
+ /**
+ * Private constructor
+ *
+ * @param root
+ * Root hash directory.
+ */
+ private HTree(HashDirectory root) {
+ _root = root;
+ }
+
+ /**
+ * Create a persistent hashtable.
+ *
+ * @param recman
+ * Record manager used for persistence.
+ */
+ public static HTree createInstance(RecordManager recman) throws IOException {
+ HashDirectory root;
+ long recid;
+
+ root = new HashDirectory((byte) 0);
+ recid = recman.insert(root);
+ root.setPersistenceContext(recman, recid);
+
+ return new HTree(root);
+ }
+
+ /**
+ * Load a persistent hashtable
+ *
+ * @param recman
+ * RecordManager used to store the persistent hashtable
+ * @param root_recid
+ * Record id of the root directory of the HTree
+ */
+ public static HTree load(RecordManager recman, long root_recid)
+ throws IOException {
+ HTree tree;
+ HashDirectory root;
+
+ root = (HashDirectory) recman.fetch(root_recid);
+ root.setPersistenceContext(recman, root_recid);
+ tree = new HTree(root);
+ return tree;
+ }
+
+ /**
+ * Associates the specified value with the specified key.
+ *
+ * @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) throws IOException {
+ _root.put(key, value);
+ }
+
+ /**
+ * Returns the value which is associated with the given key. Returns
+ * <code>null</code> if there is not association for this key.
+ *
+ * @param key
+ * key whose associated value is to be returned
+ */
+ public synchronized Object get(Object key) throws IOException {
+ return _root.get(key);
+ }
+
+ /**
+ * Remove the value which is associated with the given key. If the key does
+ * not exist, this method simply ignores the operation.
+ *
+ * @param key
+ * key whose associated value is to be removed
+ */
+ public synchronized void remove(Object key) throws IOException {
+ _root.remove(key);
+ }
+
+ /**
+ * Returns an enumeration of the keys contained in this
+ */
+ public synchronized FastIterator keys() throws IOException {
+ return _root.keys();
+ }
+
+ /**
+ * Returns an enumeration of the values contained in this
+ */
+ public synchronized FastIterator values() throws IOException {
+ return _root.values();
+ }
+
+ /**
+ * Get the record identifier used to load this hashtable.
+ */
+ public long getRecid() {
+ return _root.getRecid();
+ }
}
-