Package org.infinispan.commons.marshall
Interface Marshaller
- All Known Subinterfaces:
PersistenceMarshaller
,StreamingMarshaller
- All Known Implementing Classes:
AbstractJBossMarshaller
,AbstractMarshaller
,BytesOnlyMarshaller
,GenericJBossMarshaller
,GlobalMarshaller
,HotRodEntryMarshaller
,IdentityMarshaller
,ImmutableProtoStreamMarshaller
,JavaSerializationMarshaller
,JBossMarshaller
,JBossUserMarshaller
,ProtoStreamMarshaller
,ProtoStreamMarshaller
,StringMarshaller
,UTF8StringMarshaller
@ThreadSafe
public interface Marshaller
A marshaller is a class that is able to marshall and unmarshall objects efficiently.
This interface is used to marshall
ReplicableCommand
s, their parameters and their
response values, as well as any other arbitrary Object ↔ byte[] conversions, such as those used in client/server
communications.
A single instance of any implementation is shared by multiple threads, so implementations need to be threadsafe,
and preferably immutable.- Version:
- 4.1
- Author:
- Manik Surtani
-
Method Summary
Modifier and TypeMethodDescriptionReturns a marshalled payload size predictor for a particular type.default void
initialize
(ClassAllowList classAllowList) An optional method which allows an implementation to respect theClassAllowList
associated with the context, for example the EmbeddedCacheManager or RemoteCacheManager.boolean
A method that checks whether the given object is marshallable as per the rules of this marshaller.objectFromByteBuffer
(byte[] buf) Unmarshalls an object from a byte array.objectFromByteBuffer
(byte[] buf, int offset, int length) Unmarshalls an object from a specific portion of a byte array.A method that returns an instance ofByteBuffer
, which allows direct access to the byte array with minimal array copyingbyte[]
objectToByteBuffer
(Object obj) Marshalls an object to a byte array.byte[]
objectToByteBuffer
(Object obj, int estimatedSize) Marshalls an object to a byte array.default void
start()
Perform any initialization required before the marshaller is used.default void
stop()
Stop the marshaller.
-
Method Details
-
initialize
An optional method which allows an implementation to respect theClassAllowList
associated with the context, for example the EmbeddedCacheManager or RemoteCacheManager. -
objectToByteBuffer
Marshalls an object to a byte array. The estimatedSize parameter is a hint that can be passed in to allow for efficient sizing of the byte array before attempting to marshall the object. The more accurate this estimate is, the less likely byte[]s will need to be resized to hold the byte stream generated by marshalling the object.- Parameters:
obj
- object to convert to a byte array. Must not be null.estimatedSize
- an estimate of how large the resulting byte array may be- Returns:
- a byte array with the marshalled form of the object
- Throws:
IOException
- if marshalling cannot complete due to some I/O errorInterruptedException
- if the marshalling was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more unmarshalling should be attempted.
-
objectToByteBuffer
Marshalls an object to a byte array.- Parameters:
obj
- object to convert to a byte array. Must not be null.- Returns:
- a byte array
- Throws:
IOException
- if marshalling cannot complete due to some I/O errorInterruptedException
- if the marshalling process was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more marshalling should be attempted.
-
objectFromByteBuffer
Unmarshalls an object from a byte array.- Parameters:
buf
- byte array containing the binary representation of an object. Must not be null.- Returns:
- an object
- Throws:
IOException
- if unmarshalling cannot complete due to some I/O errorClassNotFoundException
- if the class of the object trying to unmarshall is unknown
-
objectFromByteBuffer
Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException Unmarshalls an object from a specific portion of a byte array.- Parameters:
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 consider- Returns:
- an object
- Throws:
IOException
- if unmarshalling cannot complete due to some I/O errorClassNotFoundException
- if the class of the object trying to unmarshall is unknown
-
objectToBuffer
A method that returns an instance ofByteBuffer
, which allows direct access to the byte array with minimal array copying- Parameters:
o
- object to marshall- Throws:
IOException
- if marshalling cannot complete due to some I/O errorInterruptedException
- if the marshalling process was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more marshalling should be attempted.
-
isMarshallable
A method that checks whether the given object is marshallable as per the rules of this marshaller.- Parameters:
o
- object to verify whether it's marshallable or not- Returns:
- true if the object is marshallable, otherwise false
- Throws:
Exception
- if while checking whether the object was serializable or not, an exception arose
-
getBufferSizePredictor
Returns a marshalled payload size predictor for a particular type. Accurate prediction of a type's serialized payload size helps avoid unnecessary copying and speeds up application performance.- Parameters:
o
- Object for which serialized predictor will be returned- Returns:
- an instance of
BufferSizePredictor
- Throws:
NullPointerException
- if o is null
-
mediaType
MediaType mediaType()- Returns:
- the
MediaType
associated with the content produced by the marshaller
-
start
default void start()Perform any initialization required before the marshaller is used. -
stop
default void stop()Stop the marshaller. Implementations of this method should clear up any cached data, or close any resources while marshalling/unmarshalling that have not been already closed.
-