GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid.marshaller.optimized
Class GridOptimizedMarshaller

java.lang.Object
  extended by org.gridgain.grid.marshaller.optimized.GridOptimizedMarshaller
All Implemented Interfaces:
GridMarshaller

public class GridOptimizedMarshaller
extends Object
implements GridMarshaller

Optimized implementation of GridMarshaller. Unlike GridJdkMarshaller, which is based on standard ObjectOutputStream, this marshaller does not enforce that all serialized objects implement Serializable interface. It is also generally much faster as it removes lots of serialization overhead that exists in default JDK implementation.

GridOptimizedMarshaller is the default marshaler and will be used if no other marshaller was explicitly configured.

Configuration

Mandatory

This marshaller has no mandatory configuration parameters.

Java Example

 GridOptimizedMarshaller marshaller = new GridOptimizedMarshaller();

 // Enforce Serializable interface.
 marshaller.setRequireSerializable(true);

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 // Override marshaller.
 cfg.setMarshaller(marshaller);

 // Starts grid.
 G.start(cfg);
 

Spring Example

GridOptimizedMarshaller can be configured from Spring XML configuration file:
 <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
     ...
     <property name="marshaller">
         <bean class="org.gridgain.grid.marshaller.optimized.GridOptimizedMarshaller">
             <property name="requireSerializable">true</property>
         </bean>
     </property>
     ...
 </bean>
 


For information about Spring framework visit www.springframework.org

Injection Example

GridOptimizedMarshaller can be injected in users task, job or SPI as following:
 public class MyGridJob implements GridJob {
     ...
     @GridMarshallerResource
     private GridMarshaller marshaller;
     ...
 }
 
or
 public class MyGridJob implements GridJob {
     ...
     private GridMarshaller marshaller;
     ...
     @GridMarshallerResource
     public void setMarshaller(GridMarshaller marshaller) {
         this.marshaller = marshaller;
     }
     ...
 }
 

Wiki & Forum:


Wiki
Forum

 

Constructor Summary
GridOptimizedMarshaller()
          Initializes marshaller not to enforce Serializable interface.
GridOptimizedMarshaller(boolean requireSer, Collection<String> clsNames, String clsNamesPath)
          Initializes marshaller with given serialization flag.
 
Method Summary
 boolean isRequireSerializable()
           
 void marshal(Object obj, OutputStream out)
          Marshals object to the output stream.
 void setClassNames(Collection<String> clsNames)
          Adds provides class names.
 void setClassNamesPath(String path)
          Specifies a name of the file which lists all class names to be optimized.
 void setRequireSerializable(boolean requireSer)
          Sets flag to enforce Serializable interface or not.
<T> T
unmarshal(InputStream in, ClassLoader clsLdr)
          Unmarshalls object from the output stream using given class loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridOptimizedMarshaller

public GridOptimizedMarshaller()
Initializes marshaller not to enforce Serializable interface.


GridOptimizedMarshaller

public GridOptimizedMarshaller(boolean requireSer,
                               Collection<String> clsNames,
                               String clsNamesPath)
                        throws GridException
Initializes marshaller with given serialization flag. If true, then objects will be required to implement Serializable in order to be serialize.

Throws:
GridException - If an I/O error occurs while writing stream header.
Parameters:
requireSer - Flag to enforce Serializable interface or not. If true, then objects will be required to implement Serializable in order to be marshalled, if false, then such requirement will be relaxed.
clsNames - User preregistered class names.
clsNamesPath - Path to a file with user preregistered class names.
Method Detail

setClassNames

public void setClassNames(Collection<String> clsNames)
Adds provides class names.

Parameters:
clsNames - User preregistered class names to add.

setClassNamesPath

public void setClassNamesPath(String path)
                       throws GridException
Specifies a name of the file which lists all class names to be optimized. The file path can either be absolute path, relative to GRIDGAIN_HOME, or specify a resource file on the class path.

The format of the file is class name per line, like this:

 ...
 com.example.Class1
 com.example.Class2
 ...
 

Throws:
GridException - If an error occurs while writing stream header.
Parameters:
path - Path to a file with user preregistered class names.

isRequireSerializable

public boolean isRequireSerializable()
Returns:
Whether to enforce Serializable interface.

setRequireSerializable

public void setRequireSerializable(boolean requireSer)
                            throws IllegalArgumentException
Sets flag to enforce Serializable interface or not.

Throws:
IllegalArgumentException - If requireSer is false while marshalling of non-serializable classes is not available in the current JVM implementation.
Parameters:
requireSer - Flag to enforce Serializable interface or not. If true, then objects will be required to implement Serializable in order to be marshalled, if false, then such requirement will be relaxed.

marshal

public void marshal(@Nullable
                    Object obj,
                    OutputStream out)
             throws GridException
Marshals object to the output stream. This method should not close given output stream.

Specified by:
marshal in interface GridMarshaller
Throws:
GridException - If marshalling failed.
Parameters:
obj - Object to marshal.
out - Output stream to marshal into.

unmarshal

public <T> T unmarshal(InputStream in,
                       @Nullable
                       ClassLoader clsLdr)
            throws GridException
Unmarshalls object from the output stream using given class loader. This method should not close given input stream.

Specified by:
unmarshal in interface GridMarshaller
Throws:
GridException - If unmarshalling failed.
Type Parameters:
T - Type of unmarshalled object.
Parameters:
in - Input stream.
clsLdr - Class loader to use.
Returns:
Unmarshalled object.

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube