J2EE之巔

           

          Orbacus名字服務的使用

          Orbacus IONA 提供的開源 COBRA 實現,但其相關技術文檔去很不詳盡,而且還有錯誤,以下是以舉例的方式說明了如何使用其提供的名字服務。

          1 啟動名字服務

          java -Dooc.orb.oa.endpoint="iiop --port 9998" -classpath OBNaming.jar;OB.jar com.ooc.CosNaming.Server

          其中通過 ooc.orb.oa.endpoint="iiop --port 9998" 設置服務的端口

          2 服務器段代碼:

          import helloorb.Hello;

          import helloorb.Hello_Impl;

          ?

          import org.omg.CosNaming.NameComponent;

          import org.omg.CosNaming.NamingContextExt;

          import org.omg.CosNaming.NamingContextExtHelper;

          ?

          import com. ooc .CORBA.ORB;

          import com.ooc.OBPortableServer.POA;

          import com.ooc.OBPortableServer.POAHelper;

          import com.ooc.OBPortableServer.POAManager;

          ?

          public class ByNamingServer {

          ??? public static void main(String[] args) {

          ?????? java.util.Properties props = System.getProperties();

          ?????? props.put( "org.omg.CORBA.ORBClass" , "com.ooc.CORBA.ORB" );

          ?????? props.put( "org.omg.CORBA.ORBSingletonClass" ,

          ????????????? "com.ooc.CORBA.ORBSingleton" );

          ?

          ?????? org.omg.CORBA.ORB orb = null ;

          ?????? try {

          ?????????? orb = ORB.init(args, props);

          ?

          ?????????? org.omg.CORBA.Object poaObj = null ;

          ?????????? try {

          ????????????? poaObj = orb.resolve_initial_references( "RootPOA" );

          ?????????? } catch (org.omg.CORBA.ORBPackage.InvalidName ex) {

          ????????????? throw new RuntimeException();

          ?????????? }

          ?????????? POA rootPOA = POAHelper.narrow(poaObj);

          ?????????? org.omg.PortableServer.POAManager manager = rootPOA

          ????????????????? .the_POAManager();

          ?

          ?????????? org.omg.CORBA.Object obj = null ;

          ?????????? try {

          ????????????? String nameService= "corbaloc::127.0.0.1:9998/NameService" ;

          ????????????? obj = orb.string_to_object(nameService);

          ?????????? } catch (Exception ex) {

          ????????????? ex.printStackTrace();

          ????????????? throw new RuntimeException();

          ?????????? }

          ?

          ?????????? if (obj == null ) {

          ????????????? throw new RuntimeException();

          ?

          ?????????? }

          ?????????? NamingContextExt nc = null ;

          ?????????? try {

          ????????????? ?Hello_Impl helloImpl = new Hello_Impl();

          ?????????? ???? Hello hello = helloImpl._this(orb);

          ?????????? ???? NameComponent[] a2Name = new NameComponent[1];

          ?????? ???????? a2Name[0] = new NameComponent();

          ?????????? ????? a2Name[0]. id = "HelloServer" ;

          ?????????? ????? a2Name[0]. kind = "" ;

          ????????????? nc = NamingContextExtHelper.narrow(obj);

          ????????????? nc.rebind(a2Name, hello);

          ????????????? manager.activate();

          ?????????? } catch (Exception ex) {

          ????????????? ex.printStackTrace();

          ????????????? throw new RuntimeException();

          ?????????? }

          ?????? } catch (Exception e1) {

          ?????????? e1.printStackTrace();

          ?????? }

          ??? }

          }

          ?

          3 客戶端代碼

          import org.omg.CosNaming.NameComponent;

          import org.omg.CosNaming.NamingContextExt;

          import org.omg.CosNaming.NamingContextExtHelper;

          ?

          import helloorb.Hello;

          import helloorb.HelloHelper;

          ?

          ?

          public class ByNamingClient {

          ??? public static void main(String args[]) {

          ?????? java.util.Properties props = System.getProperties();

          ?????? props.put( "org.omg.CORBA.ORBClass" , "com.ooc.CORBA.ORB" );

          ?????? props.put( "org.omg.CORBA.ORBSingletonClass" ,

          ????????????? "com.ooc.CORBA.ORBSingleton" );

          ?

          ?????? int status = 0;

          ?????? org.omg.CORBA.ORB orb = null ;

          ?

          ?????? try {

          ?????????? orb = org.omg.CORBA.ORB.init(args, props);

          ?????????? status = run(orb);

          ??????????

          ?????? } catch (Exception ex) {

          ?????????? ex.printStackTrace();

          ?????????? status = 1;

          ?????? }

          ?

          ?????? if (orb != null ) {

          ?????????? try {

          ????????????? orb.destroy();

          ?????????? } catch (Exception ex) {

          ????????????? ex.printStackTrace();

          ????????????? status = 1;

          ?????????? }

          ?????? }

          ?

          ?????? System.exit(status);

          ??? }

          ?

          ??? static int run(org.omg.CORBA.ORB orb) {

          ?????? org.omg.CORBA.Object obj = null ;

          ??? /*? try {

          ?????????? String refFile = "Hello.ref";

          ?????????? java.io.BufferedReader in = new java.io.BufferedReader(

          ????????????????? new java.io.FileReader(refFile));

          ?????????? String ref = in.readLine();

          ?????????? obj = orb.string_to_object(ref);

          ??????????

          ?????? } catch (java.io.IOException ex) {

          ?????????? ex.printStackTrace();

          ?????????? return 1;

          ?????? }*/

          ?????? try {

          ?????? obj = orb.string_to_object( "corbaloc::127.0.0.1:9998/NameService" );

          ?????? NamingContextExt nc = NamingContextExtHelper.narrow(obj);

          ??? /*? ? NameComponent[] a2Name = new NameComponent[1];

          ??? ???????? a2Name[0] = new NameComponent();

          ?????? ????? a2Name[0].id = "HelloServer";

          ?????? ????? a2Name[0].kind = "";*/

          ??????

          ?????? Hello hello = HelloHelper.narrow(nc.resolve_str( "HelloServer" ));

          ?????? hello.say_hello();

          ?????? } catch (Exception e){

          ?????????? e.printStackTrace();

          ?????? }

          ?????? return 0;

          ??? }

          }

          posted on 2006-11-19 22:02 超越巔峰 閱讀(1774) 評論(3)  編輯  收藏 所屬分類: CORBA

          評論

          # re: Orbacus名字服務的使用 2007-09-14 00:19 ucs_2008

          推薦一款功能強大的Corba模擬器UCS...不用不知道,用了才說妙...

          Download site:
          http://sourceforge.net/projects/ucs

          UCS (Ultra Corba Simulator) is one more powerful corba client/servant simulator tool than other similar products(e.g. Telcopro's MtSim, or OpenFusion's Corba Explorer, or eaiBridge's CAST). It doesn't need idl-related helper class or IR service  回復  更多評論   

          # re: Orbacus名字服務的使用 2009-11-24 23:04 fbin

          java -Dooc.orb.oa.endpoint="iiop --port 9998" -classpath OBNaming.jar;OB.jar com.ooc.CosNaming.Server
          為什么我在命令行下,出錯呢  回復  更多評論   

          # re: Orbacus名字服務的使用 2009-11-24 23:05 fbin

          Exception in thread "main" java.lang.NoClassDefFoundError: com/ooc/CosNaming/Server  回復  更多評論   


          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           

          導航

          統(tǒng)計

          常用鏈接

          留言簿(12)

          隨筆分類(54)

          隨筆檔案(59)

          文章分類(2)

          文章檔案(1)

          相冊

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 高要市| 梅河口市| 南陵县| 碌曲县| 乌兰察布市| 中卫市| 兴文县| 林西县| 洪江市| 安平县| 安仁县| 巧家县| 和田县| 广河县| 瑞丽市| 广宗县| 辛集市| 保山市| 贵定县| 全州县| 纳雍县| 龙泉市| 昌黎县| 贵阳市| 旌德县| 麟游县| 大庆市| 林周县| 绥芬河市| 昭觉县| 长宁区| 溆浦县| 板桥市| 万全县| 鄂州市| 瓮安县| 灵武市| 三都| 武清区| 新疆| 太仆寺旗|