org.infinispan.marshall
Interface Marshaller

All Known Subinterfaces:
StreamingMarshaller
All Known Implementing Classes:
AbstractMarshaller, AbstractStreamingMarshaller, GenericJBossMarshaller, JBossMarshaller, VersionAwareMarshaller

@ThreadSafe
public interface Marshaller

A marshaller is a class that is able to marshall and unmarshall objects efficiently.

This interface is used to marshall ReplicableCommands, their parameters and their response values, as well as any other arbitraty Object <--> byte[] conversions, such as those used in client/server communications.

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.

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
 boolean isMarshallable(Object o)
          A method that checks whether the given object is marshallable as per the rules of this marshaller.
 Object objectFromByteBuffer(byte[] buf)
          Unmarshalls an object from a byte array.
 Object objectFromByteBuffer(byte[] buf, int offset, int length)
          Unmarshalls an object from a specific portion of a byte array.
 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)
          Marshalls an object to a byte array.
 byte[] objectToByteBuffer(Object obj, int estimatedSize)
          Marshalls an object to a byte array.
 

Method Detail

objectToByteBuffer

byte[] objectToByteBuffer(Object obj,
                          int estimatedSize)
                          throws IOException
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
Throws:
IOException

objectToByteBuffer

byte[] objectToByteBuffer(Object obj)
                          throws IOException
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

objectFromByteBuffer

Object objectFromByteBuffer(byte[] buf)
                            throws IOException,
                                   ClassNotFoundException
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
ClassNotFoundException

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 reading
length - number of bytes to consider
Returns:
an object
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

isMarshallable

boolean isMarshallable(Object o)
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

Google Analytics

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