Download presentation
Presentation is loading. Please wait.
1
CORBA 簡介 郭 俊 博 中華大學資訊工程研究所 平行與分散實驗室
(C) Copyright PodsCat, 1998 CORBA 簡介
2
異質環境 不同的作業系統 不同的程式語言 不同的分散式計算架構 UNIX, NT, ... etc. C++, Java, ... etc.
DCE, Socket-based, RPC CORBA, Java, DCOM (C) Copyright PodsCat, 1998 CORBA 簡介
3
CORBA 非常適用於異質環境整合 不同程式語言的物件可透過 CORBA 聯繫。 在多種作業系統上都有 CORBA 的平台。
IIOP ESIOP CORBA/COM (C) Copyright PodsCat, 1998 CORBA 簡介
4
物件管理架構 (OMA) Application Objects Client Object Implementation
Common Object Services (COS) Common Facilities (CFA) Object Request Broker (ORB) (C) Copyright PodsCat, 1998 CORBA 簡介
5
物件訊息仲裁者 (ORB) 物件訊息仲裁者 (Object Request Broker, ORB) 可視為一種軟體的匯流排 (software bus)。 各廠商只要遵循 ORB 對外的界面標準,至於內部可以由各廠商自行決定實作 ORB 的方法。 (C) Copyright PodsCat, 1998 CORBA 簡介
6
物件訊息仲裁者 (ORB) ORB 連接不同的物件,並達成 : 物件位置的通透性 (location transparency)
動態或靜態的物件呼叫 (invocations) 可用高階的物件語言來使用 ORB (language binding) 物件間聯繫的安全性 其它物件導向應有的特性 (C) Copyright PodsCat, 1998 CORBA 簡介
7
物件訊息仲裁者 (ORB) (C) Copyright PodsCat, 1998 CORBA 簡介
8
界面定義語言與界面儲存器 為了能夠使用唯一的方式描述一個物件的界面 (Interface),CORBA 提供了一個界面定義語言 (Interface Definition Language, IDL)。 透過一致的界面定義,使物件的界面 (Interface) 與物件的實體 (Implementation) 可以獨立開來。 (C) Copyright PodsCat, 1998 CORBA 簡介
9
界面定義語言與界面儲存器 為了能夠動態地查詢物件的界面,CORBA 提供了一個界面儲存器 (Interface Repository, IR)。 程式開發者在選定使用 CORBA 的語言後,可以經由適當的 IDL 編譯器將 IDL 轉換成該語言。 (C) Copyright PodsCat, 1998 CORBA 簡介
10
Object Implementation
CORBA 程式設計流程 Client Code Client Stub C++ Compiler Client IDL Compiler IDL C++ class IDL Spec. C++ Compiler Server Server Skeleton Object Implementation (C) Copyright PodsCat, 1998 CORBA 簡介
11
CORBA (Use Java) 範例: CORBA 環境 : CORBA are support in JDK 1.2
The newest JDK is JDK1.2Beta3 另有 idltojava are support at SPARC & Win32. Download these files at ftp://ftp.csie.chu.edu.tw/pub/Language/java/jdk/jdk-1.2-Bata3/ ftp://ftp.csie.chu.edu.tw/pub/Language/corba/ (C) Copyright PodsCat, 1998 CORBA 簡介
12
CORBA (Use Java) 範例: Three source files
The Interface definition ( Hello.idl ) The Implementing the Server ( HelloServer.java ) The Implementing The Client ( HelloClient.java ) (C) Copyright PodsCat, 1998 CORBA 簡介
13
Hello.idl Compile the IDL interface with the command: module HelloApp
{ interface Hello string sayHello(); }; Compile the IDL interface with the command: idltojava Hello.idl (C) Copyright PodsCat, 1998 CORBA 簡介
14
Hello.idl This generates five files in a HelloApp subdirectory:
_HelloImplBase.java This abstract class is the server skeleton, providing basic CORBA functionality for the server. It implements the Hello.java interface. The server class HelloServant extends _HelloImplBase. _HelloStub.java This class is the client stub, providing CORBA functionality for the client. It implements the Hello.java interface. Hello.java This interface contains the Java version of our IDL interface. It contains the single method sayHello(). The Hello.java interface extends org.omg.CORBA.Object, providing standard CORBA object functionality as well. HelloHelper.java This final class provides auxiliary functionality, notably the narrow() method required to cast CORBA object references to their proper types. HelloHolder.java This final class holds a public instance member of type Hello. It provides operations for out and inout arguments, which CORBA has but which do not map easily to Java's semantics. (C) Copyright PodsCat, 1998 CORBA 簡介
15
HelloServer.java (C) Copyright PodsCat, 1998 CORBA 簡介
import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; class HelloServant extends _HelloImplBase { public String sayHello() { return "\nHello world !!\n"; } } public class HelloServer { public static void main(String args[]) try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // create servant and register it with the ORB HelloServant helloRef = new HelloServant(); orb.connect(helloRef); (C) Copyright PodsCat, 1998 CORBA 簡介
16
HelloServer.java (C) Copyright PodsCat, 1998 CORBA 簡介
// get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent nc = new NameComponent("Hello", ""); NameComponent path[] = {nc}; ncRef.rebind(path, helloRef); // wait for invocations from clients java.lang.Object sync = new java.lang.Object(); synchronized (sync) { sync.wait(); } } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } } } (C) Copyright PodsCat, 1998 CORBA 簡介
17
HelloClient.java import HelloApp.*; import org.omg.CosNaming.*;
import org.omg.CORBA.*; public class HelloClient { public static void main(String args[]) try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); (C) Copyright PodsCat, 1998 CORBA 簡介
18
HelloClient.java // resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", ""); NameComponent path[] = {nc}; Hello helloRef = HelloHelper.narrow(ncRef.resolve(path)); // call the Hello server object and print results String hello = helloRef.sayHello(); System.out.println(hello); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } (C) Copyright PodsCat, 1998 CORBA 簡介
19
Building and Running Run idltojava on the IDL file to create stubs and skeletons idltojava Hello.idl Compile the .java files, including the stubs and skeletons: javac *.java HelloApp/*.java Make sure the name server is running: tnameserv -ORBInitialPort 1050& Start the Hello server: java HelloServer -ORBInitialPort 1050 Run the Hello application client from a different shell than the server: java HelloClient -ORBInitialPort 1050 (C) Copyright PodsCat, 1998 CORBA 簡介
20
分散式物件技術 (C) Copyright PodsCat, 1998 CORBA 簡介
Similar presentations