Class OptimizedMarshaller

  • All Implemented Interfaces:
    Marshaller

    public class OptimizedMarshaller
    extends AbstractNodeNameAwareMarshaller
    Optimized implementation of Marshaller. Unlike JdkMarshaller, which is based on standard ObjectOutputStream, this marshaller does not enforce that all serialized objects implement Serializable interface. It is also about 20 times faster as it removes lots of serialization overhead that exists in default JDK implementation.

    OptimizedMarshaller is tested only on Java HotSpot VM on other VMs it could yield unexpected results. It is the default marshaller on Java HotSpot VMs and will be used if no other marshaller was explicitly configured.

    Configuration

    Mandatory

    This marshaller has no mandatory configuration parameters.

    Java Example

     OptimizedMarshaller marshaller = new OptimizedMarshaller();
    
     // Enforce Serializable interface.
     marshaller.setRequireSerializable(true);
    
     IgniteConfiguration cfg = new IgniteConfiguration();
    
     // 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.apache.ignite.configuration.IgniteConfiguration" singleton="true">
         ...
         <property name="marshaller">
             <bean class="OptimizedMarshaller">
                 <property name="requireSerializable">true</property>
             </bean>
         </property>
         ...
     </bean>
     


    For information about Spring framework visit www.springframework.org

    • Field Detail

      • USE_DFLT_SUID

        public static final boolean USE_DFLT_SUID
        Use default serialVersionUID for Serializable classes.
    • Constructor Detail

      • OptimizedMarshaller

        public OptimizedMarshaller()
        Creates new marshaller will all defaults.
        Throws:
        IgniteException - If this marshaller is not supported on the current JVM.
      • OptimizedMarshaller

        public OptimizedMarshaller​(boolean requireSer)
        Creates new marshaller providing whether it should require Serializable interface or not.
        Parameters:
        requireSer - Whether to require Serializable.
    • Method Detail

      • setRequireSerializable

        public OptimizedMarshaller setRequireSerializable​(boolean requireSer)
        Sets whether marshaller should require Serializable interface or not.
        Parameters:
        requireSer - Whether to require Serializable.
        Returns:
        this for chaining.
      • setPoolSize

        public OptimizedMarshaller setPoolSize​(int poolSize)
        Specifies size of cached object streams used by marshaller. Object streams are cached for performance reason to avoid costly recreation for every serialization routine. If 0 (default), pool is not used and each thread has its own cached object stream which it keeps reusing.

        Since each stream has an internal buffer, creating a stream for each thread can lead to high memory consumption if many large messages are marshalled or unmarshalled concurrently. Consider using pool in this case. This will limit number of streams that can be created and, therefore, decrease memory consumption.

        NOTE: Using streams pool can decrease performance since streams will be shared between different threads which will lead to more frequent context switching.

        Parameters:
        poolSize - Streams pool size. If 0, pool is not used.
        Returns:
        this for chaining.
      • unmarshal0

        protected <T> T unmarshal0​(InputStream in,
                                   @Nullable
                                   @Nullable ClassLoader clsLdr)
                            throws IgniteCheckedException
        Unmarshals object from the input stream using given class loader. This method should not close given input stream.
        Specified by:
        unmarshal0 in class AbstractNodeNameAwareMarshaller
        Type Parameters:
        T - Type of unmarshalled object.
        Parameters:
        in - Input stream.
        clsLdr - If not null then given class loader will be used for unmarshal object.
        Returns:
        Unmarshalled object.
        Throws:
        IgniteCheckedException - If unmarshalling failed.
      • unmarshal0

        protected <T> T unmarshal0​(InputStream in,
                                   @Nullable
                                   @Nullable ClassLoader clsLdr,
                                   boolean useCache)
                            throws IgniteCheckedException
        Unmarshals object from the input stream using given class loader. This method should not close given input stream.
        Type Parameters:
        T - Type of unmarshalled object.
        Parameters:
        in - Input stream.
        clsLdr - Class loader to use.
        useCache - True if class loader cache will be used, false otherwise.
        Returns:
        Unmarshalled object.
        Throws:
        IgniteCheckedException - If unmarshalling failed.
      • unmarshal0

        protected <T> T unmarshal0​(byte[] arr,
                                   @Nullable
                                   @Nullable ClassLoader clsLdr)
                            throws IgniteCheckedException
        Unmarshals object from byte array using given class loader.
        Specified by:
        unmarshal0 in class AbstractNodeNameAwareMarshaller
        Type Parameters:
        T - Type of unmarshalled object.
        Parameters:
        arr - Byte array.
        clsLdr - If not null then given class loader will be used for unmarshal object.
        Returns:
        Unmarshalled object.
        Throws:
        IgniteCheckedException - If unmarshalling failed.
      • available

        public static boolean available()
        Checks whether GridOptimizedMarshaller is able to work on the current JVM.

        As long as GridOptimizedMarshaller uses JVM-private API, which is not guaranteed to be available on all JVM, this method should be called to ensure marshaller could work properly.

        Result of this method is automatically checked in constructor.

        Returns:
        true if GridOptimizedMarshaller can work on the current JVM or false if it can't.
      • onUndeploy

        public void onUndeploy​(ClassLoader ldr)
        Undeployment callback invoked when class loader is being undeployed.
        Specified by:
        onUndeploy in class AbstractMarshaller
        Parameters:
        ldr - Class loader being undeployed.
      • clearClassDescriptorsCache

        public void clearClassDescriptorsCache()
        Clears the optimized class descriptors cache. This is essential for the clients on disconnect in order to make them register their user types again (server nodes may lose previously registered types).