Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Applications Using RMI Lesson 1B / Slide 1 of 19 Network and Distributed Programming in Java Pre-assessment Questions 1.Which of the following.

Similar presentations


Presentation on theme: "Creating Applications Using RMI Lesson 1B / Slide 1 of 19 Network and Distributed Programming in Java Pre-assessment Questions 1.Which of the following."— Presentation transcript:

1 Creating Applications Using RMI Lesson 1B / Slide 1 of 19 Network and Distributed Programming in Java Pre-assessment Questions 1.Which of the following refers to the component-based approach of creating distributed applications? a.Two-tier architecture b.Three-tier architecture c.Monolithic architecture d.Single-tier architecture 2. Which of the following is NOT true for RMI? a.RMI is a specification that enables one JVM to invoke methods of an object located in another JVM. b.RMI is implemented on the middle-tier of the three-tier architecture framework. c.RMI application run on cross-platform specification. d.RMI supports cross-language specification.

2 Creating Applications Using RMI Lesson 1B / Slide 2 of 19 Network and Distributed Programming in Java Pre-assessment Questions 3. RMI registry is a _____. a.Server b.Client c.Middle-tier d.Service 4.Which of the following services is provided by the transport layer in the RMI architecture? a.Creating the connection between the client and server b.Creating the server objects c.Registering the server object d.Invoking the remote method

3 Creating Applications Using RMI Lesson 1B / Slide 3 of 19 Network and Distributed Programming in Java Pre-assessment Questions 5. Which system property controls the lease time? a.java.rmi.dgc.lease.clean b.javax.rmi.dgc.leaseValue c.java.rmi.dgc.leaseValue d.java.rmi.dgc.lease.dirty

4 Creating Applications Using RMI Lesson 1B / Slide 4 of 19 Network and Distributed Programming in Java Solutions to Pre-assessment Questions 1. b. Three-tier Architecture 2. d. RMI supports cross-language specification. 3. d. Service 4. a. Creating the connection between the client and server 5. c. java.rmi.dgc.leaseValue

5 Creating Applications Using RMI Lesson 1B / Slide 5 of 19 Network and Distributed Programming in Java Objectives In this lesson, you will learn about: Transmit files using RMI Create application using client-side callbacks

6 Creating Applications Using RMI Lesson 1B / Slide 6 of 19 Network and Distributed Programming in Java Demonstration-Transmitting Files Using RMI Problem Statement Create a distributed application using RMI, where an RMI client can download a file (plain text or binary) from the RMI server.

7 Creating Applications Using RMI Lesson 1B / Slide 7 of 19 Network and Distributed Programming in Java Demonstration-Transmitting Files Using RMI (Contd.) Solution The steps to create the distributed application using RMI are: 1.Create the FileRemote interface for the RMI server. 2.Create the FileRemoteImpl class that implements the FileRemote interface. 3.Create the RMIFileServer class. 4.Create the RMIFileClient class. 5.Run the application.

8 Creating Applications Using RMI Lesson 1B / Slide 8 of 19 Network and Distributed Programming in Java Client-Side Callbacks In client-side callbacks: The RMI server invokes the method of the RMI client. The RMI client acts as an RMI server. The RMI client extends the UnicastRemoteObjcet class.

9 Creating Applications Using RMI Lesson 1B / Slide 9 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) Creating an Application using Client-Side Callbacks 1.Create a remote interface for the client 2.Create a remote interface for the server 3.Implement the server interface 4.Implement the client interface 5.Create an RMI server 6.Create an RMI client 7.Run the client and server applications

10 Creating Applications Using RMI Lesson 1B / Slide 10 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 1.Creating Remote Interface for the Client The code to create a remote interface for the RMI client is: public interface CRemote extends Remote { public void displayValue(String s) throws RemoteException; }

11 Creating Applications Using RMI Lesson 1B / Slide 11 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 2.Creating Remote Interface for the Server The code to create a remote interface for the RMI server is: public interface SRemote extends Remote { public void registerClient(CRemote c) throws RemoteException; public CRemote getCallback() throws RemoteException; }

12 Creating Applications Using RMI Lesson 1B / Slide 12 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 3.Implementing the Server Interface The code snippet to implement the server interface is: public class SRemoteImpl extends SRemote {public void registerClient(CRemote c) throws RemoteException {...... } public CRemote getCallback() throws RemoteException {...... }

13 Creating Applications Using RMI Lesson 1B / Slide 13 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 4.Implementing the Client Interface The code snippet to implement the client interface is: public class CRemoteImpl extends CRemote { public void displayvalue(String s) throws RemoteException {...... }

14 Creating Applications Using RMI Lesson 1B / Slide 14 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 5.Creating an RMI Server The code snippet to create the RMI server is: public class CallbackServer { public static void main (String args []) throws Exception { SRemote b = new SRemoteImpl(); UnicastRemoteObjcet.exportObjcet(b); Naming.rebind(“callback”, b); }

15 Creating Applications Using RMI Lesson 1B / Slide 15 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 6.Creating an RMI Client The code snippet to create the RMI client is: public class CallbackClient { public static void main (String args []) throws Exception { CallbackS = (SRemote)Naming.lookup(“rmi://192.168.0.52/callback”); CallbackC = callbackS.getCallback(); UnicastRemoteObjcet.exportObjcet(callbackC); callbackS.registerClient(callbackC); }

16 Creating Applications Using RMI Lesson 1B / Slide 16 of 19 Network and Distributed Programming in Java Client-Side Callbacks (Contd.) 7.Running the Application The steps to run an RMI application using client-side callbacks are: 1.Compile all the Java source files. javac *.java 2.Generate the stub and skeleton for the RMI server. rmic SRemoteImpl 3.Generate the stub and skeleton for the RMI client. rmic CRemoteImpl 4.Start the RMI registry. start rmiregistry 5.Run the server-side application. java CallbackServer 6.Run the client-side application. java CallbackClient

17 Creating Applications Using RMI Lesson 1B / Slide 17 of 19 Network and Distributed Programming in Java Demonstration-Implementing a Chat Application Problem Statement Create a chat application using RMI where an RMI server receives a message from one client and sends that message to all other clients.

18 Creating Applications Using RMI Lesson 1B / Slide 18 of 19 Network and Distributed Programming in Java Demonstration-Implementing a Chat Application (Contd.) Solution The steps to create the chat application using RMI are: 1.Create the ServerRemote interface for the chat server 2.Create the ClientRemote interface for the chat client. 3.Create the ChatServer class that implements the ServerRemote interface. 4.Create the ChatClient class that implements the ClientRemote interface. 5.Run the chat application.

19 Creating Applications Using RMI Lesson 1B / Slide 19 of 19 Network and Distributed Programming in Java Summary In this lesson, you learned that: You use serialization to convert a set of objects into byte streams. The byte streams can be sent from one JVM to another JVM. When the RMI server calls back a remote method, such as progress feedback, or an alert message to the RMI client, these method calls are called client-side callbacks. The RMI client calls the exportObject() method of java.rmi.server.UnicastRemoteObject class to allow the RMI server to perform client side callbacks.


Download ppt "Creating Applications Using RMI Lesson 1B / Slide 1 of 19 Network and Distributed Programming in Java Pre-assessment Questions 1.Which of the following."

Similar presentations


Ads by Google