public class OptimizedMarshaller extends AbstractMarshaller
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="org.apache.ignite.marshaller.optimized.OptimizedMarshaller"> <property name="requireSerializable">true</property> </bean> </property> ... </bean>
For information about Spring framework visit www.springframework.org
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. |
byte[] |
marshal(Object obj)
Marshals object to byte array.
|
void |
marshal(Object obj,
OutputStream out)
Marshals object to the output stream.
|
void |
onUndeploy(ClassLoader ldr)
Undeployment callback invoked when class loader is being undeployed.
|
void |
setIdMapper(OptimizedMarshallerIdMapper mapper)
Sets ID mapper.
|
void |
setPoolSize(int poolSize)
Specifies size of cached object streams used by marshaller.
|
void |
setRequireSerializable(boolean requireSer)
Sets whether marshaller should require
Serializable interface or not. |
<T> T |
unmarshal(byte[] arr,
ClassLoader clsLdr)
Unmarshals object from byte array using given class loader.
|
<T> T |
unmarshal(InputStream in,
ClassLoader clsLdr)
Unmarshals object from the output stream using given class loader.
|
setContext
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 void setRequireSerializable(boolean requireSer)
Serializable
interface or not.requireSer
- Whether to require Serializable
.public void setIdMapper(OptimizedMarshallerIdMapper mapper)
mapper
- ID mapper.public void 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.public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException
obj
- Object to marshal.out
- Output stream to marshal into.IgniteCheckedException
- If marshalling failed.public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException
marshal
in interface Marshaller
marshal
in class AbstractMarshaller
obj
- Object to marshal.IgniteCheckedException
- If marshalling failed.public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException
T
- Type of unmarshalled object.in
- Input stream.clsLdr
- Class loader to use.IgniteCheckedException
- If unmarshalling failed.public <T> T unmarshal(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException
unmarshal
in interface Marshaller
unmarshal
in class AbstractMarshaller
T
- 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)
ldr
- Class loader being undeployed.
Follow @ApacheIgnite
Ignite Fabric : ver. 1.1.0-incubating Release Date : May 20 2015