- Slides: 24
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.
Remote. Command. Invocation. Protocol
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 Object. Input. Stream and Object. Output. Stream 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.
Message Encoder Decoder (previous lecture)
Message Encoder Decoder for arbitrary objects • Previously we saw an implementation for String. • The Object. Encoder. Decoder is a binary encoder decoder. • An Object will be serialized into Byte array: N, b 1, b 2, b 3, . . . , bn • N - the message will start with the number of bytes. • Sent in binary representation (methods int. To. Byte(), byte. To. Int()).
A generic client for our generic protocol
Example: News. Feed. Server • 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 News. Feed:
The client commands receive the News. Feed and manipulate it
News. Feed implementation • Since the news feed can be manipulated concurrently by different handlers in the server it must be thread safe.
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 0 x 134693 F] third client received: [new SPL assignment is out soon!!, THE CAKE IS A LIE!]