IceBox

IceBox是一个Ice应用服务框架。加载多个服务进行配置,进行一定优化;通过配置加载服务,解除服务和服务器的耦合。

IceBox服务需要Slice定义、骨架代码(slice定义映射的特定语言代码)、Servant类、IceBox服务。

具体实现:

Hello.ice、Hello.h/Hello.cpp、HelloI.h/HelloI.cpp(Servant类,实现Hello)不再介绍,参考上篇日志。

IceBox服务

HelloServiceI.h

#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,实现start和stop,以供IceBox服务管理器调用。start在服务加载后被调用,stop在服务关闭时被调用。

//创建服务
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){
	//加入Servant实例
    adapter=communicator -> createObjectAdapter(name);
    Ice::ObjectPtr object=new HelloI;
    adapter->add(object, communicator->stringToIdentity("hello"));
    adapter->activate();
}
void HelloServiceI::stop(){
    adapter->deactivate();
}

配置服务器

config.icebox主配置文件

 IceBox.Service.Hello=HelloService:create --Ice.Config=config.service

config.service次配置文件(服务的端口和协议)

Hello.Endpoints=tcp -p 10000:udp -p 10000

打包

g++ -o -shared libHelloService.so HelloServiceI.cpp HelloI.cpp Hello.cpp -I. -I $ICE_HOME/include -fPIC

启动IceBox

icebox --Ice.Config=config.icebox

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值