org.infinispan.marshall
Interface Marshaller

All Known Implementing Classes:
AbstractMarshaller, JBossMarshaller, MarshallerImpl, VersionAwareMarshaller

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 as org.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 ReplicableCommands, 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.

Since:
4.0
Author:
Manik Surtani, Galder ZamarreƱo

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)
          Create and open a new ObjectInput for the given input stream.
 ObjectOutput startObjectOutput(OutputStream os)
          Create and open a new ObjectOutput for the given output stream.
 

Method Detail

startObjectOutput

ObjectOutput startObjectOutput(OutputStream os)
                               throws IOException
Create and open a new ObjectOutput for the given output stream. This method should be used for opening data outpus when multiple objectToObjectStream() calls will be made before the stream is closed

Parameters:
os - output stream
Returns:
ObjectOutput to write to
Throws:
IOException

finishObjectOutput

void finishObjectOutput(ObjectOutput oo)
Finish using the given ObjectOutput. After opening a ObjectOutput and calling objectToObjectStream() mutliple times, use this method to flush the data and close if necessary

Parameters:
oo - data output that finished using

objectToObjectStream

void objectToObjectStream(Object obj,
                          ObjectOutput out)
                          throws IOException
Marshalls an object to a given ObjectOutput

Parameters:
obj - object to marshall
out - stream to marshall to
Throws:
IOException

startObjectInput

ObjectInput startObjectInput(InputStream is)
                             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.

Parameters:
is - input stream
Returns:
ObjectInput to read from
Throws:
IOException

finishObjectInput

void finishObjectInput(ObjectInput oi)
Finish using the given ObjectInput. After opening a ObjectInput and calling objectFromObjectStream() mutliple times, use this method to flush the data and close if necessary

Parameters:
oi - data input that finished using

objectFromObjectStream

Object objectFromObjectStream(ObjectInput in)
                              throws IOException,
                                     ClassNotFoundException
Unmarshalls an object from an ObjectInput

Parameters:
in - stream to unmarshall from
Throws:
IOException
ClassNotFoundException

objectToBuffer

ByteBuffer objectToBuffer(Object o)
                          throws IOException
A method that returns an instance of ByteBuffer, which allows direct access to the byte array with minimal array copying

Parameters:
o - object to marshall
Returns:
a ByteBuffer
Throws:
Exception
IOException

objectFromByteBuffer

Object objectFromByteBuffer(byte[] buf,
                            int offset,
                            int length)
                            throws IOException,
                                   ClassNotFoundException
Throws:
IOException
ClassNotFoundException

objectToByteBuffer

byte[] objectToByteBuffer(Object obj)
                          throws IOException
Throws:
IOException

objectFromByteBuffer

Object objectFromByteBuffer(byte[] buf)
                            throws IOException,
                                   ClassNotFoundException
Throws:
IOException
ClassNotFoundException

objectFromInputStream

Object objectFromInputStream(InputStream is)
                             throws IOException,
                                    ClassNotFoundException
Throws:
IOException
ClassNotFoundException


Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.