import java.io.*; public class Customer implements Serializable { public Customer(int theAge, int theSex, String[] theHobbies) { age = theAge; sex.

Slides:



Advertisements
Similar presentations
Remote method invocation. Introduction First introduced in JDK 1.1. Allows distributed Java programs to work with each others by behaving as if they are.
Advertisements

Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
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.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Introduction to Remote Method Invocation (RMI)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Lecture 19 Graphics User Interfaces (GUIs)
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
Java Computing 6. RMI By Dr. Jiang B. Liu
Internet Software Development Remote Method Invocation Paul Krause.
By Dr. Jiang B. Liu 3. Graphic User Interface using AWT.
Slides for Chapter 5: Communication between distributed objects
Io package as Java’s basic I/O system continue’d.
JAVA - Network DUT Info - Option ISI (C) Philippe Roose , 2005.
1 Java Programming II Java Network II (Distributed Objects in Java)
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
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.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
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.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Event Handling Mohanraj S AP / IT Angel College of Engg & Tech.,
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
CS100A, Fall Lecture, 4 Nov. 1 CS100A, Fall 1997 Lecture 4 November: OTHELLO Goals: Introduce you to assignment 8. Let you have fun with the game.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Event Driven Programming. Event-driven Programming In the early days of computing communication with the outside world was accomplished using a technique.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Computer Science 209 GUIs Model/View/Controller Layouts.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Ch15 簡單計算機 物件導向系統實務. Ch22_Main.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class Ch22_Main { public static void main(String.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
RMI Example. Compilation: /home2/fccheng/temp/RMI2> javac MyObject.java /home2/fccheng/temp/RMI2> javac RemoteServer.java /home2/fccheng/temp/RMI2> javac.
Slides for Chapter 5: Distributed objects and remote invocation From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
Khoa CNTT 1/37 PHẠM VĂN TÍNH   Java RMI (Remote Method Invocation)
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Esercizio RMI. Server import java.io.*; class Item implements Serializable { private String category, itemNumber, descr; private int value, cost, bidder,
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
第十一讲 分布式编程 Socket and RMI 李庆旭. 2 本章内容提要  Socket TCP /IP protocol suit Socket A TCP Server and a TCP Client Supporting Multiple Concurrent Clients A UDP.
Netprog Java RMI1 Remote Method Invocation.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Graphical User Interfaces -- GUIs
GUIs Model/View/Controller Layouts
Remote Method Invocation
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Java RMI (more) CS-328 Internet Programming.
null, true, and false are also reserved.
Slides for Chapter 5: Distributed objects and remote invocation
Remote method invocation (RMI)
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Java Remote Method Invocation
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

import java.io.*; public class Customer implements Serializable { public Customer(int theAge, int theSex, String[] theHobbies) { age = theAge; sex = theSex; hobbies = theHobbies; } public int getAge() { return age; } public int getSex() { return sex; } public boolean hasHobby(String aHobby) { if (aHobby == "") return true; for (int i = 0; i < hobbies.length; i++) if (hobbies[i].equals(aHobby)) return true; return false; }

public void reset() { age = 0; sex = 0; hobbies = null; } public String toString() { String result = "Age: " + age + ", Sex: "; if (sex == Product.MALE) result += "Male"; else if (sex == Product.FEMALE) result += "Female"; else result += "Male or Female"; result += ", Hobbies:"; for (int i = 0; i < hobbies.length; i++) result += " " + hobbies[i]; return result; } private int age; private int sex; private String[] hobbies; }

import java.rmi.*; public interface Product extends Remote { String getDescription() throws RemoteException; static final int MALE = 1; static final int FEMALE = 2; static final int BOTH = MALE + FEMALE; }

import java.rmi.*; import java.rmi.server.*; public class ProductImpl extends UnicastRemoteObject implements Product { public ProductImpl(String n, int s, int age1, int age2, String h) throws RemoteException { name = n; ageLow = age1; ageHigh = age2; sex = s; hobby = h; } public boolean match(Customer c) // local method { if (c.getAge() ageHigh) return false; if (!c.hasHobby(hobby)) return false; if ((sex & c.getSex()) == 0) return false; return true; }

public String getDescription() throws RemoteException { return "I am a " + name + ". Buy me!"; } private String name; private int ageLow; private int ageHigh; private int sex; private String hobby; }

import java.awt.*; import java.awt.event.*; import java.io.*; import java.rmi.*; import java.rmi.server.*; import java.util.*; import javax.swing.*; public class WarehouseClient { public static void main(String[] args) { JFrame frame = new WarehouseClientFrame(); frame.show(); }

class WarehouseClientFrame extends JFrame implements ActionListener { public WarehouseClientFrame() { initUI(); System.setSecurityManager(new RMISecurityManager()); try { Properties props = new Properties(); String fileName = "WarehouseClient.properties"; FileInputStream in = new FileInputStream(fileName); props.load(in); String url = props.getProperty("warehouse.url"); if (url == null) url = "rmi://localhost/central_warehouse"; centralWarehouse = (Warehouse)Naming.lookup(url); } catch(Exception e) { System.out.println("Error: Can't connect to warehouse. " + e); }

private void callWarehouse(Customer c) { try { Vector recommendations = centralWarehouse.find(c); result.setText(c + "\n"); for (int i = 0; i < recommendations.size(); i++) { Product p = (Product)recommendations.get(i); String t = p.getDescription() + "\n"; result.append(t); } catch(Exception e) { result.setText("Error: " + e); }

public void actionPerformed(ActionEvent evt) { Object[] hobbyObjects = hobbies.getSelectedValues(); String[] hobbyStrings = new String[hobbyObjects.length]; System.arraycopy(hobbyObjects, 0, hobbyStrings, 0, hobbyObjects.length); Customer c = new Customer(Integer.parseInt(age.getText()), (male.isSelected() ? Product.MALE : 0) + (female.isSelected() ? Product.FEMALE : 0), hobbyStrings); callWarehouse(c); } private void initUI() { setTitle("WarehouseClient"); setSize(300, 300); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); getContentPane().setLayout(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 100; gbc.weighty = 0; add(new JLabel("Age:"), gbc, 0, 0, 1, 1); age = new JTextField(4); age.setText("20"); add(age, gbc, 1, 0, 1, 1); male = new JCheckBox("Male", true); female = new JCheckBox("Female", true); add(male, gbc, 0, 1, 1, 1); add(female, gbc, 1, 1, 1, 1); gbc.weighty = 100; add(new JLabel("Hobbies"), gbc, 0, 2, 1, 1); String[] choices = { "Gardening", "Beauty", "Computers", "Household", "Sports" }; gbc.fill = GridBagConstraints.BOTH; hobbies = new JList(choices); add(new JScrollPane(hobbies), gbc, 1, 2, 1, 1);

gbc.weighty = 0; gbc.fill = GridBagConstraints.NONE; JButton submitButton = new JButton("Submit"); add(submitButton, gbc, 0, 3, 2, 1); submitButton.addActionListener(this); gbc.weighty = 100; gbc.fill = GridBagConstraints.BOTH; result = new JTextArea(4, 40); result.setEditable(false); add(result, gbc, 0, 4, 2, 1); } private void add(Component c, GridBagConstraints gbc, int x, int y, int w, int h) { gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; getContentPane().add(c, gbc); }

private Warehouse centralWarehouse; private JTextField age; private JCheckBox male; private JCheckBox female; private JList hobbies; private JTextArea result; }

RMI Callbacks Server Calls Back the Client True Peer-to-Peer Interaction Client itself must be exportable remote object Registered with a remote server

Example Quote Client/Server Server maintains a list of quotes Client makes additions to list of quotes Callback used to allow server to asynchronously update clients with list of quotes

Steps Specify Remote Server Interface Specify Remote Client Interface Develop Remote-server object Develop Client Compile Run