uka.transport
Class MarshalStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byuka.transport.BinaryOutputStream
          extended byuka.transport.MarshalStream
All Implemented Interfaces:
java.io.DataOutput, java.io.ObjectOutput, TransportConstants

public class MarshalStream
extends BinaryOutputStream
implements java.io.ObjectOutput, TransportConstants

Author:
Bernhard Haumacher

Nested Class Summary
 class MarshalStream.Bridge
           
 
Field Summary
(package private)  boolean enableReplace
           
private  java.io.DataOutputStream lazy_dout
           
(package private)  IntQueue objectReferences
           
protected  ObjectSpace objectSpace
           
protected  MarshalStream.Bridge oout
           
protected  int oout_id
           
protected  EnlargingIntArray oout_ids
           
protected  boolean oout_init
           
protected  boolean oout_used
           
protected  WireHashtable wireClassTable
           
 
Fields inherited from class uka.transport.BinaryOutputStream
buf, bufcnt, out
 
Fields inherited from interface uka.transport.TransportConstants
REQUEST_MAX, REQUEST_MAX_boolean, REQUEST_MAX_byte, REQUEST_MAX_char, REQUEST_MAX_double, REQUEST_MAX_float, REQUEST_MAX_int, REQUEST_MAX_long, REQUEST_MAX_short, SIZEOF_boolean, SIZEOF_byte, SIZEOF_char, SIZEOF_double, SIZEOF_float, SIZEOF_int, SIZEOF_long, SIZEOF_short, TC_ANONYMOUS, TC_DEFAULT, TC_EXCEPTION, TC_NEW, TC_NULL, TC_REFERENCE, TC_REPLACEMENT, TC_RESET, TC_RESETTYPE, TC_TYPE, TC_USER
 
Constructor Summary
MarshalStream(java.io.OutputStream out)
           
 
Method Summary
protected  boolean enableReplaceObject(boolean enable)
           
private  java.io.DataOutputStream getDataOutputStream()
           
private  void internalWriteObject(java.lang.Object obj, int id, java.lang.Class type)
           
protected  java.lang.Object replaceObject(java.lang.Object obj)
           
 ObjectSpace setObjectSpace(ObjectSpace objectSpace)
          An object space is a translation from objects to identifiers.
 void symmetricReset()
           
 void symmetricResetType()
           
 void writeAnonymous(java.lang.Object obj)
           
 void writeBytes(java.lang.String data)
           
private  void writeNew(int id, java.lang.Class type, TransportDescriptor descriptor, java.lang.Object obj)
           
private  void writeNull()
           
 void writeObject(java.lang.Object root)
          Marshal an object and all objects that are (transitively) referenced from that object.
private  void writeReference(int id, java.lang.Object obj)
           
 void writeReference(java.lang.Object obj)
          Marshal an object reference.
private  void writeSerializable(int id, java.lang.Object obj)
           
protected  void writeStreamHeader()
           
private  void writeType(java.lang.Class type)
           
 void writeUTF(java.lang.String data)
           
 
Methods inherited from class uka.transport.BinaryOutputStream
close, deliver, drain, flush, getBuffer, getPosition, reserve, write, write, write, writeBoolean, writeByte, writeChar, writeChars, writeDouble, writeFloat, writeHugeBooleanArray, writeHugeByteArray, writeHugeCharArray, writeHugeDoubleArray, writeHugeFloatArray, writeHugeIntArray, writeHugeLongArray, writeHugeShortArray, writeInt, writeLong, writeShort, writeUnsignedByte, writeUnsignedShort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.ObjectOutput
close, flush, write, write, write
 
Methods inherited from interface java.io.DataOutput
writeBoolean, writeByte, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort
 

Field Detail

oout

protected MarshalStream.Bridge oout

oout_init

protected boolean oout_init

oout_used

protected boolean oout_used

oout_ids

protected EnlargingIntArray oout_ids

oout_id

protected int oout_id

objectSpace

protected ObjectSpace objectSpace

wireClassTable

protected final WireHashtable wireClassTable

objectReferences

IntQueue objectReferences

enableReplace

boolean enableReplace

lazy_dout

private java.io.DataOutputStream lazy_dout
Constructor Detail

MarshalStream

public MarshalStream(java.io.OutputStream out)
              throws java.io.IOException
Method Detail

setObjectSpace

public ObjectSpace setObjectSpace(ObjectSpace objectSpace)

An object space is a translation from objects to identifiers. In normal operation, these identifiers are used to address objects that were already transmitted through this stream. When marshaling object graphs with cycles, only an object is only transmitted the first time it is encountered. For each further reference to the same object only its identifier is marshaled. In other words, an object identifier is the wire representation of an object reference.

By installing a custom translation between objects and identifiers, this mapping survives the current marshaling process. When installing the same mapping into a future MarshalStream, objects that were transmitted in the first marshaling process can be referenced in the second one without again marshaling them. Replicated objects heavily depend on this feature.

Returns:
the previously installed object space.

symmetricReset

public void symmetricReset()
                    throws java.io.IOException
Throws:
java.io.IOException

symmetricResetType

public void symmetricResetType()
                        throws java.io.IOException
Throws:
java.io.IOException

writeNull

private void writeNull()
                throws java.io.IOException
Throws:
java.io.IOException

writeReference

private void writeReference(int id,
                            java.lang.Object obj)
                     throws java.io.IOException
Throws:
java.io.IOException

writeNew

private void writeNew(int id,
                      java.lang.Class type,
                      TransportDescriptor descriptor,
                      java.lang.Object obj)
               throws java.io.IOException
Throws:
java.io.IOException

writeSerializable

private void writeSerializable(int id,
                               java.lang.Object obj)
                        throws java.io.IOException
Throws:
java.io.IOException

writeObject

public final void writeObject(java.lang.Object root)
                       throws java.io.IOException
Marshal an object and all objects that are (transitively) referenced from that object. This method should be called from the application to marshal an object.

Specified by:
writeObject in interface java.io.ObjectOutput
Throws:
java.io.IOException

writeReference

public final void writeReference(java.lang.Object obj)
                          throws java.io.IOException
Marshal an object reference. This method only marshals information that is necessary to construct an object of the same type at the receiving side. This method exclusively called from within the Transportable.marshal(uka.transport.MarshalStream) method.

Throws:
java.io.IOException

writeAnonymous

public void writeAnonymous(java.lang.Object obj)
                    throws java.io.IOException
Throws:
java.io.IOException

internalWriteObject

private void internalWriteObject(java.lang.Object obj,
                                 int id,
                                 java.lang.Class type)
                          throws java.io.IOException
Throws:
java.io.IOException

writeType

private void writeType(java.lang.Class type)
                throws java.io.IOException
Throws:
java.io.IOException

enableReplaceObject

protected boolean enableReplaceObject(boolean enable)
                               throws java.lang.SecurityException
Throws:
java.lang.SecurityException

replaceObject

protected java.lang.Object replaceObject(java.lang.Object obj)
                                  throws java.io.IOException
Throws:
java.io.IOException

writeStreamHeader

protected void writeStreamHeader()
                          throws java.io.IOException
Throws:
java.io.IOException

getDataOutputStream

private java.io.DataOutputStream getDataOutputStream()

writeBytes

public void writeBytes(java.lang.String data)
                throws java.io.IOException
Specified by:
writeBytes in interface java.io.DataOutput
Overrides:
writeBytes in class BinaryOutputStream
Throws:
java.io.IOException

writeUTF

public void writeUTF(java.lang.String data)
              throws java.io.IOException
Specified by:
writeUTF in interface java.io.DataOutput
Overrides:
writeUTF in class BinaryOutputStream
Throws:
java.io.IOException