ICE 简单介绍(Internet Communication Engine)

1. ICE的一些背景

the Internet Communications Engine   http://www.zeroc.com/ice.html

ICE 是ZeroC的主要产品,   是一个object-oriented toolkit,用来帮助我们构建分布式应用程序,使我们专注于程序的逻辑而不是底程网络交互的细节

ZeroC provides a fast and highly-scalable communications infrastructure for demanding technical applications, such as telecom, defense, finance, on-line entertainment, manufacturing, and process control. ZeroC's core product is Ice, the Internet Communications Engine. Ice is one of the most versatile and powerful distributed computing platforms ever.

With an aggressive, no-nonsense licensing model for the Open Source community (GPL, the GNU General Public License), in addition to traditional proprietary licensing models for commercial customers, ZeroC aims to establish Ice as the leading technical middleware product.

ice提供了强大的 RPC(remote procedure call)功能,(同步异步Invocation,dispatch), one-way (对tcp,ssl),datagram(udp) ,也就是客户端调用了就不管了(fire and forget)  以及提供了除rpc之外的几个强大的服务,iceGrid, iceStorm....

ICE提供的编程模型 :4步, 定义slice文件, slice文件生成相应语言的代码(根据client,server所使用的语言),  编写client-side代码并链接ICE, 编写server-side代码并链接ICE

ICE广泛支持了各主流语言和 platform(OS & compiler)

2. ice manual的基本内容

这个文档是ice主要的文档了,编程什么的都参考它,主要分了4个部份;  

2.1,概述,ice主要的几个部份介绍,在2.2.2(terminology)作为术语解释,包括ice object, ice proxy,  ice object简单说是一个可以响应client request的实体,它有至少一个interface,interface则有一个或多个operation,每个ice object都有一个object identity(object在35章详讲);   ice proxy:  client要想contact一个ice object,就必须hold一个ice proxy,它就是ice object的本地代理,所以proxy必须有object的address信息,以及object的identity来定位object,(proxy在32章详讲),  以及一个hello world例子,告诉我们最简单的ice client,server怎么写

2.2 slice(specification language for ice) , slice在client和server之间做了一个约定, slice会被c++的预处理器作预处理,所以我们在文件中都应该用到#ifndef, #define,#endif, 另外 #include应该用<>,这样slice compiler会在编译选项的-I路径中去查找头文件,slice中所有的定义都必须放到module中,不能在全局定义

特别的要提到Ice module, 基本上所有的Ice run time时的API, 都是在以slice的形式定义和表达的,在module Ice { }中,比如我们下面提到的communicator是一个slice的interface  

slice中的类型有basic types , user-defined types(enum, structure, sequence, dictionary), sequence<type>,  dictionary<type,type>在c++中被映射为vector和map

interface是slice中最中心最关注的东西了, 通过proxy调用一个operation则就由Ice run time向目标object发送了一个message,  4.10.4讲了ice所定义的exception的层次结构,根处是Ice::Exception,应该是Ice自己用Slice定义的吧,不知道映射到C++中是不是std::Exception,  interface可以用extends来派生, interface  Thing  extends BaseThing {}

class的内容很丰富,后面看,有和interface,struct的比较。。

2.3 slice到具体语言的映射,主要去看看到C++的映射

2.4 ice的configuration, thread,  ice run-time的深入理解(其中有proxy),上面提到,run-time的api基本都是由slice定义的,以及ice object的深入理解

2.5 ice提供的其它服务,如ice storm

3. ICE manual 中的一张图  

这是在ice manual中概述部份的一张图,2.2.5, client和server端的结构,其中proxy code和Skeleton都是slice生成的具体语言的代码,Object Adapter是专属server端的 Ice run-time的一部份,它把client的request映射到object具体的方法上

4, communicator的一点理解

以下内容差不多都看自于 Ice manual中Ice run-time in detail那一章

Communicator代表了Ice run time的主要进入点, Ice::Communicator的一个 instance(实例)关联了一系列 run-time resources(运行时的资源) , 包括Client-side Thread Pool, Server-side Thread Pool , Configuration Properties ......  Communicator 是一个slice定义的 local interface, Communicator提供了一系列的operation,  stringToProxy ,  createObjectAdapterWithEndpoints...;     talk中的IceChannel这个类就是对 Ice Communicator的包装, 且IceChannel中定义的方法大都是对createObjectAdapterWithEndpoints的包装, 在talk的main函数中, 要用communicator的地方用的IceChannel

(32.3)Communicator的在创建的过程中, ICE run time为其初始化了一系列的特性, 并且初使化后不能修改, 也就是只能在创建一个communicator时设定这些特性;   首先初始化一个data structure,   对C++来说是  struct InitializationData {PropertiesPtr properties; ...},  然后使用函数 Ice::initialize来初使化生成一个communicator  CommunicatorPtr initialize(const InitializationData& = InitializationData())

1 Ice::InitializationData id;
2 id.PropertiesPtr = properties;(properites先赋好值)
3 Ice::CommunicatorPtr ic = Ice::initialize(id);

在talk的 IceChannel::init()中先设置PropertiesPtr 再 生成 CommunicatorPtr_ ;

Object Adapters(32.4)

一个communicator有一个或多个object adapters, 一个object adapter处在Ice run time和server application(服务端应用程序)之间,  Object Adapter本身是一个local interface, 

endpoint的概念也是adapter的, 且一个adapter维护两组endpoints,  physical endpoints 和 published endpoints, 

servant activation and deactivation(32.4.4) : adapter提供了 add , remove, find 等操作 , 在talk中main函数里面用到了add, 注意创建的是 Ice::objectPtr ....,而add带的第二参数是 Identity(32.5), 也就是client要使用这个servant必须知晓的名字

object Identity (32.5)   每一个ICE object都有一个object Identity, 这是一个slice定义的struct(module Ice中),  Object Identity可以以string的形式表式,  Fatory/File 表示 category是 Factory, name是File  Communicator提供了 stringToIdentity  和 identityToString 来进行string和Identity的互转  除非使用Locator, category常常是空的

module Ice{
struct Identity {
string name;
string category;
};
};

5.ICE wiki 介绍

 http://en.wikipedia.org/wiki/Internet_Communications_Engine   这幅图不错  去细看看里面那幅图

ICE 在线文档(不知道为什么现在没找到pdf的下载了) http://doc.zeroc.com/display/Ice/Ice+Manual

原文地址:https://www.cnblogs.com/livingintruth/p/2428130.html