1 / 65

CORBA_1/001

CORBA: Concept and Programming (2). CS 547/CS490-003 Advanced Network Programming. Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu. CORBA_1/001. CS 547 Advanced Network Programming. Presentation Agenda.

semah
Télécharger la présentation

CORBA_1/001

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CORBA: Concept and Programming (2) CS 547/CS490-003 Advanced Network Programming Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu CORBA_1/001

  2. CS 547 Advanced Network Programming Presentation Agenda • 1. Overview for a simple CORBA application: CORBA Time Server and Client • 2. CORBA Programming Concept • 3. Coding IDL • 4. Coding CORBA Time Server and Client • 5. Executing the CORBA server and client CORBA_2/002

  3. CORBA Time Server and Client Overview Request Reply Reply (Current Time) CS 547 Advanced Network Programming • CORBA Time Client requests the current time • CORBA broker forwards the client request to the time server Time Client Time Server Request (What time?) CORBA Broker CORBA/003

  4. CORBA Time Server and Client Overview (continued) Request (What time?) CS 547 Advanced Network Programming • CORBA Time Client requests the current time • CORBA broker forwards the client request to the time server CORBA Broker Time Client Time Server Reply • Put the CORBA Broker at the server host CORBA/004

  5. The CORBA ORB we are going to use CS 547 Advanced Network Programming - the CORBA ORB developed by Sun Microsystems • Java 2 SDK • Java 2 SDK Standard Edition v.1.4.0, rev. 01 (v.1.4.0_01) • Java IDL assumes JAVA for its programming language • Java 2 contains a free CORBA ORB • Java 2 SDK for Win32 environment is available - Posted in CS547/CS490-003 Home - A little bit big (about 32MB) - Sample server/client source will be posted CORBA_2/005

  6. Installing Java 2 SDK J2SE J2SE CORBA Java IDL ORB CS 547 Advanced Network Programming • Download java-2 SDK standard Edition for Win32 environment • Can be downloaded from the Sun web site for J2SE • (http://java.sun.com/j2se/1.4/) CORBA_2/006

  7. CORBA Time Server and Client Overview (continued) Time Client CORBA program Time Server CORBA program CORBA Interface (IDL) ORB ORB IIOP IIOP TCP/IP TCP/IP CORBA Internet CS 547 Advanced Network Programming Time Client Time Server Current_Time(); Current_Time(); 11:01:58 CORBA_2/007

  8. CORBA Time Server and Client Overview (continued) CORBA Interface (IDL) ORB ORB IIOP IIOP TCP/IP TCP/IP Internet CS 547 Advanced Network Programming Time Client Time Server 11:01:58 What_time(); 11:01:58 CORBA_2/008

  9. CORBA Time Server and Client Overview (continued) ORB ORB CORBA IDL IIOP IIOP TCP/IP TCP/IP CS 547 Advanced Network Programming Time Server Time Client Current_Time(); Current_Time(); • CORBA IDL to define the interface for the caller function • IDL file is not a function implementation but a definition of the function CORBA_2/009

  10. CORBA Time Server and Client Overview (continued) “Skeleton” “Stub” ORB ORB CORBA IDL IIOP IIOP TCP/IP TCP/IP CS 547 Advanced Network Programming Time Server Time Client Current_Time(); Current_Time(); • After a CORBA IDL is compiled, the client stub and server skeleton • are created • Client stub and server skeleton are the interface between your • programming language and a CORBA ORB CORBA_2/010

  11. Client Stub CS 547 Advanced Network Programming 1. A client stub has exactly the same interface as the remote object a CORBA client is trying to call 2. The client stub communicates with the local ORB to talk to the actual remote object 3. The client stub also performs data marshaling/unmarshaling between a CORBA client and the local ORB Marshaling/unmarshaling = convert the format of data CORBA_2/011

  12. Client Stub Host A CORBA Client Process Local object call Remote object call through CORBA local object local object local object Host B remote object ORB ORB Network CS 547 Advanced Network Programming • A client stub is a proxy object CORBA_2/012

  13. Client Stub Host A Local object call Local object call Remote object call through CORBA local object local object local object client stub Client stub talks to ORB on behalf of a calling client ORB ORB remote object CS 547 Advanced Network Programming CORBA Client Process Host B Network CORBA_2/013

  14. Server Skeleton (1) Type of programming language (2) Input parameters (parameter types) (3) Output parameters (parameter types) CS 547 Advanced Network Programming • A server skeleton is an ORB – remote method interface • A remote method is implemented in some high-level • programming language (such as C++, Java, COBOL, FORTLAN, CGI…) • There must be a translator program between an ORB and a remote object • The translator must know how to call the remote object CORBA_2/014

  15. Host A CORBA Client Process Local object call Local object call Remote object call through CORBA local object local object local object client stub Skeleton ORB ORB ORB remote object remote object CS 547 Advanced Network Programming Host B Network CORBA_2/015

  16. CORBA Today Server/Client Development procedures CORBA Broker Today Client Today Server 18:01 July 9, 2002 Request Reply (“18:01 July 9, 2002) CS 547 Advanced Network Programming CORBA_2/016

  17. CORBA Today Server/Client Development procedures module TodayApp { interface Today { string which_day(); oneway void shutdown(); }; }; CS 547 Advanced Network Programming  Example of Time Server/Client IDL: This IDL file is assumed to be saved as “Today.IDL” CORBA_2/017

  18. IDL Syntax CS 547 Advanced Network Programming IDL is a language to define interface for Java and the following terms are defined: • Module • Interface • Operation • Parameter • Attribute • Constant • Exception • Type :declares an object :defines a name of an object : declares a method in an object : defines parameters in a method : defines attributes in an object : declares constant(s) in an object : defines operations for exception : data type definition CORBA_2/018

  19. Object Name Module CORBA Time Server/Client Development procedures Object Methods CS 547 Advanced Network Programming Example of Time Server/Client IDL: module TodayApp { interface Today { string which_day(); oneway void shutdown(); }; }; CORBA_2/019

  20. POA File If no error, six files will be generated CORBA Time Server/Client Development procedures Stub File Interface File in the target programming language (= function prototypes) CORBA IDL Helper File CORBA IDL Compiler Holder File Operations File CS 547 Advanced Network Programming CORBA_2/020

  21. Compiling IDL file by JAVA IDL compiler CS 547 Advanced Network Programming  Make sure that the j2sdk/bin directory (or the directory of idlj, java, javac, and orbd) are in your path • You can make sure your current path setting by typing “PATH” • at DOS command prompt • If the current path does not include a path to j2sdk/bin, you can • include a path by modifying config.sys (a hidden Windows system file)  Go to a command line prompt in Windows’ DOS box  Change to the directory that contains your IDL file (*.idl file)  Compile your IDL by: “idlj -fall Hello.idl”  On success, the IDL output directory will be created with six files CORBA_2/021

  22. POA (Portable Object Adapter) File This file is a skeleton (for CORBA server) CS 547 Advanced Network Programming • This file contains the abstract class for stream-based (connection-oriented) • server skeleton • POA file provides basic CORBA functionality for a CORBA server (an object) • The server class (the server object) is implemented by extending this class • File name: “TodayPOA.java”, if the name of IDL is “Today.idl” CORBA_2/022

  23. Stub File CS 547 Advanced Network Programming • This is the client stub • The stub file provides basic CORBA functionality for a CORBA client • File name: “_TodayStub.java”, if the name of IDL is “Today.idl” CORBA_2/023

  24. Interface File CS 547 Advanced Network Programming Describe the last 3 output files from the IDL compiler CORBA_2/024

  25. Helper File Holder File CS 547 Advanced Network Programming • Contains the class that convert JAVA data types to/from CORBA data types • File name: “TodayHelper.java”, if the IDL file is “Today.idl” • Contains public functions and variables in the resulting JAVA program • Delegates to the methods in the Helper class for reading and writing • File name: “TodayHolder.java”, if the IDL file is “Today.idl” CORBA_2/025

  26. Operations File CS 547 Advanced Network Programming • Contains the methods in the client process • This file defines the signatures (the interface) of all methods • Shared by the stub and the skeleton • File name: “TodayOperations.java”, if the IDL is “Today.idl” CORBA_2/026

  27. JAVA Compiler Time Server Source Code Time Client Executable Time Server Executable CORBA IDL CORBA IDL Compiler JAVA Compiler Time Client Source Code CS 547 Advanced Network Programming CORBA_2/027

  28.   Today Server Source Code Today Client Executable Today Server Executable CORBA IDL CORBA IDL Compiler   CS 547 Advanced Network Programming Compiler     Compiler Today Client Source Code CORBA_2/057

  29. (1) Server Setup Section (2) Servant Section Coding Time Server Program: Program Organization (3) Server Body Section Server Program CS 547 Advanced Network Programming The CORBA server program consists of three sections: CORBA_2/030

  30. // TodayServer.java import TodayApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; import java.util.Properties; Section 1: Server Setup Section CS 547 Advanced Network Programming  CORBA_2/031

  31. Implementation of “which_day” method Section 2: Servant Section class TodayImpl extends TodayPOA { private ORB orb; publicvoid setORB(ORB orb_val) { orb = orb_val; } publicString which_day() { return ("\n18:01 July 9, 2002"); } } CS 547 Advanced Network Programming  CORBA_2/032

  32. Servant CS 547 Advanced Network Programming • An ORB creates an object (= activates a servant) based on a servant • when a CORBA client makes a request to it • Servant is a CORBA server service registered to an ORB = implementation of your CORBA server object CORBA_2/028

  33. Object Adapter CS 547 Advanced Network Programming • When a CORBA server is started, CORBA object may not be created • OA creates (instantiates) and deletes local CORBA objects • Most popular OA is POA (Portable Object Adapter) • When a CORBA server is started, the operations are registered to its ORB CORBA_2/029

  34. CORBA Server CORBA Object POA Servant Create Object Adapter Register ORB CS 547 Advanced Network Programming What is OA (Object Adapter)? • OA (Object Adapter) is an ORB component • OA manages (creates and deletes) local CORBA objects CORBA_2/029

  35. Section 3: Server Body Section CS 547 Advanced Network Programming   Initializethe local ORB  Get reference to RootPOA & activate the POAmanager  Create an ORB servant and register it with the ORB setup at   Get object reference from the servant created at   Get the root naming context  Bind the object reference in naming  Wait for invocation from clients CORBA_2/033

  36.  Initialize the local ORB Pointer to ORB properties (default = NULL) “args” in main () can be passed here CS 547 Advanced Network Programming ORB orb = ORB.init (args, null); • ORB.init initializes the local ORB and needs to be called • at the beginning • The call to the ORB’s init () method passes in the server’s command • line arguments, allowing you to set certain properties at runtime • Special ORB properties can be specified CORBA_2/034

  37.  Get reference to the RootPOA & activate the POAManager CS 547 Advanced Network Programming POA rootpoa = POAHelper.narrow (orb.resolve_initial_references(“RootPOA”); Rootpoa.the POAManager().activate(); • The reference to the root POA is retrieved in the first line • The POA Manager is activated CORBA_2/035

  38.  Get reference to the RootPOA & activate the POAManager CORBA Server CORBA Server CORBA Object POA1 POAn Servant Servant Create Register Root POA ORB CS 547 Advanced Network Programming Register POA Manager CORBA_2/036

  39.  Create a servant and register it with the ORB created at  1. TodayImpl todayImpl = new TodayImpl (); 2. today_impl.setORB(orb); CS 547 Advanced Network Programming There are two steps to perform  CORBA_2/037

  40.  Create a servant and register it with the ORB created at  Step #1 The constructor of the “TodayImpl” class Object (= the instantiation of “TodayImpl” class) The Servant Class Name (“TodayImpl” class) CS 547 Advanced Network Programming TodayImpl todayImpl = new TodayImpl (); CORBA_2/038

  41.  Create a servant and register it with the ORB created at  Step #2 setORB method registers this object to ORB (POA) Servant object name (not servant class name) CS 547 Advanced Network Programming Register an object to ORB (POA) todayImpl.setORB (orb); CORBA_2/039

  42.  Get object reference for the servant created at  Host A Object Reference = a set of information that physically identify a target CORBA remote object Host C • IP address CORBA client • Port # ORB • Protocol = TCP = ORB Object Reference CORBA Broker TCP/IP Internet Host B remote object ORB CS 547 Advanced Network Programming CORBA_2/040

  43.  Get the root naming context Get object reference CORBA Server CORBA Object POA1 Servant Create Register Created Root POA CORBA Broker ORB Network CS 547 Advanced Network Programming CORBA_2/041

  44.  Get the root naming context • In CORBA, a CORBA client can call a CORBA server • by its server name • We have to give a CORBA server a name to a CORBA Broker CS 547 Advanced Network Programming • It is not a good idea to let a CORBA client to identify • each CORBA server by the object reference CORBA_2/042

  45.  Get the root naming context Get object reference CORBA Server Object Reference Server Name CORBA Object POA1 Servant Create Register Root POA CORBA Broker ORB Network CS 547 Advanced Network Programming CORBA_2/043

  46.  Get the root naming context orb.omg.CORBA.Object objRef = Object name (instantiation) of naming context Class name of naming context orb.resolve_initial_references (“NameService”); “resolve_initial_references” advertises POAs in an ORB Constant “NameService” required CS 547 Advanced Network Programming CORBA_2/044

  47.  Get the root naming context Object name (instantiation) of naming context Class name of naming context “resolve_initial_references” advertises POAs in an ORB CS 547 Advanced Network Programming NamingContextExt ncRef = NamingContextHelper.narrow(objRef); Constant “NameService” required CORBA_2/045

  48.  Bind the object reference in naming Get object reference CORBA Server Object Reference Server Name Bind CORBA Object POA1 Servant Create Register Root POA CORBA Broker Advertise the servant object by “Server Name” Network CS 547 Advanced Network Programming ORB CORBA_2/046

  49.  Bind the object reference in naming The server name to be advertised to a CORBA broker CS 547 Advanced Network Programming String name = “Today”; NameComponentPath path [ ] = ncRef.to_name (name); ncRef.rebind (path, href); CORBA_2/047

  50.  Wait for invocation from a client After this, “Today” CORBA object (= Today CORBA Server) is up and running, waiting for a CORBA client CS 547 Advanced Network Programming orb.run (); CORBA_2/048

More Related