Class GlobalMarshaller
- All Implemented Interfaces:
Marshaller,StreamingMarshaller
- Since:
- 5.0
- Author:
- Galder ZamarreƱo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Externalizer<T>voidFinish using the given ObjectInput.voidFinish using the given ObjectOutput.Returns a marshalled payload size predictor for a particular type.static AdvancedExternalizergetExternalExternalizer(GlobalMarshaller gm, Class<?> clazz) static AdvancedExternalizergetInteralExternalizer(GlobalMarshaller gm, Class<?> clazz) booleanA 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[] bytes, int offset, int len) Unmarshalls an object from a specific portion of a byte array.Unmarshall an object from anInputStreamUnmarshalls an object from anObjectInputA 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.voidobjectToObjectStream(Object obj, ObjectOutput out) Marshalls an object to a givenObjectOutputstatic Objectvoidstart()Perform any initialization required before the marshaller is used.startObjectInput(InputStream is, boolean isReentrant) Create and open a new ObjectInput for the given input stream.startObjectOutput(OutputStream os, boolean isReentrant, int estimatedSize) Create and open an ObjectOutput instance for the given output stream.voidstop()Stop the marshaller.static voidwriteExternalClean(Object obj, AdvancedExternalizer ext, ObjectOutput out) static voidwriteInternalClean(Object obj, AdvancedExternalizer ext, ObjectOutput out) static voidwriteUnknown(Marshaller marshaller, Object obj, ObjectOutput out) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.infinispan.commons.marshall.Marshaller
initialize
-
Field Details
-
NOT_FOUND
public static final int NOT_FOUND- See Also:
-
ID_NULL
public static final int ID_NULL- See Also:
-
ID_PRIMITIVE
public static final int ID_PRIMITIVE- See Also:
-
ID_INTERNAL
public static final int ID_INTERNAL- See Also:
-
ID_EXTERNAL
public static final int ID_EXTERNAL- See Also:
-
ID_ANNOTATED
public static final int ID_ANNOTATED- See Also:
-
ID_UNKNOWN
public static final int ID_UNKNOWN- See Also:
-
-
Constructor Details
-
GlobalMarshaller
public GlobalMarshaller()
-
-
Method Details
-
start
public void start()Description copied from interface:MarshallerPerform any initialization required before the marshaller is used.- Specified by:
startin interfaceMarshaller- Specified by:
startin interfaceStreamingMarshaller
-
stop
public void stop()Description copied from interface:StreamingMarshallerStop 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.- Specified by:
stopin interfaceMarshaller- Specified by:
stopin interfaceStreamingMarshaller
-
getPersistenceMarshaller
-
objectToByteBuffer
Description copied from interface:MarshallerMarshalls an object to a byte array.- Specified by:
objectToByteBufferin interfaceMarshaller- 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
Description copied from interface:MarshallerUnmarshalls an object from a byte array.- Specified by:
objectFromByteBufferin interfaceMarshaller- 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
-
startObjectOutput
public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant, int estimatedSize) throws IOException Description copied from interface:StreamingMarshallerCreate and open an ObjectOutput instance for the given output stream. This method should be used for opening data outputs when multiple objectToObjectStream() calls will be made before the stream is closed by calling finishObjectOutput().
This method also takes a boolean that represents whether this particular call to startObjectOutput() is reentrant or not. A call to startObjectOutput() should be marked reentrant whenever a 2nd or more calls to this method are made without having called finishObjectOutput() first.
To potentially speed up calling startObjectOutput multiple times in a non-reentrant way, i.e. startObjectOutput/finishObjectOutput...startObjectOutput/finishObjectOutput...etc, which is is the most common case, the StreamingMarshaller implementation could potentially use some mechanisms to speed up this startObjectOutput call.
On the other hand, when a call is reentrant, i.e. startObjectOutput/startObjectOutput(reentrant)...finishObjectOutput/finishObjectOutput, the StreamingMarshaller implementation might treat it differently. An example of reentrancy would be marshalling of MarshalledValue. When sending or storing a MarshalledValue, a call to startObjectOutput() would occur so that the stream is open and following, a 2nd call could occur so that MarshalledValue's raw byte array version is calculated and sent across. This enables storing as binary on the receiver side which is performance gain. The StreamingMarshaller implementation could decide that it needs a separate ObjectOutput or similar for the 2nd call since it's aim is only to get the raw byte array version and the close finish with it.
- Specified by:
startObjectOutputin interfaceStreamingMarshaller- Parameters:
os- output streamisReentrant- whether the call is reentrant or not.estimatedSize- estimated size in bytes of the output. Only meant as a possible performance optimization.- Returns:
- ObjectOutput to write to
- Throws:
IOException
-
objectToObjectStream
Description copied from interface:StreamingMarshallerMarshalls an object to a givenObjectOutput- Specified by:
objectToObjectStreamin interfaceStreamingMarshaller- Parameters:
obj- object to marshallout- stream to marshall to- Throws:
IOException
-
finishObjectOutput
Description copied from interface:StreamingMarshallerFinish using the given ObjectOutput. After opening a ObjectOutput and calling objectToObjectStream() multiple times, use this method to flush the data and close if necessary- Specified by:
finishObjectOutputin interfaceStreamingMarshaller- Parameters:
oo- data output that finished using
-
objectFromByteBuffer
public Object objectFromByteBuffer(byte[] bytes, int offset, int len) throws IOException, ClassNotFoundException Description copied from interface:MarshallerUnmarshalls an object from a specific portion of a byte array.- Specified by:
objectFromByteBufferin interfaceMarshaller- Parameters:
bytes- byte array containing the binary representation of an object. Must not be null.offset- point in buffer to start readinglen- 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
-
objectFromInputStream
Description copied from interface:StreamingMarshallerUnmarshall an object from anInputStream- Specified by:
objectFromInputStreamin interfaceStreamingMarshaller- Parameters:
is- stream to unmarshall from- Returns:
- the unmarshalled object instance
- Throws:
IOException- if unmarshalling cannot complete due to some I/O errorClassNotFoundException- if the class of the object trying to unmarshall is unknown
-
isMarshallable
Description copied from interface:MarshallerA method that checks whether the given object is marshallable as per the rules of this marshaller.- Specified by:
isMarshallablein interfaceMarshaller- 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
Description copied from interface:MarshallerReturns 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.- Specified by:
getBufferSizePredictorin interfaceMarshaller- Parameters:
o- Object for which serialized predictor will be returned- Returns:
- an instance of
BufferSizePredictor
-
mediaType
- Specified by:
mediaTypein interfaceMarshaller- Returns:
- the
MediaTypeassociated with the content produced by the marshaller
-
objectToBuffer
Description copied from interface:MarshallerA method that returns an instance ofByteBuffer, which allows direct access to the byte array with minimal array copying- Specified by:
objectToBufferin interfaceMarshaller- 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.
-
objectToByteBuffer
public byte[] objectToByteBuffer(Object obj, int estimatedSize) throws IOException, InterruptedException Description copied from interface:MarshallerMarshalls 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.- Specified by:
objectToByteBufferin interfaceMarshaller- 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.
-
startObjectInput
Description copied from interface:StreamingMarshallerCreate and open a new ObjectInput for the given input stream. This method should be used for opening data inputs when multiple objectFromObjectStream() calls will be made before the stream is closed.
This method also takes a boolean that represents whether this particular call to startObjectInput() is reentrant or not. A call to startObjectInput() should be marked reentrant whenever a 2nd or more calls to this method are made without having called finishObjectInput() first.
To potentially speed up calling startObjectInput multiple times in a non-reentrant way, i.e. startObjectInput/finishObjectInput...startObjectInput/finishObjectInput...etc, which is is the most common case, the StreamingMarshaller implementation could potentially use some mechanisms to speed up this startObjectInput call.
- Specified by:
startObjectInputin interfaceStreamingMarshaller- Parameters:
is- input streamisReentrant- whether the call is reentrant or not.- Returns:
- ObjectInput to read from
-
finishObjectInput
Description copied from interface:StreamingMarshallerFinish using the given ObjectInput. After opening a ObjectInput and calling objectFromObjectStream() multiple times, use this method to flush the data and close if necessary- Specified by:
finishObjectInputin interfaceStreamingMarshaller- Parameters:
oi- data input that finished using
-
objectFromObjectStream
Description copied from interface:StreamingMarshallerUnmarshalls an object from anObjectInput- Specified by:
objectFromObjectStreamin interfaceStreamingMarshaller- Parameters:
in- stream to unmarshall from
-
findExternalizerFor
-
getInteralExternalizer
-
getExternalExternalizer
-
readObjectFromObjectInput
public static Object readObjectFromObjectInput(GlobalMarshaller gm, ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeUnknown
public static void writeUnknown(Marshaller marshaller, Object obj, ObjectOutput out) throws IOException - Throws:
IOException
-
writeInternalClean
-
writeExternalClean
-