ICEBOX的配置和使用【CPlusPlus】
一 理论部分
(1) 为什么要使用icebox?
icebox server代替了通常的server.
icebox是为了方便集中管理多个ice服务而建立的。
它通过使用icebox服务器,把ice服务注册进去,从而建立联系。
所以它除了建立传统的ice服务器,ice客户端,主要是配置icebox服务器。
二 编写icebox配置文件
1 建立icebox服务器,主要是配置文件的编写
#file icebox.config
//核心参数
//进入点的指定。要把服务配置进 IceBox 服务器中,只需使用一个属性,IceBox.Service.name=entry_point [args]
//这个属性的用途有好几个:它定义服务的名字Hello,它向服务管理器提供服务进入点,它还定义用于服务的属性和参数。
//属性值的第一个参数用于指定进入点。对于 C++ 服务,其形式必须是library:symbol。跟在 entry_point 后面的任何参数都会被检查。如果某个参数的形式是
--name=value,它就会被解释为属性定义,将会出现在传给服务的 start操作的通信器的属性集中。这些参数将被移除,剩下的参数会放在 args 参数中传给 start 操作。
IceBox.Service.Hello=HelloService:create --Ice.Trace.Network=1 hello there
Hello.Endpoints=tcp -p 10000
三 建立icebox服务
编写IceBox 服务接口
要编写 IceBox 服务,需要实现某个 IceBox 服务接口。(以下示例为基类,在IceBox.h中实现)
module IceBox{local interface ServiceBase{void stop();};local interface Service extends ServiceBase{void start(string name, Ice::Communicator communicator, Ice::StringSeq args) throws FailureException;};
};
1 建立ice应用服务
首先,我们包括了 IceBox 头文件,以使我们能从 IceBox::Service派生我们的实现。
其次,那些预处理器定义是必需的,因为在 Windows 上,这个服务驻留在一个 Dynamic Link Library (DLL) 中,因此我们需要输出这个类,让服务管理器能适当地加载它。
#include
#include
#include
using namespace std;
extern "C" {HELLO_API IceBox::Service* create(Ice::CommunicatorPtr communicator){return new HelloServiceI;}
}class __declspec(dllexport) CHelloService : public IceBox::Service{
public:virtual void start(const ::std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&);virtual void stop();
private:Ice::ObjectAdapterPtr spObjAdapter;
};void CHelloService::start(const ::std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args){spObjAdapter = communicator->createObjectAdapter(name);Ice::ObjectPtr spObj = new CAbsHelloService(communicator);spObjAdapter->add(spObj, Ice::stringToIdentity("Hello");spObjAdapter->activate();
}
void CHelloService::stop(){spObjAdapter->deactivate();
}
四 启动 icebox 服务器
下面是用于我们的 C++ 服务例子的配置文件:
716
IceBox
IceBox.ServiceManager.Endpoints=tcp -p 10000
IceBox.Service.Hello=HelloService:create
Hello.Endpoints=tcp -p 10001
注意,我们为 Hello 服务创建的对象适配器定义了一个端点。
假定这些属性位于名为 config 的配置文件中,我们可以这样启动 C++
IceBox 服务器:
$ icebox --Ice.Config=config
参考;
// IceBox 提供了一个管理实用程序ServiceManager 。可选参数。貌似不设置的话是默认的。
//定义IceBox 服务管理器接口的端点。以激活IceBox管理服务。服务管理器端点必须能被IceBox 管理工具访问到,以关闭IceBox 服务器。
IceBox.ServiceManager.Endpoints=tcp -p 9998
Ice.Admin.InstanceName=Box (定义IceBoxAdmin名称,默认是IceBox)
Ice.Admin.Endpoints=tcp -p 9998 -h 127.0.0.1 (定义IceBoxAdmin接入端口,这样用Ice.Admin时才能进入ServiceManager)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
