public abstract class AbstractDelegatingMarshaller extends java.lang.Object implements StreamingMarshaller
Modifier and Type | Field and Description |
---|---|
protected StreamingMarshaller |
marshaller |
Constructor and Description |
---|
AbstractDelegatingMarshaller() |
Modifier and Type | Method and Description |
---|---|
void |
finishObjectInput(java.io.ObjectInput oi)
Finish using the given ObjectInput.
|
void |
finishObjectOutput(java.io.ObjectOutput oo)
Finish using the given ObjectOutput.
|
BufferSizePredictor |
getBufferSizePredictor(java.lang.Object o)
Returns a marshalled payload size predictor for a particular type.
|
boolean |
isMarshallable(java.lang.Object o)
A method that checks whether the given object is marshallable as per the rules of this marshaller.
|
java.lang.Object |
objectFromByteBuffer(byte[] buf)
Unmarshalls an object from a byte array.
|
java.lang.Object |
objectFromByteBuffer(byte[] buf,
int offset,
int length)
Unmarshalls an object from a specific portion of a byte array.
|
java.lang.Object |
objectFromInputStream(java.io.InputStream is)
Unmarshall an object from an
InputStream |
java.lang.Object |
objectFromObjectStream(java.io.ObjectInput in)
Unmarshalls an object from an
ObjectInput |
ByteBuffer |
objectToBuffer(java.lang.Object o)
A method that returns an instance of
ByteBuffer , which allows direct access to the byte
array with minimal array copying |
byte[] |
objectToByteBuffer(java.lang.Object obj)
Marshalls an object to a byte array.
|
byte[] |
objectToByteBuffer(java.lang.Object obj,
int estimatedSize)
Marshalls an object to a byte array.
|
void |
objectToObjectStream(java.lang.Object obj,
java.io.ObjectOutput out)
Marshalls an object to a given
ObjectOutput |
java.io.ObjectInput |
startObjectInput(java.io.InputStream is,
boolean isReentrant)
Create and open a new ObjectInput for the given input stream.
|
java.io.ObjectOutput |
startObjectOutput(java.io.OutputStream os,
boolean isReentrant,
int estimatedSize)
Create and open an ObjectOutput instance for the given output stream.
|
void |
stop()
Stop the marshaller.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
start
protected StreamingMarshaller marshaller
public void stop()
StreamingMarshaller
stop
in interface StreamingMarshaller
public java.io.ObjectOutput startObjectOutput(java.io.OutputStream os, boolean isReentrant, int estimatedSize) throws java.io.IOException
StreamingMarshaller
Create 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.
startObjectOutput
in interface StreamingMarshaller
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.java.io.IOException
public void finishObjectOutput(java.io.ObjectOutput oo)
StreamingMarshaller
finishObjectOutput
in interface StreamingMarshaller
oo
- data output that finished usingpublic void objectToObjectStream(java.lang.Object obj, java.io.ObjectOutput out) throws java.io.IOException
StreamingMarshaller
ObjectOutput
objectToObjectStream
in interface StreamingMarshaller
obj
- object to marshallout
- stream to marshall tojava.io.IOException
public java.io.ObjectInput startObjectInput(java.io.InputStream is, boolean isReentrant) throws java.io.IOException
StreamingMarshaller
Create 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.
startObjectInput
in interface StreamingMarshaller
is
- input streamisReentrant
- whether the call is reentrant or not.java.io.IOException
public void finishObjectInput(java.io.ObjectInput oi)
StreamingMarshaller
finishObjectInput
in interface StreamingMarshaller
oi
- data input that finished usingpublic java.lang.Object objectFromObjectStream(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.InterruptedException
StreamingMarshaller
ObjectInput
objectFromObjectStream
in interface StreamingMarshaller
in
- stream to unmarshall fromjava.io.IOException
- if unmarshalling cannot complete due to some I/O errorjava.lang.ClassNotFoundException
- if the class of the object trying to unmarshall is unknownjava.lang.InterruptedException
- if the unmarshalling 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.public java.lang.Object objectFromInputStream(java.io.InputStream is) throws java.io.IOException, java.lang.ClassNotFoundException
StreamingMarshaller
InputStream
objectFromInputStream
in interface StreamingMarshaller
is
- stream to unmarshall fromjava.io.IOException
- if unmarshalling cannot complete due to some I/O errorjava.lang.ClassNotFoundException
- if the class of the object trying to unmarshall is unknownpublic byte[] objectToByteBuffer(java.lang.Object obj, int estimatedSize) throws java.io.IOException, java.lang.InterruptedException
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 bejava.io.IOException
- if marshalling cannot complete due to some I/O errorjava.lang.InterruptedException
- 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.public byte[] objectToByteBuffer(java.lang.Object obj) throws java.io.IOException, java.lang.InterruptedException
Marshaller
objectToByteBuffer
in interface Marshaller
obj
- object to convert to a byte array. Must not be null.java.io.IOException
- if marshalling cannot complete due to some I/O errorjava.lang.InterruptedException
- 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.public java.lang.Object objectFromByteBuffer(byte[] buf) throws java.io.IOException, java.lang.ClassNotFoundException
Marshaller
objectFromByteBuffer
in interface Marshaller
buf
- byte array containing the binary representation of an object. Must not be null.java.io.IOException
- if unmarshalling cannot complete due to some I/O errorjava.lang.ClassNotFoundException
- if the class of the object trying to unmarshall is unknownpublic java.lang.Object objectFromByteBuffer(byte[] buf, int offset, int length) throws java.io.IOException, java.lang.ClassNotFoundException
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 considerjava.io.IOException
- if unmarshalling cannot complete due to some I/O errorjava.lang.ClassNotFoundException
- if the class of the object trying to unmarshall is unknownpublic ByteBuffer objectToBuffer(java.lang.Object o) throws java.io.IOException, java.lang.InterruptedException
Marshaller
ByteBuffer
, which allows direct access to the byte
array with minimal array copyingobjectToBuffer
in interface Marshaller
o
- object to marshalljava.io.IOException
- if marshalling cannot complete due to some I/O errorjava.lang.InterruptedException
- 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.public boolean isMarshallable(java.lang.Object o) throws java.lang.Exception
Marshaller
isMarshallable
in interface Marshaller
o
- object to verify whether it's marshallable or notjava.lang.Exception
- if while checking whether the object was serializable or not, an exception arosepublic BufferSizePredictor getBufferSizePredictor(java.lang.Object o)
Marshaller
getBufferSizePredictor
in interface Marshaller
o
- Object for which serialized predictor will be returnedBufferSizePredictor