|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Marshaller
A marshaller is a class that is able to marshall and unmarshall objects efficiently.
The reason why this is implemented specially in Infinispan rather than resorting to Java serialization or even the more efficient JBoss serialization is that a lot of efficiency can be gained when a majority of the serialization that occurs has to do with a small set of known types such asorg.infinispan.transaction.GlobalTransaction
or
ReplicableCommand
, and class type information can be replaced with simple magic
numbers.
Unknown types (typically user data) falls back to JBoss serialization.
In addition, using a marshaller allows adding additional data to the byte stream, such as context class loader
information on which class loader to use to deserialize the object stream, or versioning information to allow streams
to interoperate between different versions of Infinispan (see VersionAwareMarshaller
This interface is used to marshall ReplicableCommand
s, their parameters and their
response values.
The interface is also used by the CacheStore
framework to efficiently serialize data
to be persisted, as well as the StateTransferManager
when serializing the cache
for transferring state en-masse.
Method Summary | |
---|---|
void |
finishObjectInput(ObjectInput oi)
Finish using the given ObjectInput. |
void |
finishObjectOutput(ObjectOutput oo)
Finish using the given ObjectOutput. |
Object |
objectFromByteBuffer(byte[] buf)
|
Object |
objectFromByteBuffer(byte[] buf,
int offset,
int length)
|
Object |
objectFromInputStream(InputStream is)
|
Object |
objectFromObjectStream(ObjectInput in)
Unmarshalls an object from an ObjectInput |
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)
|
void |
objectToObjectStream(Object obj,
ObjectOutput out)
Marshalls an object to a given ObjectOutput |
ObjectInput |
startObjectInput(InputStream is,
boolean isReentrant)
Create and open a new ObjectInput for the given input stream. |
ObjectOutput |
startObjectOutput(OutputStream os,
boolean isReentrant)
Create and open an ObjectOutput instance for the given output stream. |
Method Detail |
---|
ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException
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 Marshaller 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 Marshaller 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 accross.
This enables lazy deserialization on the receiver side which is performance gain. The Marshaller 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.
os
- output streamisReentrant
- whether the call is reentrant or not.
IOException
void finishObjectOutput(ObjectOutput oo)
oo
- data output that finished usingvoid objectToObjectStream(Object obj, ObjectOutput out) throws IOException
ObjectOutput
obj
- object to marshallout
- stream to marshall to
IOException
ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException
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 Marshaller implementation could potentially use some mechanisms to speed up this startObjectInput call.
is
- input streamisReentrant
- whether the call is reentrant or not.
IOException
void finishObjectInput(ObjectInput oi)
oi
- data input that finished usingObject objectFromObjectStream(ObjectInput in) throws IOException, ClassNotFoundException
ObjectInput
in
- stream to unmarshall from
IOException
ClassNotFoundException
ByteBuffer objectToBuffer(Object o) throws IOException
ByteBuffer
, which allows direct access to the byte
array with minimal array copying
o
- object to marshall
Exception
IOException
Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
byte[] objectToByteBuffer(Object obj) throws IOException
IOException
Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
Object objectFromInputStream(InputStream is) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
|
Google Analytics | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |