Download presentation
Presentation is loading. Please wait.
Published byEllen Fisher Modified over 9 years ago
1
Vakgroep Informatietechnologie - IBCN CORBA & RMI Design of Distributed Software
2
2 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Objectives After this lab session you should be able to Write client and server applications Devlop object-oriented based distributed systems Use the CORBA and Java RMI technology CORBA = Common Object Request Brokerage Architecture Language neutral technology Allowing software components on multiple computers to communicate Java RMI Java specific technology Allowing software components on multiple computers to communicate 2
3
ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN CORBA & Java RMI Distributed system
4
4 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Outline 1. CORBA How to write a CORBA application
5
5 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing CORBA in 5 steps Writing the IDL files Writing the Server Writing the Servant Writing the Client Starting the application
6
6 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the IDL files The IDL file describes Which classes can be accessed remotely The signature of each remote method Compile the file: idlj –fall server.idl module ods{ module corba{ module bmicalculator{ interface BMICalculator{ double calculateBMI(in double length, in double weight); };
7
7 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the Server Several classes were generated Writing the server Extending the abstract POA class No CORBA specific code is needed package ods.corba.bmicalculator; public class BMICalculatorImpl extends BMICalculatorPOA{ public double calculateBMI(double length, double weight){ return weight / (length * length); }
8
8 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the servant Servant: main class to start the server Steps to take: Initialize the ORB (Object Request Broker) Start the Server object java.util.Properties props = System.getProperties(); props.put("org.omg.CORBA.ORBInitialPort”,157.193.214.253); props.put("org.omg.CORBA.ORBInitialHost", 1049); ORB orb = ORB.init(new String[0], props); BMICalculatorImpl bmi_calc = new BMICalculatorImpl();
9
9 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the servant Find the Naming Service & Root POA Activate the Server object with the POA POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); NamingContext namingContext = NamingContextHelper.narrow(orb.resolve_initial_references ("NameService")); rootPOA.activate_object(bmi_calc); BMICalculator bmicalcRef = BMICalculatorHelper. narrow(rootPOA.servant_to_reference(bmi_calc));
10
10 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the servant Register the server object with the Naming Service Activate the POA and start the ORB 10 NameComponent nc = new NameComponent("BMICalculator", ""); NameComponent path[] = { nc }; namingContext.rebind(path, bmicalcRef); rootPOA.the_POAManager().activate(); orb.run();
11
11 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the client Steps to take: Initialize the ORB (Object Request Broker) Find the Naming Service java.util.Properties props = System.getProperties(); props.put("org.omg.CORBA.ORBInitialPort”,157.193.214.253); props.put("org.omg.CORBA.ORBInitialHost", 1049); ORB orb = ORB.init(new String[0], props); NamingContext namingContext = NamingContextHelper.narrow(orb.resolve_initial_references ("NameService"));
12
12 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the client Obtain a reference to the remote object Invoke a method just as a regular object NameComponent nc = new NameComponent("BMICalculator", ""); NameComponent path[] = { nc }; BMICalculator server = BMICalculatorHelper.narrow(ncRef.resolve(path)); System.out.println(server.calculateBMI(1.87, 75));
13
13 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Starting the application Starting the Naming Service Starting the Server Starting the client 13 start orbd –ORBInitialPort 1049 start java ods.corba.bmicalculator. StartBMICalculatorServer 157.193.214.253 1049 java ods.corba.bmicalculator.client.BMICalculatorClient 157.193.214.253 1049
14
14 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Outline 2. Java RMI How to write a Java RMI application
15
15 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing Java RMI in 5 steps Writing the remote Java interface Writing the Server Writing the Servant Writing the Client Starting the application Writing the policy file
16
16 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the remote interface Define the class as remote Extend Remote interface Define the available remote methods Add “ throws RemoteException ” 16 package ods.rmi.bmicalculator.server; import java.rmi.Remote; import java.rmi.RemoteException; public interface BMICalculatorServerInterface extends Remote { public double calculateBMI(double length, double weight) throws RemoteException; }
17
17 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Implementing the remote interface No specific Java RMI code is needed 17 public class BMICalculatorServer implements ods.rmi.bmicalculator.server.BMICalculatorServerInterface{ public BMICalculatorServer() { super(); } public double calculateBMI(double length, double weight) throws RemoteException { return weight/(length*length); } Writing the Server
18
18 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the servant Servant: main class to start the server Steps to take: Initialize the Security Manager Start the Server object if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } BMICalculatorServerInterface bmiCalc = new BMICalculatorServer(); BMICalculatorServerInterface stub = (BMICalculatorServerInterface) UnicastRemoteObject.exportObject(bmiCalc, 0);
19
19 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the servant Register the server with the Registry Registry registry = LocateRegistry.getRegistry(); String name = (args[0]==null)?args[0]:"BMICalculator"; registry.rebind(name, stub);
20
20 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing the client Steps to take: Initialize the Security Manager Obtain a reference to the remote object Invoke a method if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } Registry registry = LocateRegistry.(args[0]); BMICalculatorServerInterface calculator = (BMICalculatorServerInterface)registry.lookup(args[1]); System.out.println(calculator.calculateBMI(1.87, 75));
21
21 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Writing a policy file Policy file needed to allow network communication 21 grant{ permission java.net.SocketPermission "*:1024-65535", "connect,accept"; };
22
22 ODS – Introduction to CORBA & RMI Vakgroep Informatietechnologie - IBCN Starting the application Starting the Registry Starting the Server Starting the client 22 rmiregistry [port] start java -Djava.security.policy=java.policy ods.rmi.bmicalculator.server.BMICalculatorServer BMICalculator java -Djava.security.policy=java.policy ods.rmi.bmicalculator.client.BMIClientProgram 157.193.214.124 BMICalculator
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.