Serialization 4: Serializable refresh Review of Java Object Serialization and Relationship with RMI-IIOP June 25, 2002.

Slides:



Advertisements
Similar presentations
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Serialization Flatten your object for automated storage or network.
Advertisements

Slide 10.1 Advanced Programming 2004, based on LY Stefanus’s Slides Object Serialization Object serialization: the process of converting an object into.
Exception Handling1. 2 Exceptions  Definition  Exception types  Exception Hierarchy  Catching exceptions  Throwing exceptions  Defining exceptions.
15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Object-Oriented Programming: Inheritance Deitel &Deitel Java SE 8.
Object Serialization in Java Or: The Persistence of Memory…
Java Iterators interface Collection { … Iterator iterator(); Iterator iterator(); …} interface Set extends Collection { … Iterator iterator(); Iterator.
1 Java Object Model Part 1. 2 Type Definition: set of values – a set of values and set of operations –a set of operations that can be applied to those.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
Architecture of Software Systems RMI and Distributed Components Martin Rehák.
The Java Programming Language
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
Java I/O Writing and Reading Objects to File Serialization.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Object Persistence and Object serialization CSNB534 Asma Shakil.
RMI Continued IS Outline  Review of RMI  Programming example.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Copyright(c) Systems and Computer Engineering, Carleton Univeristy, * Object-Oriented Software Development Unit 13 I/O Stream Hierarchy Case.
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
IBM TSpaces Lab 2 Customizing tuples and fields. Summary Blocking commands Tuple Expiration Extending Tuples (The SubclassableTuple) Reading/writing user.
Serialization CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 12 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/ George Koutsogiannakis 1.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
1 Copyright © 2011 Tata Consultancy Services Limited TCS Internal.
Files and Serialization. Files Used to transfer data to and from secondary storage.
Simple Java I/O Part I General Principles. Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for.
XSLT in Practice. Exercises  download Apache Xalan - install it - try the example in Xalan-Java Overview  ZVON XSLT Tutorial.
1 CSE 331 Memento Pattern and Serialization slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Serialization 2: Valuetype Code
OBJECT ORIENTED PROGRAMMING II LECTURE 21 GEORGE KOUTSOGIANNAKIS
Inner Classes.
Topic: Inner Classes Course : JAVA PROGRAMMING Paper Code: ETCS-307 Faculty : Dr. Prabhjot Kaur Reader, Dept. of IT 1.
Inner Classes 27-Dec-17.
Summary prepared by Kirk Scott
Lecture 20 File I/O D&D 14 Date.
CSC 243 – Java Programming, Spring 2014
Logger, Assert and Invariants
Object Serialization in Java
Java Distributed Computing
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Creating and Modifying Text part 2
Remote Method Invocation
Testing and Exceptions
Exceptions 10-Nov-18.
Java Programming Language
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
Serialization and Deserialization Bullet points from Head First Java, Ch Dec-18 serialization.ppt.
CSE 331 Memento Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
OBJECT ORIENTED PROGRAMMING II LECTURE 22 GEORGE KOUTSOGIANNAKIS
Podcast Ch23f Title: Serialization
CSC 220 – Processing Spring, 2017
Interfaces.
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 11-May-19.
Exceptions 10-May-19.
Inner Classes 18-May-19.
Java Remote Method Invocation
LCC 6310 Computation as an Expressive Medium
slides created by Ethan Apter
Exceptions and networking
OO Java Programming Input Output.
Inner Classes 25-Oct-19.
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Serialization 4: Serializable refresh Review of Java Object Serialization and Relationship with RMI-IIOP June 25, 2002

java.io.Serializable ● Order of serialization: top down ● writeObject/readObject ● PutField/GetField ● writeReplace/readResolve ● serialVersionUID ● serialPersistantFields ● defaultWriteObject/defaultReadObject

Example 1 // Version 0 public class UserData implements Serializable { private String userName; } Future versions of the class which strive to interoperate must include the original version's serialVersionUID. (JDK/bin/serialver tool) It's also hard to compute and may change depending on compiler sensitivity to inner classes (talk to Bob Scheifler, etc), so putting it in when you define the class in the first place is best. // Better version 0 public class UserData implements Serializable { private static final long serialVersionUID = L; private String userName; }

// Version 1 public class UserData implements Serializable { private static final long serialVersionUID = L; // Fields will be serialized in a special order, not // necessarily order of definition private String userName; private long dateOfBirth; } // Version 2 public class UserData implements Serializable { private static final long serialVersionUID = L; private String userName; private long dateOfBirth; private transient String homeTown; private void writeObject(ObjectOutputStream oos) throws IOException { // defaultWriteObject only writes THIS type's data (superclass // and subclass data is written separately by the ObjectOutputStream // in order) oos.defaultWriteObject(); oos.writeUTF(homeTown); } private void readObject(ObjectInputStream ois) throws... { oos.defaultReadObject(); try { homeTown = oos.readUTF(); } catch (Exception ex) { homeTown = "Unknown, USA"; }

// Version 3 public class UserData implements Serializable { private static final long serialVersionUID = L; private String firstName; private String lastName; private long dateOfBirth; private String homeTown; private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("userName", String.class), new ObjectStreamField("dateOfBirth", Long.TYPE), }; private void writeObject(ObjectOutputStream oos) throws IOException { ObjectOutputStream.PutField fields = oos.putFields(); fields.put("userName", firstName + ' ' + lastName); fields.put("dateOfBirth", dateOfBirth); // Note: Do not wrap primitives oos.writeFields(); oos.writeUTF(homeTown); } private void readObject(ObjectInputStream ois) throws... { ObjectInputStream.GetField fields = ois.readFields(); String userName = (String)fields.get("userName", null); splitIntoFirstNameAndLastName(userName); dateOfBirth = (long)fields.get("dateOfBirth",(long)0); try { homeTown = oos.readUTF(); } catch (Exception ex) { homeTown = "Unknown, USA"; }

Evolution Notes ● Lots of rules for compatible/incompatible changes ● Arun built a test of all basic changes including writeObject/readObject, but it took weeks to run, so hasn't been run in a year. About 10 classes were taken as a quick look matrix. ● We haven't tested writeReplace/readResolve very much ● We haven't tested inner classes and inner class evolution ● We haven't tested evolving superclasses very much ● We haven't tested optional data semantics very much ●

Evolution & RMI-IIOP ● Java Serialization includes all type information on the wire. RMI- IIOP doesn't, so to handle evolution, must use the callback Codebase object. Some want a new RMI-IIOP stream version in which a TypeCode is sent with the valuetype giving all info. ● Codebase IOR exchanged via SendingContext Runtime service context. ● Codebase "meta" method query results in information represented by a FullValueDescriptor including ValueMembers and TypeCodes which are then used to compare the remote and local versions. ● We have sketchy TypeCode and comparison code

CDROutputStream write_value write_value First handles nulls, indirections, IDL ValueBases, IDLEntity types, Strings, and Classes (Strings and Classes are special cases of RMI-IIOP types) if it wasn't one of the above, it must be an RMI-IIOP valuetype: 1. Let the ValueHandler perform a writeReplace 2. Must make sure that if the object is different, it isn't a null, indirection, etc. 3. If ValueHandler says isCustomMarshaled, then make sure to set the chunking bit in the valuetag and start chunking 4. Hand control to ValueHandler's writeValue 5. Stop chunking 6. Write end tag

CDRInputStream read_value read_value First handles nulls and indirections. 0. If valuetag indicates chunking was used, must start chunking. 1. Based on repository ID(s) and possible expected type argument, must determine the class that was serialized. 2. Handles WstringValue and Class as special cases 3. Handles IDLEntity types 4. Gives control to ValueHandler to readValue 5. If chunking, should skip over any unread data and process the end tag

RMI-IIOP Problems In RMI-IIOP, as in Java Object Serialization, data is serialized from superclass down. However, unlike Java Object Serialization, RMI-IIOP stream format version 1 didn't have any indicators to let the reader know where a superclass's data ended and the next subclass's data began. This was fine unless the superclass had evolved to write optional data. With optional data, even querying the remote FVD won't help - - nothing about the remote class's structure itself can tell you what's on the wire. An unevolved reader would need to be able to skip data until the next class boundary, but there are no class boundaries... all the data is together. Thus, stream format version 2 was born...