JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   On Github   Forums 

Specifying alternate object streams

From JPPF 3.3 Documentation

Jump to: navigation, search

Contents

Main Page > Extending and Customizing JPPF > Specifying alternate object streams

JPPF performs objects transport and associated serialization by the means of object streams, which are instances of ObjectInputStream and ObjectOutputStream or subclasses of these classes.

It is now possible to specify alternate object stream classes for a JPPF grid, enabling the use of non-serializable classes without any extra coding required for the JPPF task developer. JPPF provides 2 ways to achieve this:

1 Specifying the object stream classes

This is done in the JPPF configuration file, by adding these 2 properties:

 # configure the object input stream implementation
 jppf.object.input.stream.class = my.package.MyObjectInputStream
 # configure the object output stream implementation
 jppf.object.output.stream.class = my.package.MyObjectOutputStream

Please note that the object stream implementations must have a constructor that takes an InputStream parameter for the object input stream class, and an OutputStream parameter for the object output stream class.

2 Implementing an object stream builder

An object stream builder is an object that instantiates input and output object streams.

It is defined as an implementation of the JPPFObjectStreamBuilder interface:

 // Interface for all builders instantiating alternate object input and output streams
 public interface JPPFObjectStreamBuilder {
   // Obtain an input stream used for deserializing objects.
   public ObjectInputStream newObjectInputStream(InputStream in) throws Exception;
 
   // Obtain an Output stream used for serializing objects.
   public ObjectOutputStream newObjectOutputStream(OutputStream out) throws Exception;
 }

You then configure JPPF to use this object stream builder by specifying the following property in the JPPF configuration file:

 # configure the object stream builder implementation
 jppf.object.stream.builder = my.package.MyObjectStreamBuilder

Notes: when alternate object streams are specified, they must be used by all JPPF clients, servers and nodes, otherwise JPPF will not work. The implementation classes must also be present in the classpath of all JPPF components

3 Built-in implementations

Out of the box, JPPF provides 3 serialization schemes:

3.1 Default serialization

This is the default Java serialization mechanism, using the known JDK classes java.io.ObjectInputStream and java.io.ObjectOutputStream. It is used by default, when no serialization scheme is specified.

3.2 Generic JPPF serialization

This is a serialization scheme implemented from scratch, which functions pretty much like the standard Java mechanism with one major difference: it enables the serialization of classes that do not implement java.io.Serializable nor java.io.Externalizable. This allows developers to use classes in their tasks that are not normally serializable and for which they cannot access the source code. We understand that it breaks the contract specified in the JDK for serialization, however it provides an effective workaround for dealing with non-serializable classes in JPPF jobs and tasks.

Apart from this, it conforms to the specifications for the standard ObjectInputStream and ObjectOutputStream classes, in that it processes transient fields in the same manner, and handles the special cases when a class implements the methods writeObject(ObjectOutputStream), readObject(ObjectInputStream), and the java.io.Externalizable interface.

The JPPF implementation relies on an extension of the standard mechanism by defining 2 new classes: JPPFObjectInputStream and JPPFObjectOutputStream.

This implementation is also slower than the default Java one: serialization and deserialization of an object graph takes generally around 50% more time. This overhead will be signifcant essentially for very short-lived tasks (i.e. a few milliseconds). It is thus recommended to use the default Java serialization whenever it is possible.

To specify this scheme in your JPPF configuration:

 # configure the object stream builder implementation
 jppf.object.stream.builder = org.jppf.serialization.GenericObjectStreamBuilder
 
 # configure the object input stream implementation
 jppf.object.input.stream.class = org.jppf.serialization.JPPFObjectInputStream
 # configure the object output stream implementation
 jppf.object.output.stream.class = org.jppf.serialization.JPPFObjectOutputStream

3.3 XStream-based serialization

JPPF has a built-in Object Stream Builder that uses XStream to provide XML serialization: XstreamObjectStreamBuilder. To use it, simply specify:

 # configure the object stream builder implementation
 jppf.object.stream.builder = org.jppf.serialization.XstreamObjectStreamBuilder

in the JPPF configuration files.

You will also need the XStream 1.3 (or later) jar file and the xpp3 jar file available in the XStream distribution.

Main Page > Extending and Customizing JPPF > Specifying alternate object streams

JPPF Copyright © 2005-2020 JPPF.org Powered by MediaWiki