public abstract class GenericWritable extends Object implements Writable, Configurable
When two sequence files, which have same Key type but different Value types, are mapped out to reduce, multiple Value types is not allowed. In this case, this class can help you wrap instances with different types.
Compared with ObjectWritable
, this class is much more effective,
because ObjectWritable
will append the class declaration as a String
into the output file in every Key-Value pair.
Generic Writable implements Configurable
interface, so that it will be
configured by the framework. The configuration is passed to the wrapped objects
implementing Configurable
interface before deserialization.
getTypes()
, defines
the classes which will be wrapped in GenericObject in application.
Attention: this classes defined in getTypes()
method, must
implement Writable
interface.
public class GenericObject extends GenericWritable { private static Class[] CLASSES = { ClassType1.class, ClassType2.class, ClassType3.class, }; protected Class[] getTypes() { return CLASSES; } }
构造器和说明 |
---|
GenericWritable() |
限定符和类型 | 方法和说明 |
---|---|
Writable |
get()
Return the wrapped instance.
|
Configuration |
getConf()
Return the configuration used by this object.
|
protected abstract Class<? extends Writable>[] |
getTypes()
Return all classes that may be wrapped.
|
void |
readFields(DataInput in)
Deserialize the fields of this object from
in . |
void |
set(Writable obj)
Set the instance that is wrapped.
|
void |
setConf(Configuration conf)
Set the configuration to be used by this object.
|
String |
toString() |
void |
write(DataOutput out)
Serialize the fields of this object to
out . |
public void set(Writable obj)
obj
- public Writable get()
public void readFields(DataInput in) throws IOException
Writable
in
.
For efficiency, implementations should attempt to re-use storage in the existing object where possible.
readFields
在接口中 Writable
in
- DataInput
to deseriablize this object from.IOException
public void write(DataOutput out) throws IOException
Writable
out
.write
在接口中 Writable
out
- DataOuput
to serialize this object into.IOException
protected abstract Class<? extends Writable>[] getTypes()
public Configuration getConf()
Configurable
getConf
在接口中 Configurable
public void setConf(Configuration conf)
Configurable
setConf
在接口中 Configurable
Copyright © 2009 The Apache Software Foundation