ICE BOX 配置,使用----第一篇

一 理论部分

(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应用服务

头文件:

#include <IceBox/IceBox.h>
#if defined(_WIN32)
#
define HELLO_API __declspec(dllexport)
#else
#
define HELLO_API /**/
#endif
class HELLO_API HelloServiceI : public IceBox::Service {
public:
virtual void start(const std::string &,
const Ice::CommunicatorPtr &,
const Ice::StringSeq &);
virtual void stop();
private:
Ice::ObjectAdapterPtr _adapter;
};

成员文件:
首先,我们包括了 IceBox 头文件,以使我们能从 IceBox::Service派生我们的实现。
其次,那些预处理器定义是必需的,因为在 Windows 上,这个服务驻留在一个 Dynamic Link Library (DLL) 中,因此我们需要输出这个类,让服
务管理器能适当地加载它。

cpp文件定义同样直截了当:
#include <Ice/Ice.h>
#include <HelloServiceI.h>
#include <HelloI.h>
using namespace std;
extern "C" {
HELLO_API IceBox::Service *
create(Ice::CommunicatorPtr communicator)
{
return new HelloServiceI;
}
}
void
HelloServiceI::start(
const string & name,
const Ice::CommunicatorPtr & communicator,
const Ice::StringSeq & args)
{
_adapter = communicator->createObjectAdapter(name);
Ice::ObjectPtr object = new HelloI(communicator);
_adapter->add(object, Ice::stringToIdentity("hello"));
_adapter->activate();
}
void
HelloServiceI::stop()
{
_adapter->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)





参考:

一个完整的java版本的配置使用icebox示例。http://wenku.baidu.com/link?url=a2pRxEvi35hS1Kygb88Cg1MVs0OVUOLLTEdVxb09cE0rJZAW3GN0kH1fnc6eVi79lZGRZkqus7-FLCzaC-5u7yTmPkceYO5ihc3AXPISMcu


对icebox的管理   http://hi.baidu.com/monsterfairy/item/5a4dacc1a21f322646d5c09a

posted @ 2013-12-21 17:33  唐僧吃肉  阅读(1199)  评论(0编辑  收藏  举报