Јава - RMI Дизајн симулатора дискретних догађаја опште намене обухвата пројектовање више различитих структурних нивоа. Унутар сваког од структурних нивоа.

Slides:



Advertisements
Similar presentations
Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
Advertisements

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.
Distributed Objects and Remote Invocation: RMI & CORBA Most concepts are drawn from Chapter 5 © Pearson Education Dr. Rajkumar Buyya and Xingchen Chu Grid.
© 2001 Marty Hall, Larry Brown Web core programming 1 Remote Method Invocation.
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.
Java RMI. What is RMI? RMI is an RPC system for an object based language. Objects provide a natural granularity for the binding of functions. –RMI allows.
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
Introduction to Remote Method Invocation (RMI)
Algorithm Programming Distributed Programming in Java Bar-Ilan University תשס " ו by Moshe Fresko.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Java Computing 6. RMI By Dr. Jiang B. Liu
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
Internet Software Development Remote Method Invocation Paul Krause.
Slides for Chapter 5: Communication between distributed objects
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.
ICS 123 Java RMI ICS 123 Richard N. Taylor and Eric M. Dashofy* UC Irvine * with the usual thanks to David Rosenblum.
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.
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.
RMI – Command Line CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Remote Method Invocation onlineTraining/rmi/RMI.html.
RMI Continued IS Outline  Review of RMI  Programming example.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved TDTS04 Föreläsning.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Example: RMI Program How to write it.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
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.*
Presentation: RMI Continued 2 Using The Registry & Callbacks.
 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.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
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.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
Java Object-Relational Layer Sharon Diskin GUS 3.0 Workshop June 18-21, 2002.
Netprog Java RMI1 Remote Method Invocation.
import java.io.*; public class Customer implements Serializable { public Customer(int theAge, int theSex, String[] theHobbies) { age = theAge; sex.
Using RMI The Example of A Remote Calculator 1. Parts of A Working RMI System A working RMI system is composed of several parts. –Interface definitions.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Principles of Software Development
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Remote Method Invokation
Remote Method Invocation
Advanced Remote Method Invocations
Edition 5, © Addison-Wesley 2012
Java RMI (more) CS-328 Internet Programming.
Distributed Systems Course Topics in distributed objects
null, true, and false are also reserved.
Slides for Chapter 5: Distributed objects and remote invocation
Remote method invocation (RMI)
Using RMI -The Example of A Remote Calculator
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 Object-Relational Layer
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Јава - RMI Дизајн симулатора дискретних догађаја опште намене обухвата пројектовање више различитих структурних нивоа. Унутар сваког од структурних нивоа постоји скуп градивних блокова зависних од семантике конкретног нивоа. Овај рад има за циљ да представи интегрални поступак дизајна заснован на употреби независно формираних градивних блокова повезаних предметом симулације. Представљени дизајн је верификован имплементацијом алата заснованог на описаном поступку. Предности примене предложеног решења су размотрени уз осврт на могућа унапређења.

Промена парадигме

RMI

Комуникација са удаљеним објектом

Креирање интерфејса За све објекте који ће се приступати удаљено мора се креирати интерфејс преко кога се приступа одговарајућем објекту: import java.rmi.*; public interface Validator extends Remote{ String validate(String aUserName, String aPassword) throws RemoteException; }

Креирање класе import java.rmi.*; import java.util.*; import java.rmi.server.UnicastRemoteObject; public class ValidatorImpl extends UnicastRemoteObject implements Validator{ Map memberMap; public ValidatorImpl() throws RemoteException{ memberMap = new HashMap(); memberMap.put("John", "Appleseed"); } public String validate(String aUserName, String aPassword) throws RemoteException{ if(getMemberMap().containsKey(aUserName)&& getMemberMap().get(aUserName).equals(aPassword)) return "Welcome " + aUserName; return "Sorry invalid login information!"; public Map getMemberMap(){ return memberMap;

Повезивање имена са објектом import java.net.*; import java.rmi.*; public class LoginServer{ public static String server = …; public static int port = …; public static void main(String args[]){ try{ System.setSecurityManager(new RMISecurityManager()); LocateRegistry.createRegistry(port); ValidatorImpl aValidator = new ValidatorImpl(); String urlString = "//" + server + ":" + port + "/validator"; Naming.rebind(urlString , aValidator); System.out.println("Login server open for business"); }catch(RemoteException e){ //catches a RemoteException e.printStackTrace(); }catch(MalformedURLException me){ System.out.println("MalformedURLException " + me); }

Креирање клијента import java.rmi.*; import java.net.*; public class ValidatorClient{ public static void main(String args[]){ if(args.length==0||!args[0].startsWith("rmi:")){ System.out.println("Usage: java ValidatorClient" + "rmi://host.domain:port/validator username password"); } try{ System.setSecurityManager(new RMISecurityManager()); Object remote = Naming.lookup(args[0]); Validator reply = (Validator)remote; System.out.println(reply.validate(args[1], args[2])); }catch(MalformedURLException me){ System.out.println(args[0] + " is not a valid URL"); }catch(RemoteException nbe){ System.out.println("Could not find requested object on the server");

Заштита java.policy grant { // Allow everything for now permission java.security.AllPermission; };

Коришћење Превођење: javac -d . *.java rmic ValidatorImpl Покретање: start rmiregistry java -Djava.security.policy=java.policy LoginServer java -Djava.security.policy=java.policy ValidatorClient rmi://host.domain:port/validator username password

Задаци

The Savings Account problem Рачун у банци може да дели више корисника. Сваки корисник може да уплаћује и подиже новац са рачуна под условом да салдо на рачуну никада не буде негативан, као и да види тренутно стање рачуна. Решити проблем користећи удаљене позиве метода у Јави.

The Savings Account problem import java.rmi.*; public interface Banck extends Remote { public UserAcount getUserAcount(String name) throws RemoteException; } public interface UserAcount extends Remote { public float getStatus() throws RemoteException; public void transaction(float value) throws RemoteException;

The Savings Account problem import java.rmi.*; import java.rmi.server.*; import java.util.HashMap; public class BanckImpl extends UnicastRemoteObject implements Banck { private static transient HashMap users = new HashMap(); public BanckImpl() throws RemoteException {} public UserAcount getUserAcount(String name)throws RemoteException { synchronized(this){ UserAcountImpl user = (UserAcountImpl)users.get(name); if (user != null) { return user; } user = new UserAcountImpl(name); users.put(name, user);

The Savings Account problem import java.rmi.*; import java.rmi.server.*; import java.io.Serializable; public class UserAcountImpl extends UnicastRemoteObject implements UserAcount, Serializable { private float status = 0; private String name; public UserAcountImpl (String name) throws RemoteException { this.name = name; } private void work(){ try { Thread.currentThread().sleep(500+(int)(Math.random()*1000)); } catch(InterruptedException e) {}

The Savings Account problem public float getStatus() throws RemoteException { synchronized(this){ work(); return status; } public void transaction(float value) throws RemoteException{ while(status + value < 0){ try{ wait(); } catch(Exception ex){} status += value; notifyAll();

The Savings Account problem import java.rmi.*; import java.rmi.registry.LocateRegistry; public class Server { public static final int port = 8181; public static final String server = "127.0.0.1"; public static void main(String []args){ System.setSecurityManager(new RMISecurityManager()); try { LocateRegistry.createRegistry(port); System.out.println("Definisan Registry port"); System.out.println("BanckImpl: kreira Banck"); Banck dli = new BanckImpl(); System.out.println("BanckImpl: povezuje ga sa imenom"); String urlString = "//" + server + ":" + port + "/Banck"; System.out.println(urlString); Naming.rebind(urlString, dli); System.out.println("Banck je sada spremna"); } catch (Exception ex) { System.out.println("Desila se greska" + ex); ex.printStackTrace();} }

The Savings Account problem import java.rmi.*; public class Client { public static final int port = 8181; public static final String server = "127.0.0.1"; public static void main(String []args){ Banck dl = null; UserAcount UserAcount = null; String name = args[0]; System.setSecurityManager(new RMISecurityManager()); try { String url = "//" + server + ":" + port + "/Banck"; System.out.println("url = " + url); dl = (Banck)Naming.lookup(url); } catch (Exception e) { System.err.println("ERROR Naming.lookup" + e); System.exit(-1); }

The Savings Account problem try { UserAcount = dl.getUserAcount(name); System.out.println("Nadjeni podaci za " + name); } catch (Exception e) { System.err.println("ERROR reaching " + name); System.exit(-1); } for(int m = 0; m < 100; m++){ float nstatus = (float)(50 + m - (int)(Math.random()*100)); System.out.println("Status: " + UserAcount.getStatus()); System.out.println("Promena statusa za " + nstatus); UserAcount.transaction(nstatus); System.out.println("Novi status: " + UserAcount.getStatus()); System.err.println("Greska pri transakciji za " + name);

The Savings Account problem java.policy grant { // Allow everything for now permission java.security.AllPermission; }; Превођење: javac -d . *.java rmic UserAcountImpl BanckImpl Покретање: start rmiregistry java -Djava.security.policy=java.policy Server java -Djava.security.policy=java.policy Client pera

Питања? Захарије Радивојевић Електротехнички Факултет Универзитет у Београду zaki@etf.bg.ac.yu