Package org.apache.ignite.marshaller
Interface Marshaller
-
- All Known Implementing Classes:
AbstractMarshaller
,AbstractNodeNameAwareMarshaller
,JdkMarshaller
public interface Marshaller
Marshaller
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.Ignite provides the following
Marshaller
implementations:- Default binary marshaller. Will be used when no other marshaller is explicitly set to the
configuration. For more information, see
IgniteBinary
. JdkMarshaller
Below are examples of marshaller configuration, usage, and injection into tasks, jobs, and SPI's.
Java Example
Marshaller
can be explicitly configured in code.JdkMarshaller marshaller = new JdkMarshaller(); IgniteConfiguration cfg = new IgniteConfiguration(); // Override marshaller. cfg.setMarshaller(marshaller); // Starts grid. G.start(cfg);
Spring Example
Marshaller 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="org.apache.ignite.marshaller.jdk.JdkMarshaller"/> </property> ... </bean>
For information about Spring framework visit www.springframework.org
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]
marshal(@Nullable Object obj)
Marshals object to byte array.void
marshal(@Nullable Object obj, OutputStream out)
Marshals object to the output stream.void
setContext(MarshallerContext ctx)
Sets marshaller context.<T> T
unmarshal(byte[] arr, @Nullable ClassLoader clsLdr)
Unmarshals object from byte array using given class loader.<T> T
unmarshal(InputStream in, @Nullable ClassLoader clsLdr)
Unmarshals object from the input stream using given class loader.
-
-
-
Method Detail
-
setContext
void setContext(MarshallerContext ctx)
Sets marshaller context.- Parameters:
ctx
- Marshaller context.
-
marshal
void marshal(@Nullable @Nullable Object obj, OutputStream out) throws IgniteCheckedException
Marshals object to the output stream. This method should not close given output stream.- Parameters:
obj
- Object to marshal.null
object will be marshaled to binarynull
representation.out
- Output stream to marshal into.- Throws:
IgniteCheckedException
- If marshalling failed.
-
marshal
byte[] marshal(@Nullable @Nullable Object obj) throws IgniteCheckedException
Marshals object to byte array.- Parameters:
obj
- Object to marshal.null
object will be marshaled to binarynull
representation.- Returns:
- Byte array.
- Throws:
IgniteCheckedException
- If marshalling failed.
-
unmarshal
<T> T unmarshal(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.- Type Parameters:
T
- Type of unmarshalled object.- Parameters:
in
- Input stream.clsLdr
- If notnull
then given class loader will be used for unmarshal object.- Returns:
- Unmarshalled object.
- Throws:
IgniteCheckedException
- If unmarshalling failed.
-
unmarshal
<T> T unmarshal(byte[] arr, @Nullable @Nullable ClassLoader clsLdr) throws IgniteCheckedException
Unmarshals object from byte array using given class loader.- Type Parameters:
T
- Type of unmarshalled object.- Parameters:
arr
- Byte array.clsLdr
- If notnull
then given class loader will be used for unmarshal object.- Returns:
- Unmarshalled object.
- Throws:
IgniteCheckedException
- If unmarshalling failed.
-
-