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

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

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

    xylz,imxylz

    關注后端架構、中間件、分布式和并發編程

       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      111 隨筆 :: 10 文章 :: 2680 評論 :: 0 Trackbacks

    ICE Grid 入門篇


    這篇是ICE Grid入門的最簡單版本(不涉及到IceGride Node)。這里面設計到過多的概念和知識,暫且不表。

    創建slice文件

    Printer.ice
     1 // **********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 // **********************************************************************
     8 
     9 module Demo{
    10     interface Printer {
    11         void printString(string s);
    12     };
    13 };

    轉換slice

    slice2cpp Printer.ice 

    配置IceGrid Registry
    registry.cfg
    IceGrid.InstanceName=DemoGrid

    Ice.Default.Locator=DemoGrid/Locator:default -p 4061  

    IceGrid.Registry.Client.Endpoints=tcp -p 4061
    IceGrid.Registry.Server.Endpoints=tcp
    IceGrid.Registry.Internal.Endpoints=tcp
    IceGrid.Registry.PermissionsVerifier=DemoGrid/NullPermissionsVerifier
    IceGrid.Registry.AdminPermissionsVerifier=DemoGrid/NullPermissionsVerifier
    IceGrid.Registry.SSLPermissionsVerifier=DemoGrid/NullSSLPermissionsVerifier
    IceGrid.Registry.AdminSSLPermissionsVerifier=DemoGrid/NullSSLPermissionsVerifier
    IceGrid.Registry.Data=./data
    IceGrid.Registry.DynamicRegistration=1

    啟動Registry
    icegridregistry --Ice.Config=./registry.cfg &
    啟動前最好創建數據目錄./data
    mkdir ./data

    服務端

    PrinterI.h
     1 //**********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 //**********************************************************************
     8 
     9 #ifndef PRINTER_I_H
    10 #define PRINTER_I_H
    11 
    12 #include <Printer.h>
    13 
    14 using namespace Demo;
    15 using namespace std;
    16 
    17 class PrinterI : public Printer {
    18 public:
    19     virtual void printString(const string& s,const Ice::Current&);
    20 };
    21 
    22 #endif
    23 

    PrinterI.cpp
     1 //**********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 //**********************************************************************
     8 
     9 #include <Ice/Ice.h>
    10 #include <PrinterI.h>
    11 
    12 using namespace std;
    13 
    14 void PrinterI :: printString(const string& s,const Ice::Current&){
    15     cout << s << endl;
    16 }
    17 

    Server.cpp
     1 #include <Ice/Ice.h>
     2 #include <PrinterI.h>
     3 
     4 using namespace std;
     5 
     6 class Server : public Ice::Application {
     7 
     8     public:
     9         virtual int run(int argc,char* argv[]);
    10 };
    11 
    12 int main(int argc,char* argv[]){
    13 
    14     Server app;
    15     int status = app.main(argc,argv,"server.cfg");
    16     return status;
    17 }
    18 
    19 int Server::run(int argc,char* argv[]){
    20     if(argc>1){
    21         cerr<<appName()<<": too many arguments"<<endl;
    22         return EXIT_FAILURE;
    23     }
    24 
    25     Ice::PropertiesPtr properties = communicator()->getProperties();
    26     Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("PrinterAdapter");
    27     Ice::Identity id = communicator()->stringToIdentity("printer");
    28     Demo::PrinterPtr printer = new PrinterI();
    29     adapter->add(printer,id);
    30     adapter->activate();
    31     communicator()->waitForShutdown();
    32     return EXIT_SUCCESS;
    33 }
    34 

    編譯
    c++ -I. -I$ICE_HOME/include -c PrinterI.cpp Printer.cpp Server.cpp

    連接
    c++ -o server Printer.o Server.o PrinterI.o -L$ICE_HOME/lib -lIce -lIceUtil -lpthread

    服務端配置
    server.cfg
    PrinterAdapter.AdapterId=PrinterAdapter
    PrinterAdapter.Endpoints=default
    Ice.Default.Locator=DemoGrid/Locator:tcp -p 4061
    運行服務端
    ./server

    客戶端

    Client.cpp
     1 //**********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 //**********************************************************************
     8 
     9 #include <Ice/Ice.h>
    10 #include <IceGrid/IceGrid.h>
    11 #include <Printer.h>
    12 
    13 using namespace std;
    14 using namespace Demo;
    15 
    16 int main(int argc,char* argv[]){
    17     int status = 0;
    18     Ice::CommunicatorPtr ic;
    19     PrinterPrx printer;
    20     try{
    21         ic = Ice::initialize(argc,argv);
    22         cout<<"Printer Proxy=>"<<ic->stringToProxy("printer@PrinterAdapter")<<endl;
    23 
    24         try{
    25            printer = PrinterPrx::checkedCast(ic->stringToProxy("printer@PrinterAdapter"));
    26         }catch(const Ice::NotRegisteredException&){
    27             IceGrid::QueryPrx query = IceGrid::QueryPrx::checkedCast(ic->stringToProxy("DemoGrid/Query"));
    28             printer = PrinterPrx::checkedCast(query->findObjectByType("::Demo::Printer"));
    29         }
    30         if(!printer){
    31             cerr<<": could't find a `::Demo::Printer` object."<<endl;
    32             if(ic){
    33                 ic->destroy();
    34             }
    35             return EXIT_FAILURE;
    36         }
    37         printer->printString("Hello world!");
    38     }catch(const Ice::Exception& ex){
    39         cerr << ex << endl;
    40         status = 1;
    41     }catch(const char* msg){
    42         cerr << msg << endl;
    43         status = 2;
    44     }
    45     if(ic){
    46         ic->destroy();
    47     }
    48     return status;
    49 }
    50 

    編譯
    c++ -I. -I$ICE_HOME/include -c Printer.cpp Client.cpp

    連接
    c++ -o client Printer.o Client.o -L$ICE_HOME/lib -lIce -lIceUtil -lIceGrid -lGlacier2 -lpthread

    客戶端配置
    client.cfg
    Ice.Default.Locator=DemoGrid/Locator:default -p 4061

    運行客戶端
    ./client --Ice.Config=./client.cfg


    所有文件

    grid
    ├── client.cfg
    ├── Client.cpp
    ├── Printer.cpp
    ├── Printer.h
    ├── PrinterI.cpp
    ├── PrinterI.h
    ├── registry.cfg
    ├── server.cfg
    └── Server.cpp


    所有文件下載: Ice Mini Guide

    ©2009-2014 IMXYLZ |求賢若渴
    posted on 2012-05-22 19:47 imxylz 閱讀(3371) 評論(0)  編輯  收藏 所屬分類: ICE

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


    網站導航:
     

    ©2009-2014 IMXYLZ
    主站蜘蛛池模板: 国产gav成人免费播放视频| 日本免费人成视频播放| 亚洲AV无码一区二区三区系列| 男女猛烈激情xx00免费视频| 四虎国产精品免费视| 国产精品亚洲lv粉色| 国产成人免费手机在线观看视频| 在线亚洲午夜片AV大片| 成人免费毛片内射美女-百度| 亚洲一区二区三区在线| 动漫黄网站免费永久在线观看| 亚洲中文无码av永久| 99视频在线精品免费观看6| 亚洲一久久久久久久久| 在线A级毛片无码免费真人| 亚洲精品国产suv一区88| 日韩特黄特色大片免费视频| 国产精品观看在线亚洲人成网| 免费永久国产在线视频| 人人公开免费超级碰碰碰视频 | 亚洲色自偷自拍另类小说| 中国国语毛片免费观看视频| 亚洲AV永久精品爱情岛论坛| 日韩内射激情视频在线播放免费| 亚洲国产成a人v在线| 永久黄网站色视频免费直播| 国产免费区在线观看十分钟 | 麻豆亚洲AV永久无码精品久久| 麻豆视频免费观看| 亚洲AV无码一区二区三区久久精品| 免费a级毛片大学生免费观看 | 亚洲av成人综合网| 国产精品色午夜免费视频| 黄色视频在线免费观看| 亚洲精品美女在线观看播放| 免费毛片在线播放| 国内精品免费视频精选在线观看 | 国产亚洲女在线线精品| 亚洲第一AV网站| 在线观看免费毛片| 国产精品白浆在线观看免费|