org.apache.hadoop.hbase.io
Class HbaseObjectWritable

java.lang.Object
  extended by org.apache.hadoop.hbase.io.HbaseObjectWritable
All Implemented Interfaces:
org.apache.hadoop.conf.Configurable, WritableWithSize, org.apache.hadoop.io.Writable

public class HbaseObjectWritable
extends Object
implements org.apache.hadoop.io.Writable, WritableWithSize, org.apache.hadoop.conf.Configurable

This is a customized version of the polymorphic hadoop ObjectWritable. It removes UTF8 (HADOOP-414). Using Text intead of UTF-8 saves ~2% CPU between reading and writing objects running a short sequentialWrite Performance Evaluation test just in ObjectWritable alone; more when we're doing randomRead-ing. Other optimizations include our passing codes for classes instead of the actual class names themselves. This makes it so this class needs amendment if non-Writable classes are introduced -- if passed a Writable for which we have no code, we just do the old-school passing of the class name, etc. -- but passing codes the savings are large particularly when cell data is small (If < a couple of kilobytes, the encoding/decoding of class name and reflection to instantiate class was costing in excess of the cell handling).


Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
HbaseObjectWritable()
          default constructor for writable
HbaseObjectWritable(Class<?> declaredClass, Object instance)
           
HbaseObjectWritable(Object instance)
           
 
Method Summary
 Object get()
           
 org.apache.hadoop.conf.Configuration getConf()
           
 Class<?> getDeclaredClass()
           
 long getWritableSize()
          Provide a size hint to the caller.
static long getWritableSize(Object instance, Class declaredClass, org.apache.hadoop.conf.Configuration conf)
           
 void readFields(DataInput in)
           
static Object readObject(DataInput in, org.apache.hadoop.conf.Configuration conf)
          Read a Writable, String, primitive type, or an array of the preceding.
static Object readObject(DataInput in, HbaseObjectWritable objectWritable, org.apache.hadoop.conf.Configuration conf)
          Read a Writable, String, primitive type, or an array of the preceding.
 void set(Object instance)
          Reset the instance.
 void setConf(org.apache.hadoop.conf.Configuration conf)
           
 String toString()
           
 void write(DataOutput out)
           
static void writeObject(DataOutput out, Object instance, Class declaredClass, org.apache.hadoop.conf.Configuration conf)
          Write a Writable, String, primitive type, or an array of the preceding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Constructor Detail

HbaseObjectWritable

public HbaseObjectWritable()
default constructor for writable


HbaseObjectWritable

public HbaseObjectWritable(Object instance)
Parameters:
instance -

HbaseObjectWritable

public HbaseObjectWritable(Class<?> declaredClass,
                           Object instance)
Parameters:
declaredClass -
instance -
Method Detail

get

public Object get()
Returns:
the instance, or null if none.

getDeclaredClass

public Class<?> getDeclaredClass()
Returns:
the class this is meant to be.

set

public void set(Object instance)
Reset the instance.

Parameters:
instance -

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException

getWritableSize

public long getWritableSize()
Description copied from interface: WritableWithSize
Provide a size hint to the caller. write() should ideally not go beyond this if at all possible. You can return 0 if there is no size hint.

Specified by:
getWritableSize in interface WritableWithSize
Returns:
the size of the writable

getWritableSize

public static long getWritableSize(Object instance,
                                   Class declaredClass,
                                   org.apache.hadoop.conf.Configuration conf)

writeObject

public static void writeObject(DataOutput out,
                               Object instance,
                               Class declaredClass,
                               org.apache.hadoop.conf.Configuration conf)
                        throws IOException
Write a Writable, String, primitive type, or an array of the preceding.

Parameters:
out -
instance -
declaredClass -
conf -
Throws:
IOException

readObject

public static Object readObject(DataInput in,
                                org.apache.hadoop.conf.Configuration conf)
                         throws IOException
Read a Writable, String, primitive type, or an array of the preceding.

Parameters:
in -
conf -
Returns:
the object
Throws:
IOException

readObject

public static Object readObject(DataInput in,
                                HbaseObjectWritable objectWritable,
                                org.apache.hadoop.conf.Configuration conf)
                         throws IOException
Read a Writable, String, primitive type, or an array of the preceding.

Parameters:
in -
objectWritable -
conf -
Returns:
the object
Throws:
IOException

setConf

public void setConf(org.apache.hadoop.conf.Configuration conf)
Specified by:
setConf in interface org.apache.hadoop.conf.Configurable

getConf

public org.apache.hadoop.conf.Configuration getConf()
Specified by:
getConf in interface org.apache.hadoop.conf.Configurable


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.