Package com.tangosol.io.pof
Class SimplePofContext
- java.lang.Object
-
- com.tangosol.io.pof.SimplePofContext
-
- All Implemented Interfaces:
PofContext,Serializer
@Named("simple-pof") public class SimplePofContext extends Object implements PofContextBasicPofContextimplementation.- Since:
- Coherence 3.2
- Author:
- jh 2006.07.18
- See Also:
PortableObjectSerializer
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_fPreferJavaTimeTrue if Java 8 date/time types (java.time.*) should be preferred over legacy types.protected booleanm_fReferenceEnabledTrue if POF Identity/Reference type support is enabled.protected LongArraym_laClassA LongArray of user types, indexed by type identifier.protected LongArraym_laSerializerA LongArray of PofSerializer objects, indexed by type identifier.protected Mapm_mapTypeIdA Map that contains mappings from a registered user type into type identifier.
-
Constructor Summary
Constructors Constructor Description SimplePofContext()Create a new SimplePofContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectdeserialize(ReadBuffer.BufferInput in)Deserialize an object from a ReadBuffer by reading its state using the specified BufferInput object.ClassgetClass(int nTypeId)Determine the class associated with the given user type identifier.StringgetClassName(int nTypeId)Determine the name of the class associated with the given user type identifier.StringgetName()Return the name of this serializer.PofSerializergetPofSerializer(int nTypeId)Return a PofSerializer that can be used to serialize and deserialize an object of the specified user type to and from a POF stream.intgetUserTypeIdentifier(Class clz)Determine the user type identifier associated with the given class.intgetUserTypeIdentifier(Object o)Determine the user type identifier associated with the given object.intgetUserTypeIdentifier(String sClass)Determine the user type identifier associated with the given class name.booleanisPreferJavaTime()ReturntrueifPofReader.readObject(int)method should return the appropriate Java 8 date/time type, orfalseif a legacy date/time types should be returned in order to preserve backwards compatibility.booleanisReferenceEnabled()Determine if Identity/Reference type support is enabled for this SimplePofContext.booleanisUserType(Class clz)Determine if the given class is a user type known to this PofContext.booleanisUserType(Object o)Determine if the given object is of a user type known to this PofContext.booleanisUserType(String sClass)Determine if the class with the given name is a user type known to this PofContext.<T> SimplePofContextregisterPortableType(Class<T> clz)RegisterPortableType.SimplePofContextregisterPortableTypes(Class<?>... aClz)Register multiplePortableTypes.<T> voidregisterUserType(int nTypeId, Class<T> clz, PofSerializer<T> serializer)Associate a user type with a type identifier andPofSerializer.voidserialize(WriteBuffer.BufferOutput out, Object o)Serialize an object to a WriteBuffer by writing its state using the specified BufferOutput object.voidsetPreferJavaTime(boolean fPreferJavaTime)Set the flag specifying if Java 8 date/time types (java.time.*) should be preferred over legacy types.voidsetReferenceEnabled(boolean fEnabled)Enable or disable POF Identity/Reference type support for this SimplePofContext.voidunregisterUserType(int nTypeId)Unregister a user type that was previously registered using the specified type identifier.protected voidvalidateTypeId(int nTypeId)Ensure that the given user type identifier is valid.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tangosol.io.Serializer
deserialize
-
-
-
-
Field Detail
-
m_mapTypeId
protected Map m_mapTypeId
A Map that contains mappings from a registered user type into type identifier.
-
m_laClass
protected LongArray m_laClass
A LongArray of user types, indexed by type identifier.
-
m_laSerializer
protected LongArray m_laSerializer
A LongArray of PofSerializer objects, indexed by type identifier.
-
m_fReferenceEnabled
protected boolean m_fReferenceEnabled
True if POF Identity/Reference type support is enabled.
-
m_fPreferJavaTime
protected boolean m_fPreferJavaTime
True if Java 8 date/time types (java.time.*) should be preferred over legacy types.
-
-
Method Detail
-
serialize
public void serialize(WriteBuffer.BufferOutput out, Object o) throws IOException
Serialize an object to a WriteBuffer by writing its state using the specified BufferOutput object.Note: Starting with Coherence 12.2.1 classes that need to designate an alternative object to be used by the Serializer when writing the object to the buffer should implement the
SerializationSupport.writeReplace()method.- Specified by:
serializein interfaceSerializer- Parameters:
out- the BufferOutput with which to write the object's stateo- the object to serialize- Throws:
IOException- if an I/O error occurs
-
deserialize
public Object deserialize(ReadBuffer.BufferInput in) throws IOException
Deserialize an object from a ReadBuffer by reading its state using the specified BufferInput object.Note: Starting with Coherence 12.2.1 classes that need to designate an alternative object to be returned by the Serializer after an object is deserialized from the buffer should implement the
SerializationSupport.readResolve()method.- Specified by:
deserializein interfaceSerializer- Parameters:
in- the BufferInput with which to read the object's state- Returns:
- the deserialized user type instance
- Throws:
IOException- if an I/O error occurs
-
getName
public String getName()
Description copied from interface:SerializerReturn the name of this serializer.- Specified by:
getNamein interfaceSerializer- Returns:
- the name of this serializer
-
getPofSerializer
public PofSerializer getPofSerializer(int nTypeId)
Return a PofSerializer that can be used to serialize and deserialize an object of the specified user type to and from a POF stream.- Specified by:
getPofSerializerin interfacePofContext- Parameters:
nTypeId- the type identifier of the user type that can be serialized and deserialized using the returned PofSerializer; must be non-negative- Returns:
- a PofSerializer for the specified user type
-
getUserTypeIdentifier
public int getUserTypeIdentifier(Object o)
Determine the user type identifier associated with the given object.- Specified by:
getUserTypeIdentifierin interfacePofContext- Parameters:
o- an instance of a user type; must not be null- Returns:
- the type identifier of the user type associated with the given object
-
getUserTypeIdentifier
public int getUserTypeIdentifier(Class clz)
Determine the user type identifier associated with the given class.- Specified by:
getUserTypeIdentifierin interfacePofContext- Parameters:
clz- a user type class; must not be null- Returns:
- the type identifier of the user type associated with the given class
-
getUserTypeIdentifier
public int getUserTypeIdentifier(String sClass)
Determine the user type identifier associated with the given class name.- Specified by:
getUserTypeIdentifierin interfacePofContext- Parameters:
sClass- the name of a user type class; must not be null- Returns:
- the type identifier of the user type associated with the given class name
-
getClassName
public String getClassName(int nTypeId)
Determine the name of the class associated with the given user type identifier.- Specified by:
getClassNamein interfacePofContext- Parameters:
nTypeId- the user type identifier; must be non-negative- Returns:
- the name of the class associated with the specified user type identifier
-
getClass
public Class getClass(int nTypeId)
Determine the class associated with the given user type identifier.- Specified by:
getClassin interfacePofContext- Parameters:
nTypeId- the user type identifier; must be non-negative- Returns:
- the class associated with the specified user type identifier
-
isUserType
public boolean isUserType(Object o)
Determine if the given object is of a user type known to this PofContext.- Specified by:
isUserTypein interfacePofContext- Parameters:
o- the object to test; must not be null- Returns:
- true iff the specified object is of a valid user type
-
isUserType
public boolean isUserType(Class clz)
Determine if the given class is a user type known to this PofContext.- Specified by:
isUserTypein interfacePofContext- Parameters:
clz- the class to test; must not be null- Returns:
- true iff the specified class is a valid user type
-
isUserType
public boolean isUserType(String sClass)
Determine if the class with the given name is a user type known to this PofContext.- Specified by:
isUserTypein interfacePofContext- Parameters:
sClass- the name of the class to test; must not be null- Returns:
- true iff the class with the specified name is a valid user type
-
isPreferJavaTime
public boolean isPreferJavaTime()
ReturntrueifPofReader.readObject(int)method should return the appropriate Java 8 date/time type, orfalseif a legacy date/time types should be returned in order to preserve backwards compatibility.- Specified by:
isPreferJavaTimein interfacePofContext- Returns:
trueif Java 8 date/time types should be preferred over legacy types
-
registerPortableType
public <T> SimplePofContext registerPortableType(Class<T> clz)
RegisterPortableType.- Parameters:
clz- the portable type to register with this PofContext; must not be null, and must be annotated withPortableTypeannotation- Throws:
IllegalArgumentException- on invalid type identifer, class, or PofSerializer
-
registerPortableTypes
public SimplePofContext registerPortableTypes(Class<?>... aClz)
Register multiplePortableTypes.- Parameters:
aClz- the array of portable types to register with this PofContext; each specified class must be annotated withPortableTypeannotation- Throws:
IllegalArgumentException- if any of the specified classes is not a validPortableType
-
registerUserType
public <T> void registerUserType(int nTypeId, Class<T> clz, PofSerializer<T> serializer)Associate a user type with a type identifier andPofSerializer.- Parameters:
nTypeId- the type identifier of the specified user type; must be greater or equal to 0clz- the user type to register with this PofContext; must not be nullserializer- the PofSerializer that will be used to serialize and deserialize objects of the specified class; must not be null- Throws:
IllegalArgumentException- on invalid type identifer, class, or PofSerializer
-
unregisterUserType
public void unregisterUserType(int nTypeId)
Unregister a user type that was previously registered using the specified type identifier.- Parameters:
nTypeId- the type identifier of the user type to unregister- Throws:
IllegalArgumentException- if the specified user type identifier is unknown to this PofContext
-
setPreferJavaTime
public void setPreferJavaTime(boolean fPreferJavaTime)
Set the flag specifying if Java 8 date/time types (java.time.*) should be preferred over legacy types.- Parameters:
fPreferJavaTime- whether Java 8 date/time types should be
-
validateTypeId
protected void validateTypeId(int nTypeId)
Ensure that the given user type identifier is valid.- Parameters:
nTypeId- the user type identifier to validate- Throws:
IllegalArgumentException- if the given user type identifier is negative
-
isReferenceEnabled
public boolean isReferenceEnabled()
Determine if Identity/Reference type support is enabled for this SimplePofContext.- Returns:
- true if Identity/Reference type support is enabled
-
setReferenceEnabled
public void setReferenceEnabled(boolean fEnabled)
Enable or disable POF Identity/Reference type support for this SimplePofContext.- Parameters:
fEnabled- true to enable POF Identity/Reference type support; false to disable
-
-