Changes between Initial Version and Version 1 of uka.transport


Ignore:
Timestamp:
Aug 22, 2005 8:57:56 AM (13 years ago)
Author:
hauma
Comment:

From legacy page.

Legend:

Unmodified
Added
Removed
Modified
  • uka.transport

    v1 v1  
     1= Fast Object Serialization uka.transport =
     2
     3In the Java API an object serialization mechanism is provided that is able to transparently convert object structures into a linear byte sequence representation and vice versa. For sending objects across the network, this representation can be used. To make his classes serializable, the Java programmer only needs to declare his classes to implement the empty tagging interface java.io.Serializable.
     4
     5{{{
     6#!java
     7/** A simple serializable class */
     8public class Param implements java.io.Serializable {
     9   int    intValue;
     10   float  floatValue;
     11   Object objectReference;
     12}
     13}}}
     14
     15Although transparency of object serialization is one of Java's beauties, its runtime costs are phenomenal. Since RMI uses Java's built-in object serialization mechanism, usually one third of the overall invocation time of a remote method is spent in marshaling and unmarshaling method arguments. On current hardware, a millisecond is easy to spend in serialization alone. For details please refer to the section "JavaParty papers".
     16
     17{{{
     18#!java
     19// Assume: Param p, InputStream in, OutputStream out
     20//
     21// Writing an object into a stream and reading it back
     22new ObjectOutputStream(out).writeObject(p);
     23Param q = (Param) new ObjectInputStream(in).readObject();
     24}}}
     25
     26For high performance distributed computing inefficient serialization cannot be tolerated. Therefore, we've looked into the details of the official serialization, which is mostly implemented in Java itself, and derived an optimized replacement for it. In some benchmarks, we could eliminate 81-97% of the overhead caused by the regular Java serialization. For details please refer to the section "JavaParty papers".
     27
     28== Object Serialization vs. Fast Marshaling ==
     29
     30The regular Java serialization is justifiable for persistent object storage, because it guarantees that objects can be reconstructed from their byte sequence representation even with future Java releases, and even with modified application classes. Our optimized serialization does not make such guarantees. Instead, it is designed for exchanging objects between running VMs that share the same class base.
     31
     32== Look and Feel ==
     33
     34From the programmer's point of view our optimized serialization is slightly more difficult to use (you know, there is no free lunch.) The main difference is that instead of java.io.Serializable a newly introduced interface uka.transport.Transportable has to be implemented. In contrast to java.io.Serializable, the interface uka.transport.Transportable is not empty:
     35
     36{{{
     37#!java
     38package uka.transport;
     39
     40public interface Transportable
     41    extends java.io.Serializable, Cloneable
     42{
     43    // *** object marshaling ***
     44    public void marshal(MarshalStream s)
     45      throws java.io.IOException;
     46
     47    // *** object unmarshaling ***
     48    // public Transportable(UnmarshalStream s)
     49    //   throws java.io.IOException;
     50
     51    public void unmarshalReferences(UnmarshalStream s)
     52      throws java.io.IOException, ClassNotFoundException;
     53
     54    // *** local object copy ***
     55    public Object deepClone(DeepClone _helper)
     56      throws CloneNotSupportedException;
     57}
     58}}}
     59
     60Each class whose objects should be marshaled efficiently must provide an implementation for the methods declared in the Transportable interface. Subclasses of a "transportable" class must override these methods, if they add fields to the base class. If a subclass does not add additional fields, it nevertheless must provide a constructor related to marshaling. For details see below.
     61
     62Usage of the efficient serialization with transportable objects is almost identical to the regular Java serialization. Just replace java.io.OutputStream with uka.transport.MarshalStream and java.io.InputStream with uka.transport.UnmarshalStream. In the following example, please assume that class TParam implements interface uka.transport.Transportable.
     63
     64{{{
     65#!java
     66// Assume: TParam p, InputStream in, OutputStream out
     67//
     68// Writing a transportable object into a stream and reading it back
     69new MarshalStream(out).writeObject(p);
     70TParam q = (TParam) new UnmarshalStream(in).readObject();
     71}}}
     72
     73The following sections will explain how to efficiently implement the methods required by the interface uka.transport.Transportable. If you feel that it is unreasonable to write marshaling code for your classes, please have a look at the bottom of this page: Such marshaling code can be generated automatically.
     74