Presentation is loading. Please wait.

Presentation is loading. Please wait.

CORBA_1/001 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CORBA:

Similar presentations


Presentation on theme: "CORBA_1/001 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CORBA:"— Presentation transcript:

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

2 CORBA_2/002 CS 547 Advanced Network Programming 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 Presentation Agenda

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

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

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

6 CORBA_2/006 CS 547 Advanced Network Programming Installing Java 2 SDK 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/) J2SE J2SE CORBA Java IDL ORB

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

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

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

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

11 CORBA_2/011 CS 547 Advanced Network Programming Client Stub 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

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

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

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

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

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

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

18 CORBA_2/018 CS 547 Advanced Network Programming IDL Syntax IDL is a language to define interface for Java and the following terms are defined: (1)Module (2)Interface (3)Operation (4)Parameter (5)Attribute (6)Constant (7)Exception (8)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

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

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

21 CORBA_2/021 CS 547 Advanced Network Programming Compiling IDL file by JAVA IDL compiler  Go to a command line prompt in Windows’ DOS box  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)  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

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

23 CORBA_2/023 CS 547 Advanced Network Programming Stub File 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”

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

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

26 CORBA_2/026 CS 547 Advanced Network Programming Operations File 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”

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

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

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

30 CORBA_2/031 CS 547 Advanced Network Programming Section 1: Server Setup Section // 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; 

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

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

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

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

35 CORBA_2/033 CS 547 Advanced Network Programming Section 3: Server Body Section  Initialize the 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 

36 CORBA_2/034 CS 547 Advanced Network Programming  Initialize the local ORB 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 “args” in main () can be passed here Special ORB properties can be specified Pointer to ORB properties (default = NULL)

37 CORBA_2/035 CS 547 Advanced Network Programming  Get reference to the RootPOA & activate the POAManager 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

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

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

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

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

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

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

44 CORBA_2/042 CS 547 Advanced Network Programming  Get the root naming context It is not a good idea to let a CORBA client to identify each CORBA server by the object reference 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

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

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

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

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

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

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

51 Client Program CORBA_2/049 CS 547 Advanced Network Programming Coding Time Client Program: Program Organization The CORBA client program consists of two sections: (2) Client Body Section (1) Client Setup Section

52 CORBA_2/050 CS 547 Advanced Network Programming Section 1: Client Setup Section  import TodayApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*;

53 CORBA_2/051 CS 547 Advanced Network Programming Section 2: Client Body Section   Create and instantiate the local ORB  Resolve the object reference in Naming  Get the root naming context  Invoke a remote CORBA object

54 CORBA_2/052 CS 547 Advanced Network Programming ORB orb = ORB.init (args, null); “args” in main ( ) can be passed here Pointer to ORB properties (default = NULL)  Initialize the local ORB = same as the one in the server side

55 CORBA_2/053 CS 547 Advanced Network Programming orb.omg.CORBA.Object objRef = Class name of naming context Object name (instantiation) of naming context orb.resolve_initial_references (“NameService”); “resolve_initial_references” advertises POAs in an ORB Constant “NameService” required  Get the root naming context = This is the fifth step (  ) in the server

56 CORBA_2/054 CS 547 Advanced Network Programming CORBA Broker Network Server Name ORB Client Server name = “Today” CORBA Client  Resolve the object reference in Naming

57 CORBA_2/055 CS 547 Advanced Network Programming  Resolve the object reference in Naming String name = “Today”; todayImpl = TodayHelper.narrow (ncRef.resolve_str(name)); static Today todayImpl; Object name (the one specified by “interface” keyword in IDL) Call a CORBA Broker to find this object

58 CORBA_2/056 CS 547 Advanced Network Programming  Invoke a remote CORBA object System.out.println (todayImpl.whcih_day()); You can call a remote CORBA object as if it were an ordinary local JAVA object Class name of your CORBA object (remote) CORBA method A method defined in Java library

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

60 CORBA_2/058 CS 547 Advanced Network Programming CORBA Today Server/Client Development procedures (1) Create a project directory (such as “Time”) (2) Create the IDL file and save it in the directory created at (1) (3) Compile the IDL file (  : “idlj –fall Today.idl” in the directory (4) If no error, a subdirectory, “TodayApp” will be created and the six output files from IDL compiler will be placed in the subdirectory (5) Create a server source code file in “Time” directory (TodayServer.java) (6) Compile the server program (  : “javac TodayServer.java TodayApp/*.java”) (7) Create a client source code file in “Time” directory (TodayClient.java) (8) Compile the client program (  : “javac TodayClient.java TodayApp/*.java”)

61 CORBA_2/059 CS 547 Advanced Network Programming Execute the programs: Procedures Step1: Start the CORBA Broker Step2: Start the server program start ordb –ORBInitialPort 1050 –ORBInitialHost localhost start java TodayServer –ORBInitialPort 1050 –ORBInitialHost localhost Port# the CORBA Broker is listening to IP address of a machine to start a CORBA broker Port# the CORBA Broker is listing to IP address of a machine where the CORBA broker is running

62 CORBA_2/060 CS 547 Advanced Network Programming Execute the programs: Procedures Step3: Start the client program java TodayClient –ORBInitialPort 1050 –ORBInitialHost Port# the CORBA Broker is listing to IP address of a machine where the CORBA broker is running

63 CS 547 Advanced Network Programming CORBA/061 CORBA Broker Today ClientToday Server Execute the programs: Procedures (continued) Request Reply

64 CS 547 Advanced Network Programming CORBA/062 CORBA Broker Today ClientToday Server Execute the programs: Procedures (continued) Expected output: 18:01 July 9, 2002

65 CS 547 Advanced Network Programming CORBA/063 CORBA Today Server and Client Overview (continued) Time Client 11:01:58 Time Server ORB IIOP TCP/IP ORB IIOP TCP/IP Internet Time Client CORBA program Time Server CORBA program Current_Time(); Data transfer “pass by value”


Download ppt "CORBA_1/001 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CORBA:"

Similar presentations


Ads by Google