org.clazzes.remoting.marshal.impl
Class CompactMarshaler

java.lang.Object
  extended by org.clazzes.remoting.marshal.impl.MarshalerSupport
      extended by org.clazzes.remoting.marshal.impl.CompactMarshaler
All Implemented Interfaces:
Marshaler

public class CompactMarshaler
extends MarshalerSupport

A marshaler, which marshals object in a field-by-field manner. It uses a compact binary format on the underlying streams and uses a class registry, which might contain a fixed set of classes to be marshaled. The set of classes to be marshaled may be dynamically expanded, which is usually not desirable, if a remoting server communicates with an implementation in a foreign language like C++.

Author:
wglas

Constructor Summary
CompactMarshaler(MarshalerClassRegistry classRegistry, boolean extendClasses, boolean flattenCollections, ObjectResolver objectResolver, int outputBufferSize, int inputBufferSize)
           
 
Method Summary
 void close()
          Close the underlying transport and prepare the marshaler for calling Marshaler.setup(OutputStream, InputStream, ClassLoader) again.
protected  void flushStream()
          This method flushes the underlying stream without flushing the write cache This method might be used by reimplementations of CompactMarshaler which obey a more complex flush policy.
 ObjectResolver getObjectResolver()
           
 boolean isExtendClasses()
           
 boolean isFlattenCollections()
           
 java.lang.Object readObject()
          Read the next object from the input stream.
 void reset()
          Reset the state of the serializer.
 void setup(java.io.OutputStream os, java.io.InputStream is, java.lang.ClassLoader inputClassLoader)
          Set up the marshaler for operation.
 void writeObject(java.lang.Object obj)
          Write an object to the underlying transport.
protected  void writeObjectNoFlush(java.lang.Object obj)
          This writes the object to the stream without flushing the write buffer.
 
Methods inherited from class org.clazzes.remoting.marshal.impl.MarshalerSupport
getInputBufferSize, getOutputBufferSize, prepareInputStream, prepareOutputStream, setInputBufferSize, setOutputBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompactMarshaler

public CompactMarshaler(MarshalerClassRegistry classRegistry,
                        boolean extendClasses,
                        boolean flattenCollections,
                        ObjectResolver objectResolver,
                        int outputBufferSize,
                        int inputBufferSize)
Parameters:
objectResolver -
outputBufferSize -
inputBufferSize -
Method Detail

getObjectResolver

public ObjectResolver getObjectResolver()
Returns:
the object resolver used to intercept objects being read or written.

isExtendClasses

public boolean isExtendClasses()
Returns:
Whether the class registry should be auto-extended for new classes to be serialized.

isFlattenCollections

public boolean isFlattenCollections()
Returns:
Whether to write collections in a specialized form.

close

public void close()
Description copied from interface: Marshaler
Close the underlying transport and prepare the marshaler for calling Marshaler.setup(OutputStream, InputStream, ClassLoader) again. This method should be implemented in a fashion that is tolerant for an incomplete setup of the marshaler. It should even be possible to call close() twice on a single marshaler object.


readObject

public java.lang.Object readObject()
                            throws java.lang.ClassNotFoundException,
                                   java.io.IOException
Description copied from interface: Marshaler
Read the next object from the input stream. It is the responsibility of the caller, that this method is only called from a single thread at a time. The implementation need not be synchronized.

Returns:
The next object on the input stream.
Throws:
java.lang.ClassNotFoundException - If the underlying class loader was unable to find the class of a serialized object.
java.io.IOException - Upon transport errors.

reset

public void reset()
           throws java.io.IOException
Description copied from interface: Marshaler
Reset the state of the serializer. This incurs the cleanup of the object cache, which ensures, that the same instance of a class is serialized as reference rather than being serialized a second time.

Throws:
java.io.IOException - Upon transport errors.

setup

public void setup(java.io.OutputStream os,
                  java.io.InputStream is,
                  java.lang.ClassLoader inputClassLoader)
           throws java.io.IOException
Description copied from interface: Marshaler
Set up the marshaler for operation. Implementations must guarantee, that both, the input and the output stream are closed, when an excpetion is thrown.

Parameters:
os - The output stream to write to.
is - The input stream to read from.
inputClassLoader - The ClassLoader to use for deserialized instances.
Throws:
java.io.IOException - Upon errors setting up the streams.

writeObjectNoFlush

protected void writeObjectNoFlush(java.lang.Object obj)
                           throws java.io.IOException
This writes the object to the stream without flushing the write buffer. This method might be used by reimplementations of CompactMarshaler which obey a more complex flush policy.

Parameters:
obj - The object to write
Throws:
java.io.IOException - Upon errors.

flushStream

protected void flushStream()
                    throws java.io.IOException
This method flushes the underlying stream without flushing the write cache This method might be used by reimplementations of CompactMarshaler which obey a more complex flush policy.

Throws:
java.io.IOException - Upon errors on the underlying stream.

writeObject

public void writeObject(java.lang.Object obj)
                 throws java.io.IOException
Description copied from interface: Marshaler
Write an object to the underlying transport. This method must be implemented in a synchronized manner in order to allow writing objects from two concurrent threads.

Parameters:
obj - The object to write.
Throws:
java.io.IOException - Upon transport errors.


Copyright © 2010. All Rights Reserved.