Package org.apache.geode
Class CanonicalInstantiator
java.lang.Object
org.apache.geode.Instantiator
org.apache.geode.CanonicalInstantiator
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).
- Since:
- GemFire 5.1
-
Constructor Summary
ConstructorsConstructorDescriptionCanonicalInstantiator(Class<? extends DataSerializable> c, int classId) Creates a newCanonicalInstantiatorthat instantiates a given class. -
Method Summary
Modifier and TypeMethodDescriptionThis method is not supported and if called will throw UnsupportedOperationException.abstract DataSerializablenewInstance(DataInput in) Creates a new "empty" instance of aDataSerializableclass whose state will be filled in by invoking itsfromDatamethod.Methods inherited from class org.apache.geode.Instantiator
getContext, getEventId, getId, getInstantiatedClass, register, register, setContext, setEventId
-
Constructor Details
-
CanonicalInstantiator
Creates a newCanonicalInstantiatorthat instantiates a given class.- Parameters:
c- TheDataSerializableclass to register. This class must have a static initializer that registers thisInstantiator.classId- A unique id for classc. TheclassIdmust not be zero. This has been anintsince dsPhase1.- Throws:
IllegalArgumentException- Ifcdoes not implementDataSerializable,classIdis less than or equal to zero.NullPointerException- Ifcisnull
-
-
Method Details
-
newInstance
This method is not supported and if called will throw UnsupportedOperationException. UsenewInstance(DataInput)instead.- Specified by:
newInstancein classInstantiator- Returns:
- a new "empty" instance of a
DataSerializableclass - Throws:
UnsupportedOperationException- in all cases- See Also:
-
newInstance
Creates a new "empty" instance of aDataSerializableclass whose state will be filled in by invoking itsfromDatamethod.- Parameters:
in- the data input that can be read to decide what instance to create.- Returns:
- the new "empty" instance.
- Throws:
IOException- if a read frominfails.- Since:
- GemFire 5.1
-