Class MultiplexingSerializer
- All Implemented Interfaces:
ClassLoaderAware
,Serializer
Serializer
implementation that multiplexes serialization/deserialization requests
across multiple Serializer
implementations.
More specifically, for serialization operations, the list of available Serializer
s are
iterated over. The first serializer that is able to serialize the object without error, will be
the Serializer
used for that type going forward.
All serialized payloads will be prefixed with the following header to enable deserialization.
+--------------+-------------------------+ | Length (4) | Serializer Name (1...) | +--------------+-------------------------+ | Serialized Payload (0...) | +----------------------------------------+Upon deserialization, the header will be read and the specified
Serializer
will be used
to deserialize the payload. If the header is no present, an IOException
will be thrown.- Since:
- 20.06
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static final class
Simple wrapper class to hold decorated info added by the serialization process. -
Field Summary
Modifier and TypeFieldDescriptionprotected final Map
<String, Serializer> The mapping ofSerializer
s keyed by their name.protected final ConcurrentMap
<String, Serializer> The mapping of types referenced by their String name and a workingSerializer
for that type.protected final Serializer[]
protected WeakReference
<ClassLoader> The optionalClassLoader
.protected static final String
Symbolic reference fornull
. -
Constructor Summary
ConstructorDescriptionMultiplexingSerializer
(Serializer... serializers) Construct a newSerializer
that will multiplex serialization operations across the provided list ofSerializer
s. -
Method Summary
Modifier and TypeMethodDescription<T> T
deserialize
(ReadBuffer.BufferInput in, Class<? extends T> clazz) Deserialize an object as an instance of the specified class by reading its state using the specified BufferInput object.protected void
doSerialization
(WriteBuffer.BufferOutput out, Object o, Serializer[] serializers) protected void
doWrite
(WriteBuffer.BufferOutput out, Object o, Serializer serializer) Writes the serialization header and payload.Retrieve the context ClassLoader for this object.getName()
Return the name of this serializer.protected void
logSerializationErrors
(Map<Serializer, Exception> serializerExceptionMap, String typeName) Given the provided mappings between aSerializer
and theException
it threw, log each mapping for diagnostic purposes.void
serialize
(WriteBuffer.BufferOutput out, Object o) Serialize an object to a WriteBuffer by writing its state using the specified BufferOutput object.void
setContextClassLoader
(ClassLoader loader) Specify the context ClassLoader for this object.toString()
protected int
writeSerializationHeader
(WriteBuffer.BufferOutput out, String serializerName) Write the multiplex serialization header.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.tangosol.io.Serializer
deserialize
-
Field Details
-
m_refLoader
The optionalClassLoader
. -
f_serializers
-
f_mapTypeToSerializer
The mapping of types referenced by their String name and a workingSerializer
for that type. -
f_idToSerializer
The mapping ofSerializer
s keyed by their name. -
NULL_TYPE
Symbolic reference fornull
.- See Also:
-
-
Constructor Details
-
MultiplexingSerializer
Construct a newSerializer
that will multiplex serialization operations across the provided list ofSerializer
s. It's important to keep in mind that the iteration order when performing serialization/deserialization operation is based on the order they are provided. This may have bearing on ordering decisions.- Throws:
IllegalArgumentException
- if noSerializer
s are provided, or if the any of the providedSerializer
s returnnull
fromSerializer.getName()
-
-
Method Details
-
serialize
Description copied from interface:Serializer
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:
serialize
in 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
Description copied from interface:Serializer
Deserialize an object as an instance of the specified class 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:
deserialize
in interfaceSerializer
- Type Parameters:
T
- the class to deserialize to- Parameters:
in
- the BufferInput with which to read the object's stateclazz
- the type of the object to deserialize- Returns:
- the deserialized user type instance
- Throws:
IOException
- if an I/O error occurs
-
getName
Description copied from interface:Serializer
Return the name of this serializer.- Specified by:
getName
in interfaceSerializer
- Returns:
- the name of this serializer
-
getContextClassLoader
Description copied from interface:ClassLoaderAware
Retrieve the context ClassLoader for this object. The context ClassLoader is provided by the creator of the object for use by the object when loading classes and resources.- Specified by:
getContextClassLoader
in interfaceClassLoaderAware
- Returns:
- the context ClassLoader for this object
- See Also:
-
setContextClassLoader
Description copied from interface:ClassLoaderAware
Specify the context ClassLoader for this object. The context ClassLoader can be set when the object is created, and allows the creator to provide the appropriate class loader to be used by the object when when loading classes and resources.- Specified by:
setContextClassLoader
in interfaceClassLoaderAware
- Parameters:
loader
- the context ClassLoader for this object
-
toString
-
doSerialization
protected void doSerialization(WriteBuffer.BufferOutput out, Object o, Serializer[] serializers) throws IOException - Parameters:
out
- theWriteBuffer.BufferOutput
to write too
- the object to serializeserializers
- theSerializer
s to attempt the serialization operation against- Throws:
IOException
- if an error occurs during serialization
-
doWrite
protected void doWrite(WriteBuffer.BufferOutput out, Object o, Serializer serializer) throws IOException Writes the serialization header and payload.- Parameters:
out
- theWriteBuffer.BufferOutput
to write too
- the object to serializeserializer
- theSerializer
to use- Throws:
IOException
- if an error occurs during serialization
-
logSerializationErrors
protected void logSerializationErrors(Map<Serializer, Exception> serializerExceptionMap, String typeName) Given the provided mappings between aSerializer
and theException
it threw, log each mapping for diagnostic purposes.- Parameters:
serializerExceptionMap
- a mapping between aSerializer
instance and theException
it threw for any given serialization operationtypeName
- The name of the type that produced the error.
-
writeSerializationHeader
protected int writeSerializationHeader(WriteBuffer.BufferOutput out, String serializerName) throws IOException Write the multiplex serialization header.+--------------+-------------------------+ | Length (4) | Serializer Name (1...) | +--------------+-------------------------+ | Serialized Payload (0...) | +----------------------------------------+
- Parameters:
out
- the stream to write toserializerName
- the name of theSerializer
- Throws:
IOException
- if an error occurs writing the header or payload- See Also:
-
readSerializationHeader
protected MultiplexingSerializer.SerializationHeader readSerializationHeader(ReadBuffer.BufferInput in) Read theMultiplexingSerializer.SerializationHeader
.+--------------+-------------------------+ | Length (4) | Serializer Name (1...) | +--------------+-------------------------+ | Serialized Payload (0...) | +----------------------------------------+
- Parameters:
in
- the stream to read from- Returns:
- the SerializationHeader if present and a matching
Serializer
is found, otherwise returnsnull
-