org.objectweb.carol.irmi
Class RMIObjectOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.ObjectOutputStream
          extended byorg.objectweb.carol.irmi.RMIObjectOutputStream
All Implemented Interfaces:
DataOutput, ObjectOutput, ObjectStreamConstants

public class RMIObjectOutputStream
extends ObjectOutputStream

RMIObjectOutputStream is a specialized subclass of ObjectOutputStream used by this RMI implementation. It must be used in concert with RMIObjectInputStream. Specialized behavior includes class annotation using RMIClassLoader, automatic conversion of Remote objects to stubs, caching of class descriptors accross calls to ObjectOutputStream.reset(), and output buffering.

Author:
Rafael H. Schloming <rhs@mit.edu>

Nested Class Summary
 
Nested classes inherited from class java.io.ObjectOutputStream
ObjectOutputStream.PutField
 
Field Summary
 
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
 
Constructor Summary
RMIObjectOutputStream(OutputStream out)
          Constructs a new RMIObjectOutputStream that writes to the given OutputStream.
 
Method Summary
protected  void annotateClass(Class cl)
          Implementation of the ObjectOutputStream.annotateClass(Class) callback.
protected  void annotateProxyClass(Class cl)
          Implementation of the ObjectOutputStream.annotateProxyClass(Class cl) callback.
protected  Object replaceObject(Object obj)
          Implementation of the ObjectOutputStream.replaceObject(Object) callback.
protected  void writeClassDescriptor(ObjectStreamClass desc)
          Implementation of the ObjectOutputStream.writeClassDescriptor(ObjectStreamClass) callback.
protected  void writeStreamHeader()
          Implementation of the ObjectOutputStream.writeStreamHeader() callback.
 
Methods inherited from class java.io.ObjectOutputStream
close, defaultWriteObject, drain, enableReplaceObject, flush, putFields, reset, useProtocolVersion, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFields, writeFloat, writeInt, writeLong, writeObject, writeObjectOverride, writeShort, writeUnshared, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RMIObjectOutputStream

public RMIObjectOutputStream(OutputStream out)
                      throws IOException
Constructs a new RMIObjectOutputStream that writes to the given OutputStream.

Parameters:
out - the OutputStream to use for output
Method Detail

annotateClass

protected void annotateClass(Class cl)
                      throws IOException
Implementation of the ObjectOutputStream.annotateClass(Class) callback. This implementation delegates to RMIClassLoader.

Parameters:
cl - the Class to annotate
Throws:
IOException - when there is an error with the underlying stream

annotateProxyClass

protected void annotateProxyClass(Class cl)
                           throws IOException
Implementation of the ObjectOutputStream.annotateProxyClass(Class cl) callback. This implementation defers to annotateClass(Class).

Parameters:
cl - the Class to annotate
Throws:
IOException - when there is an error with the underlying stream

replaceObject

protected Object replaceObject(Object obj)
Implementation of the ObjectOutputStream.replaceObject(Object) callback. This implementation converts Remote objects to stubs if necessary.

Parameters:
obj - the object being considered for serialization
Returns:
the object to be serialized

writeClassDescriptor

protected void writeClassDescriptor(ObjectStreamClass desc)
                             throws IOException
Implementation of the ObjectOutputStream.writeClassDescriptor(ObjectStreamClass) callback. This implementation delegates to the superclass if this descripter has not already been written to the output stream, otherwise it sends an integer id referencing the previously written class.

Parameters:
desc - the ObjectStreamClass to write
Throws:
IOException - if there is an error with the underlying stream

writeStreamHeader

protected void writeStreamHeader()
Implementation of the ObjectOutputStream.writeStreamHeader() callback. This implementation is specifically overriden to do nothing because both the ObjectOutputStream.writeStreamHeader() and ObjectInputStream.readStreamHeader() callbacks are invoked from each class' respective constructor. This introduces a potentially non obvious side effect when constructing new stream objects in a client server context since the ObjectInputStream constructor will block waiting for input and this can cause deadlock if the ObjectInputStream is constructed first on both the client and server ends.