CORBA_1/001 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010...
-
Upload
sara-horton -
Category
Documents
-
view
217 -
download
0
Transcript of CORBA_1/001 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010...
CORBA_1/001
Department of Computer ScienceSouthern Illinois University Edwardsville
Spring, 2010
Dr. Hiroshi FujinokiE-mail: [email protected]
CORBA: Concept and Programming (2)
CS 547/CS490-003 Advanced Network Programming
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
CS 547 Advanced Network Programming
CORBA Broker
Request (What time?) Request
Reply
CORBA/003
CORBA Time Server and Client Overview
Time Client Time Server
Reply (Current Time)
• CORBA Time Client requests the current time
• CORBA broker forwards the client request to the time server
CS 547 Advanced Network Programming
CORBA Broker
Request (What time?)
Reply
CORBA/004
CORBA Time Server and Client Overview (continued)
Time Client Time 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
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
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
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();Current_Time();
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)
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();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
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();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
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
CORBA_2/012
CS 547 Advanced Network Programming
Client Stub • A client stub is a proxy object
localobject
localobject
localobject
Host A
Local object callCORBA Client Process
Remote object callthrough CORBA
ORB
Network
remoteobject
ORB
Host B
CORBA_2/013
CS 547 Advanced Network Programming
Client Stub
localobject
localobject
localobject
remoteobject
ORB
Host A
Local object call
ORB
Remote object callthrough CORBA
Network
clientstub
CORBA Client Process
Local object call
Client stub talks toORB on behalf of
a calling client
Host B
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)
CORBA_2/015
CS 547 Advanced Network Programming
remoteobject
ORB
Network
localobject
localobject
localobject
Host A
Local object call
ORB
Remote object callthrough CORBA
clientstub
CORBA Client Process
Local object call
Host B
remoteobject
ORB
Skeleton
CS 547 Advanced Network Programming
CORBA_2/016
CORBA BrokerToday Client Today Server
Request
CORBA Today Server/Client Development procedures
18:01 July 9, 2002
Reply (“18:01 July 9, 2002)
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
CORBA_2/018
CS 547 Advanced Network Programming
IDL Syntax
IDL is a language to define interface for Java and the following termsare 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
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
CORBA_2/020
CS 547 Advanced Network Programming
CORBA Time Server/Client Development procedures
CORBA IDLCORBA 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
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
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”
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”
CORBA_2/024
CS 547 Advanced Network Programming
Describe the last 3 output files from the IDL compiler
Interface File
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
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”
CORBA_2/027
CS 547 Advanced Network Programming
CORBA IDLCORBA IDL
Compiler
Time Server Source Code JAVACompiler
JAVACompiler
Time Server Executable
Time Client Executable
Time Client Source Code
CORBA_2/057
CS 547 Advanced Network Programming
CORBA IDLCORBA IDL
Compiler
Today Server Source Code
Today Client Source Code
Compiler
Compiler
Today Server Executable
Today Client Executable
Server ProgramCORBA_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
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;
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
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
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)
CS 547 Advanced Network Programming
ORB POA
CORBA Server
CORBAObject
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
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
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 ORBproperties (default = NULL)
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
CORBA_2/036
CS 547 Advanced Network Programming
Get reference to the RootPOA & activate the POAManager
ORB
Root POA
POA1
CORBA Server
Servant
Register
CORBAObject
Create
POAn
CORBA Server
Servant
Register
POA Manager
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
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
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
CORBA_2/040
CS 547 Advanced Network Programming
Get object reference for the servant created at
remoteobject
ORB
Host B
CORBAclient
ORB
Host A
CORBABroker
ORB
Host C
TCP/IPInterne
t
Object Reference= a set of information that physically identify a target CORBA remote object
Object Reference
• IP address• Port #
• Protocol = TCP
=
CORBA_2/041
CS 547 Advanced Network Programming
ORB
Root POA
POA1
CORBA Server
Servant
Register
CORBA Broker
Network
Get the root naming context
CORBAObject
CreateGet objectreference
Created
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
CORBA_2/043
CS 547 Advanced Network Programming
ORB
Root POA
POA1
CORBA Server
Servant
Register
CORBA Broker
Network
Get the root naming context
CORBAObject
CreateGet objectreference
ObjectReference
ServerName
CORBA_2/044
CS 547 Advanced Network Programming
Get the root naming context
Class name of naming contextObject 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
CORBA_2/045
CS 547 Advanced Network Programming
Get the root naming context
NamingContextExt ncRef =
Class name of naming contextObject name (instantiation) of naming context
NamingContextHelper.narrow(objRef);
“resolve_initial_references” advertises POAs in an ORB
Constant “NameService” required
ORB
Root POA
POA1
CORBA Server
Servant
Register
CORBA_2/046
CS 547 Advanced Network Programming
CORBA Broker
Network
CORBAObject
Create
Bind the object reference in naming
Get objectreference
Advertise the servant object by “Server Name”
BindServerName
ObjectReference
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 advertisedto a CORBA broker
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
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
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.*;
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
CORBA_2/052
CS 547 Advanced Network Programming
ORB orb = ORB.init (args, null);
“args” in main ( ) can be passed here
Pointer to ORBproperties (default = NULL)
Initialize the local ORB = same as the one in the server side
CORBA_2/053
CS 547 Advanced Network Programming
orb.omg.CORBA.Object objRef =
Class name of naming contextObject 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
CORBA_2/054
CS 547 Advanced Network Programming
CORBA Broker
Network
ServerName
ORB
Client
Server name = “Today”
CORBA Client
Resolve the object reference in Naming
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
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 objectas if it were an ordinary local JAVA object
Class name of your CORBA object
(remote) CORBA method
A method defined in Java library
CORBA_2/057
CS 547 Advanced Network Programming
CORBA IDLCORBA IDL
Compiler
Today Server Source Code
Today Client Source Code
Compiler
Compiler
Today Server Executable
Today Client Executable
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”)
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 machineto start a CORBA broker
Port# the CORBA Broker is listing to
IP address of a machine where the CORBA broker is running
CORBA_2/060
CS 547 Advanced Network Programming
Execute the programs: Procedures
Step3: Start the client program
java TodayClient –ORBInitialPort 1050 –ORBInitialHost <IP of the broker>
Port# the CORBA Broker is listing to
IP address of a machine where the CORBA broker is running
CS 547 Advanced Network Programming
CORBA/061
CORBA BrokerToday Client Today Server
Execute the programs: Procedures (continued)
Request
Reply
CS 547 Advanced Network Programming
CORBA/062
CORBA BrokerToday Client Today Server
Execute the programs: Procedures (continued)
Expected output:
18:01 July 9, 2002