public abstract class CanonicalInstantiator extends Instantiator
CanonicalInstantiator
is much like its parent
Instantiator
except that instead of
needing to implement newInstance()
you now must implement newInstance(DataInput)
.
The addition of the DataInput
parameter allows the instance
creator to optionally read data from the data input stream and use it to
decide the instance to create. This allows a value that represents a
canonical instance to be written by a class's DataSerializer.toData(java.lang.Object, java.io.DataOutput)
and then be read by newInstance(DataInput)
and map it back to a canonical instance.
Note that DataSerializer.fromData(java.io.DataInput)
is always called on the instance
returned from newInstance(DataInput)
.
Constructor and Description |
---|
CanonicalInstantiator(Class<? extends DataSerializable> c,
int classId)
Creates a new
CanonicalInstantiator that instantiates a given
class. |
Modifier and Type | Method and Description |
---|---|
DataSerializable |
newInstance()
This method is not supported and if called will
throw UnsupportedOperationException.
|
abstract DataSerializable |
newInstance(DataInput in)
Creates a new "empty" instance of a
DataSerializable
class whose state will be filled in by invoking its
fromData method. |
getContext, getEventId, getId, getInstantiatedClass, register, register, setContext, setEventId
public CanonicalInstantiator(Class<? extends DataSerializable> c, int classId)
CanonicalInstantiator
that instantiates a given
class.c
- The DataSerializable
class to register. This
class must have a static initializer that registers this
Instantiator
.classId
- A unique id for class c
. The
classId
must not be zero.
This has been an int
since dsPhase1.IllegalArgumentException
- If c
does not implement
DataSerializable
, classId
is
less than or equal to zero.NullPointerException
- If c
is null
public final DataSerializable newInstance()
newInstance(DataInput)
instead.newInstance
in class Instantiator
UnsupportedOperationException
- in all casesDataSerializer.readObject(java.io.DataInput)
public abstract DataSerializable newInstance(DataInput in) throws IOException
DataSerializable
class whose state will be filled in by invoking its
fromData
method.in
- the data input that can be read to decide what instance to create.IOException
- if a read from in
fails.Copyright © 1997-2017 Pivotal Software, Inc. All rights reserved.