Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Chapter 4 Communication.

Similar presentations


Presentation on theme: "Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Chapter 4 Communication."— Presentation transcript:

1 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Chapter 4 Communication (2) DISTRIBUTED SYSTEMS (dDist) 2012

2 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Plan (Java) Technology –Berkeley Sockets –Java Sockets –Java Remote Method Invocation (RMI) –Java Message Service (JMS)

3 Application Communication Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 1 2 3 4 1 2 3 4 Goal: Establish a connection to service known to run on port 4 Servers (and clients) have a number of ports (2 16 ) Typically services run on known ports (web: 80) Service Application

4 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Berkeley Sockets Figure 4-14. The socket primitives for TCP/IP.

5 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Berkeley Sockets socket type bind address + port socket type connect address + port listenaccept read write close Server side Client side write

6 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Java Sockets ss = new ServerSocket portSocket s = ss.accept() s = new Socket address + port s.getInputStream().read close Server side Client side s.getOutputStream().write s.getInputStream().read

7 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 A Simple Client and Server

8 TCP UDP Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Java Socket Hierarchy

9 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Java RMI Java allows to call methods on objects running on other Java virtual machines Parameters implementing are passed by reference –Known as remote objects Objects which are not remote but which implement are passed by value Other objects, like file descriptors, cannot be passed as parameters

10 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Remote Interface A remote interface is a Java interface which extends the interface – is a tagging interface, i.e., used only to tell that the sub-interface is a remote interface

11 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Remote Objects (1/2) Objects which implement a remote interface are known as remote objects When a remote object is passed to another JVM only a stub is passed Calling a method on the stub will do a remote call to the JVM where the remote object is really running Only methods declared in the remote interface of the object are available in the stub

12 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Remote Objects (2/2) To implement behavior needed by remote objects, remote objects should at least extend the class –Handles hashCode and equals and toString semantics for remote objects For remote objects which should not be replicated, one typically implements the sub-class –Handles how the object is made remove, like how it receives calls back and the stub code

13 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 RMI Registry A Java program can put (stubs for) its remote objects into a local RMI Registry under some name like “dDistCalculator” –Just a simple database Java programs on other machines can then retrieve a stub for the remote object from the RMI Registry on the machine where the stubs were stored Gives an easy-to-use way to have RMI servers and RMI clients meet

14 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 A Remote Interface

15 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 A Remote Class

16 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Using a Remote Object

17 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Starting the RMI Registry On port 40499 on machine camel17.cs.au.dk

18 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Starting the Server Also on machine camel17.cs.au.dk

19 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Running the Client On machine camel00.cs.au.dk

20 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Running the Client On machine camel01.cs.au.dk

21 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Java Message Service A specification for a message queue and message broker framework –JMS queue: A point-to-point queue Not really a queue. Only guaranteed that all message are received once and only once –JMS producer: Puts messages in a JMS queue –JMS consumer: Takes messages from a JMS queue –JMS topic: A way to send messages to several receivers –JMS publisher: Creates JMS topics and publishes messages under the topic –JMS subscriber: Registers on a given topic and after that receivers all messages published on the subject –Durable subscription: If a subscriber goes offline it will receive all intermediary messages on the topic after going online again Non-durable: Receivers only while online

22 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Apache ActiveMQ An OpenSource implementation of JMS –Widely used in industry Communication pattern: –Asynchronous –Loosely coupled –Persistent Can use any database as the persistence provider –Reliable Can handle crashing senders and receivers and still maintain a sound semantics of multicast (much more on this topic later) We will not do exercises in using ActiveMQ, but good to know that implementations exists A tutorial on ActiveMQ can be found on the homepage –Suggested reading only


Download ppt "Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Chapter 4 Communication."

Similar presentations


Ads by Google