<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    走在架構師的大道上 Jack.Wang's home

    Java, C++, linux c, C#.net 技術,軟件架構,領域建模,IT 項目管理 Dict.CN 在線詞典, 英語學習, 在線翻譯

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      195 Posts :: 3 Stories :: 728 Comments :: 0 Trackbacks

           1)首先要熟悉idl語言,這個是專門進行接口設計的語言,它與java沒關系,有自己的語法,具體的規則需要大家自己再網上研究,這里不多說了(或者訪問如下網站詳細察看http://www.iona.com/support/docs/manuals/orbix/33/html/orbix33cxx_pguide/IDL.html)。

    module HelloApp
    {
      
     interface Hello
        {
            string sayHello();
            oneway void shutdown();
         };
    };

    這 里定義了一個簡單的interface, 將其保存為hello.idl, 然后再dos命令框里面輸入 idlj.exe -fall hello.idl 編譯。之后會出現一個叫做HelloApp的目錄,corba就是通過這個目錄里面的類來進行c-s之間的數據溝通。

          2)下一步,就是我們的server端:

    // A server for the Hello object

    import HelloApp.*;
    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;

    public class HelloServer {

      public static void main(String args[]) {
        try{
          // create and initialize the ORB
          ORB orb = ORB.init(args, null);

          // get reference to rootpoa & activate the POAManager
          POA rootpoa =
            (POA)orb.resolve_initial_references("RootPOA");
          rootpoa.the_POAManager().activate();

          // create servant and register it with the ORB
          HelloImpl helloImpl = new HelloImpl();
          helloImpl.setORB(orb);

          // get object reference from the servant
          org.omg.CORBA.Object ref =
            rootpoa.servant_to_reference(helloImpl);


          // and cast the reference to a CORBA reference
          Hello href = HelloHelper.narrow(ref);
      
          // get the root naming context
          // NameService invokes the transient name service
          org.omg.CORBA.Object objRef =
              orb.resolve_initial_references("NameService");
          // Use NamingContextExt, which is part of the
          // Interoperable Naming Service (INS) specification.
          NamingContextExt ncRef =
            NamingContextExtHelper.narrow(objRef);

          // bind the Object Reference in Naming
          String name = "Hello1";
          NameComponent path[] = ncRef.to_name( name );
          ncRef.rebind(path, href);

          System.out.println
            ("HelloServer ready and waiting ...");

          // wait for invocations from clients
          orb.run();
        }
     
          catch (Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
          }
      
          System.out.println("HelloServer Exiting ...");
     
      } //end main
    } // end class

    將其保存為HelloServer.java.放在剛才的hello.idl的目錄。編譯這個文件就不多說了。

           3)還記得在hello中定義的interface嗎?我們需要對自己定義的接口中的方法進行實現,因此HelloImp.java

    // The servant -- object implementation -- for the Hello
    // example.  Note that this is a subclass of HelloPOA, whose
    // source file is generated from the compilation of
    // Hello.idl using j2idl.

    import HelloApp.*;
    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;

    class HelloImpl extends HelloPOA //必須繼承這個類,在helloApp目錄中已自動生成

     {
      private ORB orb;

      public void setORB(ORB orb_val) {
        orb = orb_val;
      }
       
      // implement sayHello() method
        public String sayHello()
        {
     return "\nHello world !!\n";
        }
       
      // implement shutdown() method
      public void shutdown() {
        orb.shutdown(false);
      }
    } //end class
    同樣放在server所在目錄中。

          4)接下來是客戶端(HelloClient.java):

    // A sample Java IDL object client application.
    import HelloApp.*;
    import org.omg.CosNaming.*;
    import org.omg.CosNaming.NamingContextPackage.*;
    import org.omg.CORBA.*;

    public class HelloClient
    {
      static Hello helloImpl;
      String [] x=new String[6];
      public static void main(String args[]){
         try{
            // create and initialize the ORB
          ORB orb = ORB.init(args, null);

            System.out.println("ORB initialised\n");

            // get the root naming context
            org.omg.CORBA.Object objRef =
          orb.resolve_initial_references("NameService");

            // Use NamingContextExt instead of NamingContext,
            // part of the Interoperable naming Service. 
            NamingContextExt ncRef =
              NamingContextExtHelper.narrow(objRef);
     
            // resolve the Object Reference in Naming
            String name = "Hello1";
            helloImpl =
              HelloHelper.narrow(ncRef.resolve_str(name));

            System.out.println
              ("Obtained a handle on server object: "
                + helloImpl);
            System.out.println(helloImpl.sayHello());
            helloImpl.shutdown();

       }
         catch (Exception e) {
            System.out.println("ERROR : " + e) ;
          e.printStackTrace(System.out);
       }
      } //end main

    } // end class


    這個文件最好放在一個新建的目錄,已表示和server有區別,放在一起也沒有關系。如果分開的話,記著把HelloApp這個目錄復制到client的目錄來。

    5)好啦!已經可以開始爽了,我們編譯所有的java文件

    6)再dos窗口輸入orbd.exe –ORBInitialPort 1234(端口號可以自定義,但是記得s-c要保持一致),啟動corba服務。

    7)啟動服務器:java HelloServer –ORBInitialPort 1234 –ORBInitialHost localhost

    8)啟動客戶端:java HelloClient –ORBInitialPort 1234 –ORBInitialHost localhost

    9)嚴格執行上述過程是應該直接成功的。 已經經過測試。

    10)然后再仔細研究這段代碼,你就會發現corba的奧秘了。
     From: http://www.javaeye.com/topic/136691



    本博客為學習交流用,凡未注明引用的均為本人作品,轉載請注明出處,如有版權問題請及時通知。由于博客時間倉促,錯誤之處敬請諒解,有任何意見可給我留言,愿共同學習進步。
    posted on 2008-04-26 21:13 Jack.Wang 閱讀(8937) 評論(9)  編輯  收藏 所屬分類: 開發技術

    Feedback

    # re: Java Corba 2008-04-26 22:25 隔葉黃鶯
    第一行是 idl 語言,不是 idlj 語言,接口定義語言
    jdk 提供的 orb 比較簡陋,學習用用,實際項目都會選別的 orb 產口。我原來用的好像是 orabcus。corba 規范定義了一系列的服務,如 命名、事件、通知、生命、持久性對象、事務服務等。

    corba 中的對象理解起來并不是那么容易,它當初由 OMG 組織提出是為異種平臺、語言進行通行。但是由 idl 對于每一種語言要映射生成獨有的一套接口代碼來也是很煩的。

    然而現在一切都變得簡單多了,有 webservice,就是語言平臺無關性的東西,還不象 corba 那樣要考慮防火墻,所以現在大熱的是 SOA、SCA、ESB 等。

    corba 大約還會在電信網管產品中使用,IIOP 是由 corba 衍生的一種協議,用于 Internet 的互操作協議。現在企業應用基本見不著 corba 的影子了。

    說真的,很多的程序員都還沒用過 EJB,也不知道 EJB 長什么樣子的,Hibernate/Spring 橫空出世了。更別提 cobar 那個老古懂。
      回復  更多評論
      

    # re: Java Corba 2008-04-27 08:26 Jack.Wang
    學習了  回復  更多評論
      

    # re: Java Corba 2008-04-30 13:16 java-he
    不是很了解corba 。不過以前一個產品用了corba ,用了2年不是很穩定。后都改成了C++。  回復  更多評論
      

    # re: Java Corba 2009-02-05 23:35 gavin.zheng
    糾正一下
    首先:目前常用的rpc有以下幾種, corba rmi soap(soa)
    1,corba最高效,使用的是c編碼解碼,而且現在所有的服務器間通信基本上都是它
    2,以前的rmi最快,但不能不同種服務器通信,因為它是傳誦的jvm內部數據結構,為了能夠進行任何語言通信,避免跟當時的大部分企業產生分歧,它修改了它的地層協議,現在是封裝corba通信, 當然 以前的協議照樣使用
    3,soap現在成了soa的事實標準, 但是這只能作為不同公司直接進行數據交流,xml解析是非常大的性能問題,特別是在集群上,不可能允許使用soap,比如mysql jboss的集群引擎,全部是corba

    我想說的是: corba不可能過時,至少在目前,沒有任何技術在性能上可以超越它  回復  更多評論
      

    # 你們懂不懂corba?? 2009-03-15 13:32 thui
    首先corba是一個協議,和語言和平臺無關,
    不是很了解corba 。不過以前一個產品用了corba ,用了2年不是很穩定。后都改成了C++-------這句話一看就是外行

    1,corba最高效,使用的是c編碼解碼,而且現在所有的服務器間通信基本上都是它
    ---這句話也是,你調查過,都用corba????胡說八道  回復  更多評論
      

    # re: Java Corba 2009-06-05 14:24 wm
    @thui
    1.Corba不會過時,國內用的少,可能幾乎沒有,就感覺過時了,這是一個誤導現象。
    2.國外電信產品中使用比較廣泛,原因因為它是一個相對比較穩定的產品,一般C或者C++的通信用的比較多;還有因為國外的電信產品,他組成比較復雜,一部分是Java一部分是C/C++,那怎么通信呢?當然是Corba,因為它是跨平臺跨語言的。  回復  更多評論
      

    # re: Java Corba 2009-10-07 12:13 yinzhao0509
    博主,在1.6下調試通不過,而且idlj.exe編譯出的文件也和文中有所不同!  回復  更多評論
      

    # re: Java Corba 2013-04-22 17:44 JAVAdel
    講的很好很清楚  回復  更多評論
      

    # re: Java Corba 2014-10-31 17:08 skc
    @java-he
    你好 能具體說明一下,C++代替CORBA的原理嗎  回復  更多評論
      

    主站蜘蛛池模板: 久久精品国产亚洲Aⅴ香蕉| 亚洲午夜AV无码专区在线播放| 久久久亚洲欧洲日产国码二区| 免费在线看黄网站| 国产成A人亚洲精V品无码性色| XXX2高清在线观看免费视频| 久久久久久久亚洲精品| 中国一级特黄的片子免费 | 亚洲中文字幕伊人久久无码| 一级一级一片免费高清| 亚洲综合色在线观看亚洲| 国产中文字幕在线免费观看| 亚洲AV中文无码乱人伦下载| 亚欧免费无码aⅴ在线观看| 亚洲精品在线视频观看| 人妻视频一区二区三区免费| 亚洲爆乳成av人在线视菜奈实 | 亚洲精品无码AV人在线播放| 免费91麻豆精品国产自产在线观看 | 亚洲自偷自拍另类图片二区| 亚洲免费综合色在线视频| 亚洲女子高潮不断爆白浆| 亚洲人成色7777在线观看不卡 | 99精品免费观看| 亚洲人成小说网站色| 亚洲国产精品狼友中文久久久| 国产一级高青免费| 亚洲国产模特在线播放| 国产在线a不卡免费视频| a级精品九九九大片免费看| 亚洲人6666成人观看| 亚洲福利中文字幕在线网址| 国产精品免费AV片在线观看| 亚洲熟妇成人精品一区| 国产亚洲精品高清在线| 青娱乐免费在线视频| 久青草国产免费观看| 亚洲免费视频播放| 久久亚洲国产成人精品无码区| 国产曰批免费视频播放免费s| 色www免费视频|