org.infinispan.marshall
Class VersionAwareMarshaller

java.lang.Object
  extended by org.infinispan.marshall.AbstractMarshaller
      extended by org.infinispan.marshall.AbstractStreamingMarshaller
          extended by org.infinispan.marshall.VersionAwareMarshaller
All Implemented Interfaces:
Marshaller, StreamingMarshaller

public class VersionAwareMarshaller
extends AbstractStreamingMarshaller

A delegate to various other marshallers like JBossMarshaller. This delegating marshaller adds versioning information to the stream when marshalling objects and is able to pick the appropriate marshaller to delegate to based on the versioning information when unmarshalling objects.

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

Field Summary
 
Fields inherited from class org.infinispan.marshall.AbstractMarshaller
DEFAULT_BUF_SIZE
 
Constructor Summary
VersionAwareMarshaller()
           
 
Method Summary
 void finishObjectInput(ObjectInput oi)
          Finish using the given ObjectInput.
 void finishObjectOutput(ObjectOutput oo)
          Finish using the given ObjectOutput.
protected  int getCustomMarshallerVersionInt()
           
 void inject(ClassLoader loader, RemoteCommandsFactory remoteCommandsFactory)
           
 boolean isMarshallable(Object o)
          A method that checks whether the given object is marshallable as per the rules of this marshaller.
 Object objectFromByteBuffer(byte[] bytes, int offset, int len)
          Unmarshalls an object from a specific portion of a byte array.
 Object objectFromObjectStream(ObjectInput in)
          Unmarshalls an object from an ObjectInput
protected  ByteBuffer objectToBuffer(Object obj, int estimatedSize)
          This is a convenience method for converting an object into a ByteBuffer which takes an estimated size as parameter.
 void objectToObjectStream(Object obj, ObjectOutput out)
          Marshalls an object to a given ObjectOutput
 void start()
           
 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.
 void stop()
           
 
Methods inherited from class org.infinispan.marshall.AbstractStreamingMarshaller
objectFromInputStream
 
Methods inherited from class org.infinispan.marshall.AbstractMarshaller
objectFromByteBuffer, objectToBuffer, objectToByteBuffer, objectToByteBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.infinispan.marshall.Marshaller
objectFromByteBuffer, objectToBuffer, objectToByteBuffer, objectToByteBuffer
 

Constructor Detail

VersionAwareMarshaller

public VersionAwareMarshaller()
Method Detail

inject

public void inject(ClassLoader loader,
                   RemoteCommandsFactory remoteCommandsFactory)

start

public void start()

stop

public void stop()

getCustomMarshallerVersionInt

protected int getCustomMarshallerVersionInt()

objectToBuffer

protected ByteBuffer objectToBuffer(Object obj,
                                    int estimatedSize)
                             throws IOException
Description copied from class: AbstractMarshaller
This is a convenience method for converting an object into a ByteBuffer which takes an estimated size as parameter. A ByteBuffer allows direct access to the byte array with minimal array copying

Specified by:
objectToBuffer in class AbstractMarshaller
Parameters:
obj - object to marshall
estimatedSize - an estimate of how large the resulting byte array may be
Returns:
a ByteBuffer
Throws:
IOException

objectFromByteBuffer

public Object objectFromByteBuffer(byte[] bytes,
                                   int offset,
                                   int len)
                            throws IOException,
                                   ClassNotFoundException
Description copied from interface: Marshaller
Unmarshalls an object from a specific portion of a byte array.

Parameters:
bytes - byte array containing the binary representation of an object. Must not be null.
offset - point in buffer to start reading
len - number of bytes to consider
Returns:
an object
Throws:
IOException
ClassNotFoundException

startObjectOutput

public ObjectOutput startObjectOutput(OutputStream os,
                                      boolean isReentrant)
                               throws IOException
Description copied from interface: 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 accross. This enables lazy deserialization 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.

Parameters:
os - output stream
isReentrant - whether the call is reentrant or not.
Returns:
ObjectOutput to write to
Throws:
IOException

finishObjectOutput

public void finishObjectOutput(ObjectOutput oo)
Description copied from interface: StreamingMarshaller
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

public void objectToObjectStream(Object obj,
                                 ObjectOutput out)
                          throws IOException
Description copied from interface: StreamingMarshaller
Marshalls an object to a given ObjectOutput

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

startObjectInput

public ObjectInput startObjectInput(InputStream is,
                                    boolean isReentrant)
                             throws IOException
Description copied from interface: 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.

Parameters:
is - input stream
isReentrant - whether the call is reentrant or not.
Returns:
ObjectInput to read from
Throws:
IOException

finishObjectInput

public void finishObjectInput(ObjectInput oi)
Description copied from interface: StreamingMarshaller
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

public Object objectFromObjectStream(ObjectInput in)
                              throws IOException,
                                     ClassNotFoundException
Description copied from interface: StreamingMarshaller
Unmarshalls an object from an ObjectInput

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

isMarshallable

public boolean isMarshallable(Object o)
Description copied from interface: Marshaller
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.