public interface GridMarshaller
GridMarshaller allows to marshal or unmarshal objects in grid. It provides
serialization/deserialization mechanism for all instances that are sent across networks
or are otherwise serialized.
Gridgain provides the following GridMarshaller implementations:
GridOptimizedMarshaller - defaultGridJdkMarshallerBelow are examples of marshaller configuration, usage, and injection into tasks, jobs, and SPI's.
GridMarshaller can be explicitely configured in code.
GridJdkMarshaller marshaller = new GridJdkMarshaller(); GridConfiguration cfg = new GridConfiguration(); // Override marshaller. cfg.setMarshaller(marshaller); // Starts grid. G.start(cfg);
<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true">
...
<property name="marshaller">
<bean class="org.gridgain.grid.marshaller.jdk.GridJdkMarshaller"/>
</property>
...
</bean>
For information about Spring framework visit www.springframework.org
public class MyGridJob implements GridComputeJob {
...
@GridMarshallerResource
private GridMarshaller marshaller;
public Serializable execute() {
// Use marshaller to serialize/deserialize any object.
...
}
}
or
public class MyGridJob implements GridComputeJob {
...
private GridMarshaller marshaller;
...
@GridMarshallerResource
public void setMarshaller(GridMarshaller marshaller) {
this.marshaller = marshaller;
}
...
}
| Modifier and Type | Method and Description |
|---|---|
byte[] |
marshal(Object obj)
Marshals object to byte array.
|
void |
marshal(Object obj,
OutputStream out)
Marshals object to the output stream.
|
<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.
|
void marshal(@Nullable Object obj, OutputStream out) throws GridException
obj - Object to marshal.out - Output stream to marshal into.GridException - If marshalling failed.byte[] marshal(@Nullable Object obj) throws GridException
obj - Object to marshal.GridException - If marshalling failed.<T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws GridException
T - Type of unmarshalled object.in - Input stream.clsLdr - Class loader to use.GridException - If unmarshalling failed.<T> T unmarshal(byte[] arr,
@Nullable
ClassLoader clsLdr)
throws GridException
T - Type of unmarshalled object.arr - Byte array.clsLdr - Class loader to use.GridException - If unmarshalling failed.Copyright © 2014. All rights reserved.