Class OptimizedMarshallerImpl
- java.lang.Object
-
- org.apache.ignite.marshaller.AbstractMarshaller
-
- org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller
-
- org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerImpl
-
- All Implemented Interfaces:
OptimizedMarshaller,Marshaller
public class OptimizedMarshallerImpl extends AbstractNodeNameAwareMarshaller implements OptimizedMarshaller
Optimized implementation ofMarshaller. UnlikeJdkMarshaller, which is based on standardObjectOutputStream, this marshaller does not enforce that all serialized objects implementSerializableinterface. It is also about 20 times faster as it removes lots of serialization overhead that exists in default JDK implementation.OptimizedMarshalleris 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 Summary
-
Fields inherited from class org.apache.ignite.marshaller.AbstractMarshaller
ctx, DFLT_BUFFER_SIZE
-
-
Constructor Summary
Constructors Constructor Description OptimizedMarshallerImpl()Creates new marshaller will all defaults.OptimizedMarshallerImpl(boolean requireSer)Creates new marshaller providing whether it should requireSerializableinterface or not.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanavailable()Checks whetherGridOptimizedMarshalleris able to work on the current JVM.voidclearClassDescriptorsCache()protected byte[]marshal0(@Nullable Object obj)protected voidmarshal0(@Nullable Object obj, OutputStream out)voidonUndeploy(ClassLoader ldr)Undeployment callback invoked when class loader is being undeployed.OptimizedMarshallersetIdMapper(OptimizedMarshallerIdMapper mapper)OptimizedMarshallersetPoolSize(int poolSize)OptimizedMarshallersetRequireSerializable(boolean requireSer)StringtoString()protected <T> Tunmarshal0(byte[] arr, @Nullable ClassLoader clsLdr)protected <T> Tunmarshal0(InputStream in, @Nullable ClassLoader clsLdr)protected <T> Tunmarshal0(InputStream in, @Nullable ClassLoader clsLdr, boolean useCache)Unmarshals object from the input stream using given class loader.-
Methods inherited from class org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller
marshal, marshal, nodeName, unmarshal, unmarshal
-
Methods inherited from class org.apache.ignite.marshaller.AbstractMarshaller
getContext, setContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.marshaller.Marshaller
marshal, marshal, nodeName, setContext, unmarshal, unmarshal
-
-
-
-
Constructor Detail
-
OptimizedMarshallerImpl
public OptimizedMarshallerImpl()
Creates new marshaller will all defaults.- Throws:
IgniteException- If this marshaller is not supported on the current JVM.
-
OptimizedMarshallerImpl
public OptimizedMarshallerImpl(boolean requireSer)
Creates new marshaller providing whether it should requireSerializableinterface or not.- Parameters:
requireSer- Whether to requireSerializable.
-
-
Method Detail
-
setRequireSerializable
public OptimizedMarshaller setRequireSerializable(boolean requireSer)
- Specified by:
setRequireSerializablein interfaceOptimizedMarshaller
-
setIdMapper
public OptimizedMarshaller setIdMapper(OptimizedMarshallerIdMapper mapper)
- Specified by:
setIdMapperin interfaceOptimizedMarshaller
-
setPoolSize
public OptimizedMarshaller setPoolSize(int poolSize)
- Specified by:
setPoolSizein interfaceOptimizedMarshaller
-
marshal0
protected void marshal0(@Nullable @Nullable Object obj, OutputStream out) throws IgniteCheckedException- Specified by:
marshal0in classAbstractNodeNameAwareMarshaller- Throws:
IgniteCheckedException
-
marshal0
protected byte[] marshal0(@Nullable @Nullable Object obj) throws IgniteCheckedException- Specified by:
marshal0in classAbstractNodeNameAwareMarshaller- Throws:
IgniteCheckedException
-
unmarshal0
protected <T> T unmarshal0(InputStream in, @Nullable @Nullable ClassLoader clsLdr) throws IgniteCheckedException
- Specified by:
unmarshal0in classAbstractNodeNameAwareMarshaller- Throws:
IgniteCheckedException
-
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- Specified by:
unmarshal0in classAbstractNodeNameAwareMarshaller- Throws:
IgniteCheckedException
-
available
public static boolean available()
Checks whetherGridOptimizedMarshalleris able to work on the current JVM.As long as
GridOptimizedMarshalleruses 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:
trueifGridOptimizedMarshallercan work on the current JVM orfalseif it can't.
-
onUndeploy
public void onUndeploy(ClassLoader ldr)
Undeployment callback invoked when class loader is being undeployed.- Specified by:
onUndeployin interfaceMarshaller- Parameters:
ldr- Class loader being undeployed.
-
clearClassDescriptorsCache
public void clearClassDescriptorsCache()
- Specified by:
clearClassDescriptorsCachein interfaceOptimizedMarshaller
-
-