The command invocation protocol

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Slide 10.1 Advanced Programming 2004, based on LY Stefanus’s Slides Object Serialization Object serialization: the process of converting an object into.
Chapter 7 Iterators Modified. Chapter Scope The purpose of an iterator The Iterator and Interable interfaces The concept of fail-fast collections Using.
Class Hierarchy II Discussion E. Hierarchy A mail order business sells catalog merchandise all over the country. The rules for taxation on the merchandise.
C# and Windows Programming Application Domains and Remoting.
1 Chapter 8 Three Interfaces: Cloneable, Serializable, and Runnable.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
File-based Persistence: Serializability COMP53 Dec 7, 2007.
Java Iterators interface Collection { … Iterator iterator(); Iterator iterator(); …} interface Set extends Collection { … Iterator iterator(); Iterator.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
Xpath Sources:
Java File I/O (Continued). File I/O in Java Like every other programming language, Java supports the writing to and reading from different files with.
Files and Streams (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Files and Streams 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
JAVA Serializable Java Serialization API The Java platform allows us to create reusable objects in memory. However, all of those objects exist only as.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
15 - RMI. Java RMI Architecture Example Deployment RMI is a part of J2SE (standard edition), but is used by J2EE) A J2EE server is not nessesary for using.
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.
Java Programming: Advanced Topics 1 Input/Output and Serialization Chapter 3.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
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.
Object Serialization. Sequential-access Text Files Sequential-access files store records In order by the record-key field Java imposes no structure on.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
Remote Method Invocation by James Hunt, Joel Dominic, and Adam Mcculloch.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 12 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/ George Koutsogiannakis 1.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
1 Copyright © 2011 Tata Consultancy Services Limited TCS Internal.
Files and Serialization. Files Used to transfer data to and from secondary storage.
CSE 1020: Exceptions and A multiclass application Mark Shtern 1-1.
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
Streams. RHS – SWC 2 Binary files A binary file contains ”raw” bytes that can be interpreted as almost anything Can have any extension Can be created.
Iterators. Chapter Scope The purpose of an iterator The Iterator and Interable interfaces The concept of fail-fast collections Using iterators to solve.
Operating Systems {week 11a}
OBJECT ORIENTED PROGRAMMING II LECTURE 21 GEORGE KOUTSOGIANNAKIS
Topic: Classes and Objects
Networking Serialization
Object Writing in files
Object Serialization in Java
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
University of Central Florida COP 3330 Object Oriented Programming
Memento Design Pattern
Chapter 16 Iterators.
Accessing Files in Java
Client server programming
Programming in Java Files and I/O Streams
CS 116 Object Oriented Programming II
Chapter 7 Iterators.
Working with files.
Chapter 17 Binary I/O Dr. Clincy - Lecture.
Persistence & Bean Properties
The command invocation protocol
Object Serialization Explanation + Example of file + network
CS18000: Problem Solving and Object-Oriented Programming
Command Invocation Protocol
Serializable Objects Serialization is Java’s way of allowing you to write a sequence of bytes representing an object in your program to a file. Deserialization.
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
Java Remote Method Invocation
Lecture 7: RPC (exercises/questions)
Thread per client and Java NIO
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

The command invocation protocol Lecture 14 The command invocation protocol

Generic Protocol We will learn about a generic protocol. Will allow clients to execute remote commands on the server. In previous lectures we have seen:

The protocol A command is sent by a client but executed by the server (on the server process). A class that “packages” a function and arguments. The server may pass a single argument to the command. This argument can hold different services that the command can interract with.

Generic Command Invocation: Life Cycle At Client: Command object is instantiated Command object is serialized into a byte[] int length of byte[] is sent to server (4 bytes) byte[] is sent to server At Server: Data is received at server, byte by byte First 4 bytes are converted to int int size is read and stored in byte[] byte[] is deserialized back into Command object Command object is executed – function returns object Object is serialized into byte[] – this is the response byte[] sent back to client

Java Serialization/De-Serialization

RemoteCommandInvocationProtocol

Java Serialization Object serialization:  an object can be represented as a sequence of bytes. This sequence includes the object's data and type, and the types of data stored in the object. A serialized object (i.e., a byte[]) can be deserialized back into a copy of the original object. The byte[] that represent the object and its data can be used to recreate the object in memory. The process is JVM independent.

Java Serialization Classes ObjectInputStream and ObjectOutputStream can serialize and deserialize any Serializable object. A class is Serializable if it: Implements the Serializable interface or it super class is Serializable. Its first non-serializable super class has a no-args constructor. All its non-transient fields must be serializable. Serializable has no methods or fields. In principle – any data can be serialized.

Java Serialization: Example class Person implements java.io.Serializable { public transient int age; public String name; public Example(int age, String name){ this.age = age; this.name = name; } } To make a class serializable, all needs to be done is to implement: Class <ClassName> implements Serializable{ … } Java will handle the rest! Note: transient will exclude age from the serialization process!

ObjectOutputStream: Example import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.util.Date; public class Main { public static void main(String[] args) throws Exception{ FileOutputStream fos = new FileOutputStream(“file_name"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeInt(12345); oos.writeObject("today"); oos.writeObject(new Date()); oos.close(); } }

ObjectInputStream: Example import java.io.FileInputStream; import java.io.ObjectInputStream; import java.util.Date; public class Main { public static void main(String[] args) throws Exception{ FileInputStream fis = new FileInputStream("file_name"); ObjectInputStream ois = new ObjectInputStream(fis); int i = ois.readInt(); String today = (String) ois.readObject(); Date date = (Date) ois.readObject(); ois.close(); } }

Message Encoder Decoder (previous lecture)

Message Encoder Decoder for arbitrary objects Previously we saw an implementation for String. The ObjectEncoderDecoder is a binary encoder decoder. An Object will be serialized into Byte array: N,b1,b2,b3,...,bn N -  the message will start with the number of bytes. Sent in binary representation (methods intToByte(), byteToInt()).

A generic client for our generic protocol

Example: NewsFeedServer This server will allow clients to execute two commands: Publish news to a (TV) channel by its name Fetch all the news which were published to a specific (TV) channel The main object that is manipulated by the server is the NewsFeed: Command will execute this!

The client commands receive the NewsFeed and manipulate it

NewsFeed implementation Since the news feed can be manipulated concurrently by different handlers in the server it must be thread safe.

A method of ConcurrentHashMap: computeIfAbsent(key, mappingFunction) if (map.get(key) == null) { V newValue = mappingFunction.apply(key); if (newValue != null) map.put(key, newValue); } This is done once per news channel. After its invocation, the specific channel will have an entry in the hashmap, so the consequent executions will have no effect – since not absent!

The server main (thread-per-client…)

The client main

The client code will print: second client received: [System Programmer, knowledge in C++, Java and Python required. call 0x134693F] third client received: [new SPL assignment is out soon!!, THE CAKE IS A LIE!]