|
GridGain 4.3.1e
Enterprise "Data Grid" Edition |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gridgain.grid.marshaller.GridAbstractMarshaller
org.gridgain.grid.marshaller.optimized.GridOptimizedMarshaller
public class GridOptimizedMarshaller
Optimized implementation of GridMarshaller. Unlike GridJdkMarshaller,
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.
GridOptimizedMarshaller 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.
GridOptimizedMarshaller marshaller = new GridOptimizedMarshaller(); // Enforce Serializable interface. marshaller.setRequireSerializable(true); GridConfigurationAdapter cfg = new GridConfigurationAdapter(); // Override marshaller. cfg.setMarshaller(marshaller); // Starts grid. G.start(cfg);
<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
...
<property name="marshaller">
<bean class="org.gridgain.grid.marshaller.optimized.GridOptimizedMarshaller">
<property name="requireSerializable">true</property>
</bean>
</property>
...
</bean>
For information about Spring framework visit www.springframework.org
public class MyGridJob implements GridJob {
...
@GridMarshallerResource
private GridMarshaller marshaller;
...
}
or
public class MyGridJob implements GridJob {
...
private GridMarshaller marshaller;
...
@GridMarshallerResource
public void setMarshaller(GridMarshaller marshaller) {
this.marshaller = marshaller;
}
...
}
![]() |
![]() |
| Field Summary |
|---|
| Fields inherited from class org.gridgain.grid.marshaller.GridAbstractMarshaller |
|---|
DFLT_BUFFER_SIZE |
| Constructor Summary | |
|---|---|
GridOptimizedMarshaller()
Initializes marshaller not to enforce Serializable interface. |
|
GridOptimizedMarshaller(boolean requireSer,
List<String> clsNames,
String clsNamesPath)
Initializes marshaller with given serialization flag. |
|
| Method Summary | ||
|---|---|---|
static boolean |
available()
Checks whether GridOptimizedMarshaller is able to work on the current JVM. |
|
boolean |
isRequireSerializable()
|
|
byte[] |
marshal(Object obj)
Marshals object to byte array. |
|
void |
marshal(Object obj,
OutputStream out)
Marshals object to the output stream. |
|
void |
setClassNames(List<String> clsNames)
Adds provided class names for marshalling optimization. |
|
void |
setClassNamesPath(String path)
Specifies a name of the file which lists all class names to be optimized. |
|
void |
setRequireSerializable(boolean requireSer)
Sets flag to enforce Serializable interface or not. |
|
|
unmarshal(byte[] arr,
ClassLoader clsLdr)
Unmarshals object from byte array using given class loader. |
|
|
unmarshal(InputStream in,
ClassLoader clsLdr)
Unmarshals object from the output stream using given class loader. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public GridOptimizedMarshaller()
Serializable interface.
GridRuntimeException - If this marshaller is not supported on the current JVM.
public GridOptimizedMarshaller(boolean requireSer,
@Nullable
List<String> clsNames,
@Nullable
String clsNamesPath)
throws GridException
true,
then objects will be required to implement Serializable in order
to be serialize.
GridException - If an I/O error occurs while writing stream header.
GridRuntimeException - If this marshaller is not supported on the current JVM.requireSer - Flag to enforce Serializable interface or not. If true,
then objects will be required to implement Serializable in order to be
marshalled, if false, then such requirement will be relaxed.clsNames - User preregistered class names.clsNamesPath - Path to a file with user preregistered class names.| Method Detail |
|---|
public void setClassNames(@Nullable
List<String> clsNames)
NOTE: these collections of classes must be identical on all nodes and in the same order.
clsNames - User preregistered class names to add.
public void setClassNamesPath(@Nullable
String path)
throws GridException
GRIDGAIN_HOME,
or specify a resource file on the class path.
The format of the file is class name per line, like this:
... com.example.Class1 com.example.Class2 ...
NOTE: this class list must be identical on all nodes and in the same order.
GridException - If an error occurs while writing stream header.path - Path to a file with user preregistered class names.public boolean isRequireSerializable()
Serializable interface.public void setRequireSerializable(boolean requireSer)
Serializable interface or not.
requireSer - Flag to enforce Serializable interface or not. If true,
then objects will be required to implement Serializable in order to be
marshalled, if false, then such requirement will be relaxed.
public void marshal(@Nullable
Object obj,
OutputStream out)
throws GridException
GridException - If marshalling failed.obj - Object to marshal.out - Output stream to marshal into.
public byte[] marshal(@Nullable
Object obj)
throws GridException
marshal in interface GridMarshallermarshal in class GridAbstractMarshallerGridException - If marshalling failed.obj - Object to marshal.
public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws GridException
GridException - If unmarshalling failed.T - Type of unmarshalled object.in - Input stream.clsLdr - Class loader to use.
public <T> T unmarshal(byte[] arr, @Nullable ClassLoader clsLdr) throws GridException
unmarshal in interface GridMarshallerunmarshal in class GridAbstractMarshallerGridException - If unmarshalling failed.T - Type of unmarshalled object.arr - Byte array.clsLdr - Class loader to use.
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.
|
GridGain 4.3.1e
Enterprise "Data Grid" Edition |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
|
GridGain - In-Memory Big Data
|
|
|