public class OptimizedMarshaller extends AbstractNodeNameAwareMarshaller
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.
OptimizedMarshaller marshaller = new OptimizedMarshaller(); // Enforce Serializable interface. marshaller.setRequireSerializable(true); IgniteConfiguration cfg = new IgniteConfiguration(); // Override marshaller. cfg.setMarshaller(marshaller); // Starts grid. G.start(cfg);
<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
| Modifier and Type | Field and Description |
|---|---|
static boolean |
USE_DFLT_SUID
Use default
serialVersionUID for Serializable classes. |
ctx, DFLT_BUFFER_SIZE| Constructor and Description |
|---|
OptimizedMarshaller()
Creates new marshaller will all defaults.
|
OptimizedMarshaller(boolean requireSer)
Creates new marshaller providing whether it should
require
Serializable interface or not. |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
available()
Checks whether
GridOptimizedMarshaller is able to work on the current JVM. |
protected byte[] |
marshal0(Object obj)
Marshals object to byte array.
|
protected void |
marshal0(Object obj,
OutputStream out)
Marshals object to the output stream.
|
void |
onUndeploy(ClassLoader ldr)
Undeployment callback invoked when class loader is being undeployed.
|
OptimizedMarshaller |
setIdMapper(OptimizedMarshallerIdMapper mapper)
Sets ID mapper.
|
OptimizedMarshaller |
setPoolSize(int poolSize)
Specifies size of cached object streams used by marshaller.
|
OptimizedMarshaller |
setRequireSerializable(boolean requireSer)
Sets whether marshaller should require
Serializable interface or not. |
String |
toString() |
protected <T> T |
unmarshal0(byte[] arr,
ClassLoader clsLdr)
Unmarshals object from byte array using given class loader.
|
protected <T> T |
unmarshal0(InputStream in,
ClassLoader clsLdr)
Unmarshals object from the input stream using given class loader.
|
marshal, marshal, nodeName, unmarshal, unmarshalgetContext, setContextpublic static final boolean USE_DFLT_SUID
serialVersionUID for Serializable classes.public OptimizedMarshaller()
IgniteException - If this marshaller is not supported on the current JVM.public OptimizedMarshaller(boolean requireSer)
Serializable interface or not.requireSer - Whether to require Serializable.public OptimizedMarshaller setRequireSerializable(boolean requireSer)
Serializable interface or not.requireSer - Whether to require Serializable.this for chaining.public OptimizedMarshaller setIdMapper(OptimizedMarshallerIdMapper mapper)
mapper - ID mapper.this for chaining.public OptimizedMarshaller setPoolSize(int poolSize)
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.
poolSize - Streams pool size. If 0, pool is not used.this for chaining.protected void marshal0(@Nullable
Object obj,
OutputStream out)
throws IgniteCheckedException
marshal0 in class AbstractNodeNameAwareMarshallerobj - Object to marshal.out - Output stream to marshal into.IgniteCheckedException - If marshalling failed.protected byte[] marshal0(@Nullable
Object obj)
throws IgniteCheckedException
marshal0 in class AbstractNodeNameAwareMarshallerobj - Object to marshal.IgniteCheckedException - If marshalling failed.protected <T> T unmarshal0(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException
unmarshal0 in class AbstractNodeNameAwareMarshallerT - Type of unmarshalled object.in - Input stream.clsLdr - Class loader to use.IgniteCheckedException - If unmarshalling failed.protected <T> T unmarshal0(byte[] arr,
@Nullable
ClassLoader clsLdr)
throws IgniteCheckedException
unmarshal0 in class AbstractNodeNameAwareMarshallerT - Type of unmarshalled object.arr - Byte array.clsLdr - Class loader to use.IgniteCheckedException - If unmarshalling failed.public static boolean available()
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.
true if GridOptimizedMarshaller can work on the current JVM or
false if it can't.public void onUndeploy(ClassLoader ldr)
onUndeploy in class AbstractMarshallerldr - Class loader being undeployed.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.7.5 Release Date : June 4 2019