public class PersistenceMarshallerImpl extends Object implements PersistenceMarshaller
PersistenceMarshaller
implementation that is responsible
for marshalling/unmarshalling objects which are to be persisted.
Known internal objects that are required by stores and loaders, such as EmbeddedMetadata
,
are registered with this marshaller's SerializationContext
so that they can be natively marshalled by the
underlying Protostream marshaller. If no entry exists in the SerializationContext
for a given object, then
the marshalling of said object is delegated to a user marshaller if configured
(SerializationConfiguration.MARSHALLER
) and the generated bytes are wrapped
in a MarshallableUserObject
object and marshalled by ProtoStream.
Constructor and Description |
---|
PersistenceMarshallerImpl() |
Modifier and Type | Method and Description |
---|---|
BufferSizePredictor |
getBufferSizePredictor(Object o)
Returns a marshalled payload size predictor for a particular type.
|
org.infinispan.protostream.ImmutableSerializationContext |
getSerializationContext() |
Marshaller |
getUserMarshaller() |
boolean |
isMarshallable(Object o)
A method that checks whether the given object is marshallable as per the rules of this marshaller.
|
MediaType |
mediaType() |
Object |
objectFromByteBuffer(byte[] buf)
Unmarshalls an object from a byte array.
|
Object |
objectFromByteBuffer(byte[] buf,
int offset,
int length)
Unmarshalls an object from a specific portion of a byte array.
|
ByteBuffer |
objectToBuffer(Object o)
A method that returns an instance of
ByteBuffer , which allows direct access to the byte
array with minimal array copying |
byte[] |
objectToByteBuffer(Object obj)
Marshalls an object to a byte array.
|
byte[] |
objectToByteBuffer(Object obj,
int estimatedSize)
Marshalls an object to a byte array.
|
Object |
readObject(InputStream in)
Unmarshall an object from the
InputStream |
void |
register(org.infinispan.protostream.SerializationContextInitializer initializer)
Registers the schemas and marshallers defined by the provided
SerializationContextInitializer with the
PersistenceMarshaller 's SerializationContext . |
int |
sizeEstimate(Object o)
An method that provides an estimate of the buffer size that will be required once the object has been marshalled.
|
void |
start()
Perform any initialization required before the marshaller is used.
|
void |
stop()
Stop the marshaller.
|
void |
writeObject(Object o,
OutputStream out)
Marshall an object to the
OutputStream |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initialize
public org.infinispan.protostream.ImmutableSerializationContext getSerializationContext()
public void start()
Marshaller
start
in interface Marshaller
public Marshaller getUserMarshaller()
getUserMarshaller
in interface PersistenceMarshaller
SerializationContext
if one exists, otherwise the default
ProtoStream based marshaller is returned.public void register(org.infinispan.protostream.SerializationContextInitializer initializer)
PersistenceMarshaller
SerializationContextInitializer
with the
PersistenceMarshaller
's SerializationContext
.register
in interface PersistenceMarshaller
initializer
- whose schemas and marshallers' will be registered with the PersistenceMarshaller
SerializationContext
public void stop()
Marshaller
stop
in interface Marshaller
public MediaType mediaType()
mediaType
in interface Marshaller
mediaType
in interface StreamAwareMarshaller
MediaType
associated with the content produced by the marshallerpublic ByteBuffer objectToBuffer(Object o)
Marshaller
ByteBuffer
, which allows direct access to the byte
array with minimal array copyingobjectToBuffer
in interface Marshaller
o
- object to marshallpublic byte[] objectToByteBuffer(Object obj, int estimatedSize)
Marshaller
objectToByteBuffer
in interface Marshaller
obj
- object to convert to a byte array. Must not be null.estimatedSize
- an estimate of how large the resulting byte array may bepublic byte[] objectToByteBuffer(Object obj)
Marshaller
objectToByteBuffer
in interface Marshaller
obj
- object to convert to a byte array. Must not be null.public Object objectFromByteBuffer(byte[] buf) throws IOException
Marshaller
objectFromByteBuffer
in interface Marshaller
buf
- byte array containing the binary representation of an object. Must not be null.IOException
- if unmarshalling cannot complete due to some I/O errorpublic Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException
Marshaller
objectFromByteBuffer
in interface Marshaller
buf
- byte array containing the binary representation of an object. Must not be null.offset
- point in buffer to start readinglength
- number of bytes to considerIOException
- if unmarshalling cannot complete due to some I/O errorpublic BufferSizePredictor getBufferSizePredictor(Object o)
Marshaller
getBufferSizePredictor
in interface Marshaller
o
- Object for which serialized predictor will be returnedBufferSizePredictor
public void writeObject(Object o, OutputStream out) throws IOException
StreamAwareMarshaller
OutputStream
writeObject
in interface StreamAwareMarshaller
o
- the object to write to the OutputStream
out
- the OutputStream
to write the object toIOException
- if the object cannot be marshalled to the OutputStream
due to some I/O errorpublic Object readObject(InputStream in) throws ClassNotFoundException, IOException
StreamAwareMarshaller
InputStream
readObject
in interface StreamAwareMarshaller
in
- the InputStream
to unmarshall an object fromClassNotFoundException
- if the class of the object trying to unmarshall is not foundIOException
- if unmarshalling cannot complete due to some I/O errorpublic boolean isMarshallable(Object o)
Marshaller
isMarshallable
in interface Marshaller
isMarshallable
in interface StreamAwareMarshaller
o
- object to verify whether it's marshallable or notpublic int sizeEstimate(Object o)
StreamAwareMarshaller
sizeEstimate
in interface StreamAwareMarshaller
o
- instance that will be stored in the buffer.Copyright © 2021 JBoss by Red Hat. All rights reserved.