Presentation is loading. Please wait.

Presentation is loading. Please wait.

The command invocation protocol

Similar presentations


Presentation on theme: "The command invocation protocol"— Presentation transcript:

1 The command invocation protocol
Lecture 14 The command invocation protocol

2 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:

3 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.

4 RemoteCommandInvocationProtocol

5 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.

6 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.

7 Message Encoder Decoder (previous lecture)

8 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()).

9

10

11

12

13 A generic client for our generic protocol

14

15 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:

16 The client commands receive the NewsFeed and manipulate it

17

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

19

20 The server main (thread-per-client…)

21 The client main

22

23

24 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!]


Download ppt "The command invocation protocol"

Similar presentations


Ads by Google