You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/02/26 19:17:46 UTC
svn commit: r748256 - in /hadoop/hbase/trunk: CHANGES.txt
src/java/org/apache/hadoop/hbase/io/CodeToClassAndBack.java
src/java/org/apache/hadoop/hbase/io/HbaseMapWritable.java
Author: stack
Date: Thu Feb 26 18:17:46 2009
New Revision: 748256
URL: http://svn.apache.org/viewvc?rev=748256&view=rev
Log:
HBASE-1189 Changing the map type used internally for HbaseMapWritable
Added:
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/CodeToClassAndBack.java
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseMapWritable.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=748256&r1=748255&r2=748256&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Feb 26 18:17:46 2009
@@ -61,6 +61,8 @@
(Lars George via Stack)
HBASE-1221 When using ant -projecthelp to build HBase not all the important
options show up (Erik Holstad via Stack)
+ HBASE-1189 Changing the map type used internally for HbaseMapWritable
+ (Erik Holstad via Stack)
Release 0.19.0 - 01/21/2009
INCOMPATIBLE CHANGES
Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/CodeToClassAndBack.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/CodeToClassAndBack.java?rev=748256&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/CodeToClassAndBack.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/CodeToClassAndBack.java Thu Feb 26 18:17:46 2009
@@ -0,0 +1,71 @@
+/**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.io;
+
+import java.util.*;
+
+/**
+ * A Static Interface.
+ * Instead of having this code in the the HbaseMapWritable code, where it
+ * blocks the possibility of altering the variables and changing their types,
+ * it is put here in this static interface where the static final Maps are
+ * loaded one time. Only byte[] and Cell are supported at this time.
+ */
+public interface CodeToClassAndBack {
+ /**
+ * Static map that contains mapping from code to class
+ */
+ public static final Map<Byte, Class<?>> CODE_TO_CLASS =
+ new HashMap<Byte, Class<?>>();
+
+ /**
+ * Static map that contains mapping from class to code
+ */
+ public static final Map<Class<?>, Byte> CLASS_TO_CODE =
+ new HashMap<Class<?>, Byte>();
+
+ /**
+ * Class list for supported classes
+ */
+ public Class[] classList = {byte[].class, Cell.class};
+
+ /**
+ * The static loader that is used instead of the static constructor in
+ * HbaseMapWritable.
+ */
+ public InternalStaticLoader sl =
+ new InternalStaticLoader(classList, CODE_TO_CLASS, CLASS_TO_CODE);
+
+ /**
+ * Class that loads the static maps with their values.
+ */
+ public class InternalStaticLoader{
+ InternalStaticLoader(Class[] classList, Map<Byte, Class<?>> CODE_TO_CLASS,
+ Map<Class<?>, Byte> CLASS_TO_CODE){
+ byte code = 1;
+ for(int i=0; i<classList.length; i++){
+ CLASS_TO_CODE.put(classList[i], code);
+ CODE_TO_CLASS.put(code, classList[i]);
+ code++;
+ }
+ }
+ }
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseMapWritable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseMapWritable.java?rev=748256&r1=748255&r2=748256&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseMapWritable.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseMapWritable.java Thu Feb 26 18:17:46 2009
@@ -24,7 +24,6 @@
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
@@ -33,9 +32,7 @@
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HStoreKey;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.util.ReflectionUtils;
@@ -48,37 +45,45 @@
* @param <K> <byte []> key TODO: Parameter K is never used, could be removed.
* @param <V> value Expects a Writable or byte [].
*/
-public class HbaseMapWritable <K, V>
-implements SortedMap<byte [], V>, Writable, Configurable {
- private AtomicReference<Configuration> conf =
- new AtomicReference<Configuration>();
+public class HbaseMapWritable <K,V>
+implements SortedMap<byte[],V>, Configurable, Writable,
+ CodeToClassAndBack{
+
+ private AtomicReference<Configuration> conf = null;
+ protected SortedMap<byte [], V> instance = null;
// Static maps of code to class and vice versa. Includes types used in hbase
- // only.
- static final Map<Byte, Class<?>> CODE_TO_CLASS =
- new HashMap<Byte, Class<?>>();
- static final Map<Class<?>, Byte> CLASS_TO_CODE =
- new HashMap<Class<?>, Byte>();
-
- static {
- byte code = 0;
- addToMap(HStoreKey.class, code++);
- addToMap(ImmutableBytesWritable.class, code++);
- addToMap(Text.class, code++);
- addToMap(Cell.class, code++);
- addToMap(byte [].class, code++);
- }
-
- @SuppressWarnings("boxing")
- private static void addToMap(final Class<?> clazz,
- final byte code) {
- CLASS_TO_CODE.put(clazz, code);
- CODE_TO_CLASS.put(code, clazz);
+ // only. These maps are now initialized in a static loader interface instead
+ // of in a static contructor for this class, this is done so that it is
+ // possible to have a regular contructor here, so that different params can
+ // be used.
+
+ // Removed the old types like Text from the maps, if needed to add more types
+ // this can be done in the StaticHBaseMapWritableLoader interface. Only
+ // byte[] and Cell are supported now.
+ // static final Map<Byte, Class<?>> CODE_TO_CLASS =
+ // new HashMap<Byte, Class<?>>();
+ // static final Map<Class<?>, Byte> CLASS_TO_CODE =
+ // new HashMap<Class<?>, Byte>();
+
+ /**
+ * The default contructor where a TreeMap is used
+ **/
+ public HbaseMapWritable(){
+ this (new TreeMap<byte [], V>(Bytes.BYTES_COMPARATOR));
+ }
+
+ /**
+ * Contructor where another SortedMap can be used
+ *
+ * @param map the SortedMap to be used
+ **/
+ public HbaseMapWritable(SortedMap<byte[], V> map){
+ conf = new AtomicReference<Configuration>();
+ instance = map;
}
- private SortedMap<byte [], V> instance =
- new TreeMap<byte [], V>(Bytes.BYTES_COMPARATOR);
-
+
/** @return the conf */
public Configuration getConf() {
return conf.get();
@@ -228,4 +233,4 @@
this.instance.put(key, value);
}
}
-}
\ No newline at end of file
+}